Consensys / PLCRVoting

Partial Lock Commit Reveal Voting System that utilizes ERC20 Tokens
Apache License 2.0
174 stars 48 forks source link

What happens if _voteOption is something other than 0 or 1? #28

Open kangarang opened 6 years ago

kangarang commented 6 years ago

https://github.com/ConsenSys/PLCRVoting/blob/master/contracts/PLCRVoting.sol#L174

function revealVote(uint _pollID, uint _voteOption, uint _salt) external {
    // Make sure the reveal period is active
    require(revealPeriodActive(_pollID));
    require(!hasBeenRevealed(msg.sender, _pollID));                        // prevent user from revealing multiple times
    require(keccak256(_voteOption, _salt) == getCommitHash(msg.sender, _pollID)); // compare resultant hash from inputs to original commitHash

    uint numTokens = getNumTokens(msg.sender, _pollID); 

    if (_voteOption == 1) // apply numTokens to appropriate poll choice
        pollMap[_pollID].votesFor += numTokens;
    else
        pollMap[_pollID].votesAgainst += numTokens;

    dllMap[msg.sender].remove(_pollID); // remove the node referring to this vote upon reveal

    VoteRevealed(msg.sender, _pollID, numTokens, _voteOption);
}
skmgoldin commented 6 years ago

Prospective fix: Change else to else if (vote == 0), followed by an else { revert }. The user will never be able to reveal, but they will be able to rescue tokens.