MoreRulesToTheGodOfRules

This commit is contained in:
Aleksander Kryukov
2021-11-08 17:18:36 +02:00
committed by Aleksander Kryukov
parent d5c6520e4d
commit 2761ec0b66
3 changed files with 64 additions and 10 deletions

View File

@ -10,6 +10,15 @@ contract GovernorHarness is Governor {
return _proposals[proposalId].canceled; return _proposals[proposalId].canceled;
} }
function initialized(uint256 proposalId) public view returns (bool){
if (_proposals[proposalId].voteStart._deadline != 0 && _proposals[proposalId].voteEnd._deadline != 0) {
return true;
}
return false;
}
mapping(uint256 => uint256) _quorum; mapping(uint256 => uint256) _quorum;
function quorum(uint256 blockNumber) public view override virtual returns (uint256) { function quorum(uint256 blockNumber) public view override virtual returns (uint256) {
@ -64,6 +73,7 @@ contract GovernorHarness is Governor {
return _votingPeriod; return _votingPeriod;
} }
constructor(string memory name) Governor(name) {} constructor(string memory name) Governor(name) {}
// _countVots == Sum of castVote // _countVots == Sum of castVote
@ -76,28 +86,32 @@ contract GovernorHarness is Governor {
// mapping of count // mapping of count
// countMap // countMap
mapping(uint256 => mapping(address => uint256)) counted_weight_by_id; mapping(uint256 => uint256) counted_weight;
// uint decision;
// uint numberOfOptions;
function _countVote( function _countVote(
uint256 proposalId, uint256 proposalId,
address account, address account,
uint8 support, uint8 support,
uint256 weight uint256 weight
) internal override virtual { ) internal override virtual {
counted_weight_by_id[proposalId][account] += weight; counted_weight[proposalId] += weight;
} }
mapping(uint256 => uint256) public counter_vote_power_by_id;
mapping(uint256 => uint256) counter_vote_power_by_id; mapping(uint256 => uint256) public ghost_vote_power_by_id;
function castVote(uint256 proposalId, uint8 support) public virtual override returns (uint256) { function castVote(uint256 proposalId, uint8 support) public virtual override returns (uint256) {
address voter = _msgSender(); address voter = _msgSender();
// 1)
counter_vote_power_by_id[proposalId] += _castVote(proposalId, voter, support, "");
return _castVote(proposalId, voter, support, "");
// 2) // 2)
// counter_vote_power_by_id[proposalId] = _castVote(proposalId, voter, support, ""); ghost_vote_power_by_id[proposalId] = _castVote(proposalId, voter, support, "");
// return counter_vote_power;
// 1)
counter_vote_power_by_id[proposalId] += ghost_vote_power_by_id[proposalId];
// return _castVote(proposalId, voter, support, "");
return ghost_vote_power_by_id[proposalId];
} }
function castVoteWithReason( function castVoteWithReason(

View File

@ -1,2 +1,8 @@
certoraRun certora/harnesses/GovernorCountingSimpleHarness.sol \ certoraRun certora/harnesses/GovernorCountingSimpleHarness.sol \
--verify GovernorCountingSimpleHarness:certora/specs/Privileged.spec --verify GovernorCountingSimpleHarness:certora/specs/GovernorBase.spec \
--solc solc8.0 \
--staging \
--optimistic_loop \
--settings -copyLoopUnroll=4 \
--rule doubleVoting \
--msg "$1"

View File

@ -5,6 +5,11 @@ methods {
hashProposal(address[],uint256[],bytes[],bytes32) returns uint256 envfree hashProposal(address[],uint256[],bytes[],bytes32) returns uint256 envfree
isExecuted(uint256) returns bool envfree isExecuted(uint256) returns bool envfree
isCanceled(uint256) returns bool envfree isCanceled(uint256) returns bool envfree
initialized(uint256) returns bool envfree
hasVoted(uint256, address) returns bool
castVote(uint256, uint8) returns uint256
// internal functions made public in harness: // internal functions made public in harness:
_quorumReached(uint256) returns bool envfree _quorumReached(uint256) returns bool envfree
@ -23,6 +28,12 @@ methods {
invariant voteStartBeforeVoteEnd(uint256 pId) invariant voteStartBeforeVoteEnd(uint256 pId)
(proposalSnapshot(pId) > 0 => proposalSnapshot(pId) < proposalDeadline(pId)) (proposalSnapshot(pId) > 0 => proposalSnapshot(pId) < proposalDeadline(pId))
&& (proposalSnapshot(pId) == 0 => proposalDeadline(pId) == 0) && (proposalSnapshot(pId) == 0 => proposalDeadline(pId) == 0)
/*
proposalSnapshot(pId) < proposalDeadline(pId) || (proposalSnapshot(pId) == 0 && proposalDeadline(pId) == 0)
{ preserved {
require initialized(pId) == true;
}}
*/
/** /**
* A proposal cannot be both executed and canceled. * A proposal cannot be both executed and canceled.
@ -116,3 +127,26 @@ rule immutableFieldsAfterProposalCreation(uint256 pId, method f) {
assert _voteStart == voteStart_; assert _voteStart == voteStart_;
assert _voteEnd == voteEnd_; assert _voteEnd == voteEnd_;
} }
/**
* Check if it's possible to vote two time. Relevant to GovernorCountingSimpleHarness.sol contract
*/
rule doubleVoting(uint256 pId, uint8 sup) {
env e;
address user = e.msg.sender;
bool votedCheck = hasVoted(e, pId, user);
require votedCheck == true;
castVote@withrevert(e, pId, sup);
bool reverted = lastReverted;
assert reverted, "double voting accured";
}
/**
*
*/
rule votingSumAndPower(uint256 pId, uint8 sup, method f) {
}