GovernorBaseRules.spec 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. import "helpers.spec"
  2. import "Governor.helpers.spec"
  3. import "GovernorInvariants.spec"
  4. use invariant proposalStateConsistency
  5. use invariant canceledImplyCreated
  6. use invariant executedImplyCreated
  7. use invariant noBothExecutedAndCanceled
  8. /*
  9. ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  10. │ Rule: No double proposition │
  11. └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  12. */
  13. rule noDoublePropose(uint256 pId, env e) {
  14. require proposalCreated(pId);
  15. address[] targets; uint256[] values; bytes[] calldatas; string reason;
  16. uint256 result = propose(e, targets, values, calldatas, reason);
  17. assert result != pId, "double proposal";
  18. }
  19. /*
  20. ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  21. │ Rule: Once a proposal is created, voteStart, voteEnd and proposer are immutable │
  22. └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  23. */
  24. rule immutableFieldsAfterProposalCreation(uint256 pId, env e, method f, calldataarg args)
  25. filtered { f -> !skip(f) }
  26. {
  27. require proposalCreated(pId);
  28. uint256 voteStart = proposalSnapshot(pId);
  29. uint256 voteEnd = proposalDeadline(pId);
  30. address proposer = proposalProposer(pId);
  31. f(e, args);
  32. assert voteStart == proposalSnapshot(pId), "Start date was changed";
  33. assert voteEnd == proposalDeadline(pId), "End date was changed";
  34. assert proposer == proposalProposer(pId), "Proposer was changed";
  35. }
  36. /*
  37. ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  38. │ Rule: A user cannot vote twice │
  39. │ │
  40. │ Checked for castVote only. all 3 castVote functions call _castVote, so the completeness of the verification is │
  41. │ counted on the fact that the 3 functions themselves makes no changes, but rather call an internal function to │
  42. │ execute. That means that we do not check those 3 functions directly, however for castVote & castVoteWithReason it │
  43. │ is quite trivial to understand why this is ok. For castVoteBySig we basically assume that the signature referendum │
  44. │ is correct without checking it. We could check each function separately and pass the rule, but that would have │
  45. │ uglyfied the code with no concrete benefit, as it is evident that nothing is happening in the first 2 functions │
  46. │ (calling a view function), and we do not desire to check the signature verification. │
  47. └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  48. */
  49. rule noDoubleVoting(uint256 pId, env e, method f)
  50. filtered { f -> voting(f) }
  51. {
  52. address voter;
  53. uint8 support;
  54. bool votedCheck = hasVoted(pId, voter);
  55. helperVoteWithRevert(e, f, pId, voter, support);
  56. assert votedCheck => lastReverted, "double voting occurred";
  57. }
  58. /*
  59. ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  60. │ Rule: Voting against a proposal does not count towards quorum. │
  61. └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  62. */
  63. rule againstVotesDontCountTowardsQuorum(uint256 pId, env e)
  64. {
  65. bool quorumReachedBefore = quorumReached(pId);
  66. castVote(e, pId, 0);
  67. assert quorumReached(pId) == quorumReachedBefore, "quorum must not be reached with an against vote";
  68. }
  69. /// This version is more exhaustive, but to slow because "quorumReached" is a FV nightmare
  70. // rule againstVotesDontCountTowardsQuorum(uint256 pId, env e, method f)
  71. // filtered { f -> voting(f) }
  72. // {
  73. // address voter;
  74. //
  75. // bool quorumReachedBefore = quorumReached(pId);
  76. //
  77. // helperVoteWithRevert(e, f, pId, voter, 0); // support 0 = against
  78. //
  79. // assert quorumReached(pId) == quorumReachedBefore, "quorum must not be reached with an against vote";
  80. // }
  81. /*
  82. ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  83. │ Rule: A proposal could be executed only if quorum was reached and vote succeeded │
  84. └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  85. */
  86. rule executionOnlyIfQuoromReachedAndVoteSucceeded(uint256 pId, env e, method f, calldataarg args)
  87. filtered { f -> !skip(f) }
  88. {
  89. require !isExecuted(pId);
  90. bool quorumReachedBefore = quorumReached(pId);
  91. bool voteSucceededBefore = voteSucceeded(pId);
  92. f(e, args);
  93. assert isExecuted(pId) => (quorumReachedBefore && voteSucceededBefore), "quorum not met or vote not successful";
  94. }
  95. /*
  96. ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  97. │ Rule: Voting cannot start at a block number prior to proposal’s creation block number │
  98. └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  99. */
  100. rule noStartBeforeCreation(uint256 pId, env e, method f, calldataarg args)
  101. filtered { f -> !skip(f) }
  102. {
  103. require !proposalCreated(pId);
  104. f(e, args);
  105. assert proposalCreated(pId) => proposalSnapshot(pId) >= clock(e), "starts before proposal";
  106. }
  107. /*
  108. ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  109. │ Rule: A proposal cannot be executed before it ends │
  110. └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  111. */
  112. rule noExecuteBeforeDeadline(uint256 pId, env e, method f, calldataarg args)
  113. filtered { f -> !skip(f) }
  114. {
  115. require !isExecuted(pId);
  116. f(e, args);
  117. assert isExecuted(pId) => proposalDeadline(pId) <= clock(e), "executed before deadline";
  118. }
  119. /*
  120. ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  121. │ Invariant: The quorum numerator is always less than or equal to the quorum denominator │
  122. └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  123. */
  124. invariant quorumRatioLessThanOne()
  125. quorumNumerator() <= quorumDenominator()
  126. filtered { f -> !skip(f) }
  127. {
  128. preserved {
  129. require quorumNumeratorLength() < max_uint256;
  130. }
  131. }
  132. /*
  133. ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  134. │ Rule: All proposal specific (non-view) functions should revert if proposal is executed │
  135. │ │
  136. │ In this rule we show that if a function is executed, i.e. execute() was called on the proposal ID, non of the │
  137. │ proposal specific functions can make changes again. In executedOnlyAfterExecuteFunc we connected the executed │
  138. │ attribute to the execute() function, showing that only execute() can change it, and that it will always change it. │
  139. └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  140. */
  141. rule allFunctionsRevertIfExecuted(uint256 pId, env e, method f, calldataarg args) filtered { f ->
  142. !skip(f) &&
  143. f.selector != updateQuorumNumerator(uint256).selector &&
  144. f.selector != updateTimelock(address).selector
  145. } {
  146. require isExecuted(pId);
  147. requireInvariant noBothExecutedAndCanceled(pId);
  148. requireInvariant executedImplyCreated(pId);
  149. helperFunctionsWithRevert(e, f, pId);
  150. assert lastReverted, "Function was not reverted";
  151. }
  152. /*
  153. ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  154. │ Rule: All proposal specific (non-view) functions should revert if proposal is canceled │
  155. │ │
  156. │ In this rule we show that if a function is executed, i.e. execute() was called on the proposal ID, non of the │
  157. │ proposal specific functions can make changes again. In executedOnlyAfterExecuteFunc we connected the executed │
  158. │ attribute to the execute() function, showing that only execute() can change it, and that it will always change it. │
  159. └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  160. */
  161. rule allFunctionsRevertIfCanceled(uint256 pId, env e, method f, calldataarg args) filtered { f ->
  162. !skip(f) &&
  163. f.selector != updateQuorumNumerator(uint256).selector &&
  164. f.selector != updateTimelock(address).selector
  165. } {
  166. require isCanceled(pId);
  167. requireInvariant noBothExecutedAndCanceled(pId);
  168. requireInvariant canceledImplyCreated(pId);
  169. helperFunctionsWithRevert(e, f, pId);
  170. assert lastReverted, "Function was not reverted";
  171. }
  172. /*
  173. ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  174. │ Rule: Update operation are restricted to executor │
  175. └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  176. */
  177. rule privilegedUpdate(env e, method f, calldataarg args)
  178. filtered { f -> !skip(f) }
  179. {
  180. address executorBefore = getExecutor();
  181. uint256 quorumNumeratorBefore = quorumNumerator();
  182. address timelockBefore = timelock();
  183. f(e, args);
  184. assert quorumNumerator() != quorumNumeratorBefore => e.msg.sender == executorBefore;
  185. assert timelock() != timelockBefore => e.msg.sender == executorBefore;
  186. }