noVoteForSomeoneElse fix

pull/2997/head
Michael M 3 years ago
parent 92f5f0dfbb
commit 0fbf745efe
  1. 49
      certora/specs/GovernorCountingSimple.spec

@ -156,19 +156,21 @@ rule someOtherRuleToRemoveLater(uint256 num){
} }
*/ */
/* /*
* Checks that only one user is updated in the system when calling cast vote functions (assuming hasVoted is changing correctly, false->true, with every vote cast) * Checks that only one user is updated in the system when calling cast vote functions (assuming hasVoted is changing correctly, false->true, with every vote cast)
*/ */
rule oneUserVotesInCast(uint256 pId, uint8 sup, method f) filtered {f -> f.selector == castVote(uint256, uint8).selector || f.selector == castVoteBySig(uint256, uint8, uint8, bytes32, bytes32).selector} { rule oneUserVotesInCast(uint256 pId, uint8 sup, method f) filtered {f -> f.selector == castVote(uint256, uint8).selector ||
env e; calldataarg args; // ^ ^ f.selector == castVoteBySig(uint256, uint8, uint8, bytes32, bytes32).selector} {
uint256 ghost_Before = hasVoteGhost(pId); // propose castVoteWithReason env e; calldataarg args;
uint256 ghost_Before = hasVoteGhost(pId);
if (f.selector == castVote(uint256, uint8).selector) if (f.selector == castVote(uint256, uint8).selector)
{ {
castVote(e, pId, sup); castVote(e, pId, sup);
} /*else if (f.selector == 0x7b3c71d3) { } /*else if (f.selector == 0x7b3c71d3) {
require(_pId_Harness() == proposalId); require(_pId_Harness() == proposalId);
f(e,args); f(e,args);
}*/ else if (f.selector == castVoteBySig(uint256, uint8, uint8, bytes32, bytes32).selector) { }*/ else if (f.selector == castVoteBySig(uint256, uint8, uint8, bytes32, bytes32).selector) {
uint8 v; bytes32 r; bytes32 s; uint8 v; bytes32 r; bytes32 s;
castVoteBySig(e, pId, sup, v, r, s); castVoteBySig(e, pId, sup, v, r, s);
} else{ } else{
@ -178,18 +180,33 @@ rule oneUserVotesInCast(uint256 pId, uint8 sup, method f) filtered {f -> f.selec
assert(ghost_After == ghost_Before + 1, "Raised by more than 1"); assert(ghost_After == ghost_Before + 1, "Raised by more than 1");
} }
/* /*
* Checks that in any call to cast vote functions only the sender's value is updated * Checks that in any call to cast vote functions only the sender's value is updated
*/ */
rule noVoteForSomeoneElse(uint256 pId, uint8 sup, method f) filtered {f -> f.selector == castVote(uint256, uint8).selector ||
rule noVoteForSomeoneElse(uint256 pId, uint8 support){ f.selector == castVoteBySig(uint256, uint8, uint8, bytes32, bytes32).selector} {
env e; env e; calldataarg args;
address voter = e.msg.sender; address voter = e.msg.sender;
bool hasVotedBefore = hasVoted(e, pId, voter); address user;
require(!hasVotedBefore); bool hasVotedBefore_Voter = hasVoted(e, pId, voter);
castVote(e, pId, support); bool hasVotedBefore_User = hasVoted(e, pId, user);
bool hasVotedAfter = hasVoted(e, pId, voter); require(!hasVotedBefore_Voter);
assert(hasVotedBefore != hasVotedAfter => (forall address user. user != voter => !hasVoted(e, pId, user))); if (f.selector == castVote(uint256, uint8).selector)
{
castVote(e, pId, sup);
} /*else if (f.selector == 0x7b3c71d3) {
require(_pId_Harness() == proposalId);
f(e,args);
}*/ else if (f.selector == castVoteBySig(uint256, uint8, uint8, bytes32, bytes32).selector) {
uint8 v; bytes32 r; bytes32 s;
castVoteBySig(e, pId, sup, v, r, s);
} else{
f(e, args);
}
bool hasVotedAfter_Voter = hasVoted(e, pId, voter);
bool hasVotedAfter_User = hasVoted(e, pId, user);
assert hasVotedBefore_Voter != hasVotedAfter_Voter => (user != voter => hasVotedBefore_User == hasVotedAfter_User);
} }

Loading…
Cancel
Save