Name: PLCRVoting
Owner: ConsenSys
Description: Partial Lock Commit Reveal Voting System that utilizes ERC20 Tokens
Created: 2017-08-14 15:17:10.0
Updated: 2018-01-13 07:46:22.0
Pushed: 2018-01-12 05:34:03.0
Homepage: null
Size: 3388
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Smart contract for voting on the Ethereum blockchain
The process begins with a poll, which only the contract owner can create, centered upon some proposal. The proposal can be anything, but for now we will use the following as our proposal: “John gets employee of the month.” So in the most basic sense, users vote either for or against the proposal. In this case, people vote for or against John getting the employee of the month award.
The submission of a vote to a given poll is separated into two stages: the commit stage and the reveal stage. The commit stage is when a user locks some number of their tokens and associates those tokens with a given vote. The reveal stage is comprised of unlocking those tokens and counting those tokens either for or against the poll. The separation of voting into these two stages prevents potential voters from being swayed by the votes of others and prevents two different entities from voting with the same tokens.
The commit stage is the period during which any user who would like to vote in a poll can send (1) the hash of their vote (which is yes or no) and some salt (which is an arbitrary number that the user chooses) and (2) the number of tokens they want to commit to that vote. The number of tokens that are committed with a user's vote is equal to the number of tokens that will be locked from that moment until the poll ends. When tokens are locked, that means that those tokens can not be withdrawn until they are unlocked.
The reveal stage is the period during which any user who has committed to a poll can have their commited vote count in the poll. A user who has committed a vote must call reveal on the contract and must pass in the vote that he/she committed and the salt that was used in computing the commit hash. This forces anonymity because a given user's vote is only counted if his/her revealed vote, which is public, is the same as his/her committed vote, which is anonymized (i.e. the committed vote is a hash computed with a salt that only the user knows, so somebody can only compute that hash if they know both the user's vote and the user's salt). When a vote is revealed, all tokens associated with that vote are unlocked (i.e. can be withdrawn if they are not also locked in some other poll).
Once the reveal stage of a poll finishes, all voting for the poll has finished. All tokens that were At this point, anybody can check what the results of the poll are. Also, one can check how many tokens in agreement with the poll outcome one were committed by a given address. This is useful if some outside entity wanted to issue rewards or incentives to those who vote in agreement with the poll outcome.
PLCRVoting
ess tokenAddr = 0xABC;
Voting plcr = new PLCRVoting(tokenAddr);
Constructs PLCR scheme to use ERC20 token deployed at tokenAddr
numTokens = 100;
.requestVotingRights(numTokens);
Exchanges numTokens
ERC20 tokens for numTokens
voting rights
numTokens = 100;
.withdrawVotingRights(numTokens);
Withdraws numTokens
voting rights back to numTokens
ERC20 tokens
pollID = 777;
.rescueTokens(pollID);
Rescues by unlocking votes committed to poll labelled by pollID
that were never revealed
pollID
has ended choice = 1;
randromSalt = 54321;
s32 secretHash = sha3(choice, randomSalt);
pollID = 777;
prevID = 555;
numTokens = 100;
.commitVote(pollID, secretHash, numTokens, prevID);
Commits numTokens
votes to poll labelled with pollID
for choice hidden beneath secretHash
prevID
< numTokens
< the committed tokens at nextID
(computed within by getting next of prevID
)pollID
is in the configured commit period pollID = 777;
salt = randomSalt;
voteOption = choice;
.revealVote(pollID, salt, voteOption);
Attributes numTokens
votes for option voteOption
committed to poll labelled by pollID
, and unlocks these votes for withdrawal
salt
and voteOption
match salt and choice used to generate committed secretHash
pollID
is in the configured reveal period quorum = 50;
commitDuration = 100;
revealDuration = 100;
pollID = plcr.startPoll(quorum, commitDuration, revealDuration);
Generates a poll labelled by pollID
requiring a percentage majority of quorum
configuring commitDuration
and revealDuration
msg.sender
is the deployer (owner) of the plcr
instance pollID = 777;
.isPassed(pollID);
Indicates whether a poll labelled by pollID
has been approved
pollID
has ended