Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement default subs votes over pubsub #25

Open
estebanabaroa opened this issue Dec 14, 2023 · 0 comments
Open

implement default subs votes over pubsub #25

estebanabaroa opened this issue Dec 14, 2023 · 0 comments

Comments

@estebanabaroa
Copy link
Member

estebanabaroa commented Dec 14, 2023

Settings {
  chainTicker: 'eth'
  tokenAddress: '0x...'

  // don't store votes for a sub unless it has at least 1 vote with 1bil tokens or more, prevents people spamming votes for subs that dont exist
  minBalanceToProposeVote: 1bil

  // only store the last 100 votes per address, prevents people spamming votes for subs that dont exist 
  maxVotesPerAddress: 100

  // we can't fetch some address' balance at block 100 and another at block 101, we must use the same block for everyone
  // 25min at 15 secs per block on eth
  blocksPerBucket: 100
}

(put all the settings in the pubsub topic so the network can validate without any intermediaries)
pubsubTopic = /default-subplebbits/<settings.chainTicker>/<settings.tokenAddress>/<settings.minBalanceToProposeVote>/<settings.maxVotesPerAddress>/<settings.blocksPerBucket>

steps to get votes:

join pubsub <pubsubTopic>

  • fetch key /last-votes/<pubsubTopic> using libp2p fetch protocol
  • and/or listen on pubsub for new values

the value received is Votes[] (1 Votes[] per author)

Votes {
  author: Author
  signature: Signature
  votes: Vote[] // length must be smaller than maxVotesPerAddress
  blockNumber: number
}
Vote {
  subplebbitAddress: string
  vote: 1 | -1
}

how to verify:

  • check Votes.signature matches Votes.author.address
  • check Votes.author.wallets[chainTicker].signature matches Votes.author.address
  • fetch Votes.author.wallets[chainTicker].address balance at current block number bucket (Math.floor(currentBlockNumber / settings.blocksPerBucket)) and add all balances

potential problems:

  • Votes.votes isn't deterministic so attacker can spam permutations of valid Vote[]. Can be mitigated by only storing 1 Votes[] per wallet.address, the Votes with the highest Votes.blockNumber.
  • One problem with this is there's no way to revoke a wallet.signature, so if your plebbit address gets hacked, you need to move your pleb token to another eth address or the hacker will always be able to vote with your pleb (not steal them, just vote with them). Can be somewhat mitigated by storing the author.wallet.timestamp and not accepting lower timestamps.

steps to publish votes

  • the user sees a feed of subplebbits, he can vote +1 or -1 on them

  • or the user adds a new subplebbit that isn't listed via some +add [______] input

  • every blocksPerBucket, the user republishes his Votes as

Votes {
  author: Author
  signature: Signature
  votes: Vote[] // length must be smaller than maxVotesPerAddress
  blockNumber: number
}
Vote {
  subplebbitAddress: string
  vote: 1 | -1
}

notes:

when receiving a fetch protocol /last-votes/... dont send all the known Votes, only send the highest balance and/or the votes similar to your own, not sure what the max should be, maybe 100kb or something. possibly we could send only the closest k peers of the eth address (like DHT does), or just send random ones.

in the UI, if the user is voting for more subs than settings.maxVotesPerAddress warn him that he must stop voting for some subs to vote for new ones

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant