GovernorBaseRules.spec 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 -> !assumedSafe(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. │ This rule is checked for castVote, castVoteWithReason and castVoteWithReasonAndParams. For the signature variants │
  41. │ (castVoteBySig and castVoteWithReasonAndParamsBySig) we basically assume that the signature referendum is correct │
  42. │ without checking it. │
  43. └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  44. */
  45. rule noDoubleVoting(uint256 pId, env e, method f)
  46. filtered { f -> voting(f) }
  47. {
  48. address voter;
  49. uint8 support;
  50. bool votedCheck = hasVoted(pId, voter);
  51. helperVoteWithRevert(e, f, pId, voter, support);
  52. assert votedCheck => lastReverted, "double voting occurred";
  53. }
  54. /*
  55. ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  56. │ Rule: Voting against a proposal does not count towards quorum. │
  57. └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  58. */
  59. rule againstVotesDontCountTowardsQuorum(uint256 pId, env e)
  60. {
  61. bool quorumReachedBefore = quorumReached(pId);
  62. // Ideally we would use `helperVoteWithRevert` here, but it causes timeout. Consider changing it if/when the prover improves.
  63. castVote(e, pId, 0);
  64. assert quorumReached(pId) == quorumReachedBefore, "quorum must not be reached with an against vote";
  65. }
  66. /*
  67. ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  68. │ Rule: A proposal could be executed only if quorum was reached and vote succeeded │
  69. └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  70. */
  71. rule executionOnlyIfQuoromReachedAndVoteSucceeded(uint256 pId, env e, method f, calldataarg args)
  72. filtered { f -> !assumedSafe(f) }
  73. {
  74. require !isExecuted(pId);
  75. bool quorumReachedBefore = quorumReached(pId);
  76. bool voteSucceededBefore = voteSucceeded(pId);
  77. f(e, args);
  78. assert isExecuted(pId) => (quorumReachedBefore && voteSucceededBefore), "quorum not met or vote not successful";
  79. }
  80. /*
  81. ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  82. │ Rule: Voting cannot start at a block number prior to proposal’s creation block number │
  83. └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  84. */
  85. rule noStartBeforeCreation(uint256 pId, env e, method f, calldataarg args)
  86. filtered { f -> !assumedSafe(f) }
  87. {
  88. require !proposalCreated(pId);
  89. f(e, args);
  90. assert proposalCreated(pId) => proposalSnapshot(pId) >= clock(e), "starts before proposal";
  91. }
  92. /*
  93. ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  94. │ Rule: A proposal cannot be executed before it ends │
  95. └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  96. */
  97. rule noExecuteBeforeDeadline(uint256 pId, env e, method f, calldataarg args)
  98. filtered { f -> !assumedSafe(f) }
  99. {
  100. require !isExecuted(pId);
  101. f(e, args);
  102. assert isExecuted(pId) => proposalDeadline(pId) <= clock(e), "executed before deadline";
  103. }
  104. /*
  105. ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  106. │ Invariant: The quorum numerator is always less than or equal to the quorum denominator │
  107. └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  108. */
  109. invariant quorumRatioLessThanOne()
  110. quorumNumerator() <= quorumDenominator()
  111. filtered { f -> !assumedSafe(f) }
  112. {
  113. preserved {
  114. require quorumNumeratorLength() < max_uint256;
  115. }
  116. }
  117. /*
  118. ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  119. │ Rule: All proposal specific (non-view) functions should revert if proposal is executed │
  120. │ │
  121. │ In this rule we show that if a function is executed, i.e. execute() was called on the proposal ID, none of the │
  122. │ proposal specific functions can make changes again. Note that we prove that only the `execute()` function can set |
  123. | isExecuted() to true in in `GorvernorChanges.spec`. |
  124. └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  125. */
  126. rule allFunctionsRevertIfExecuted(uint256 pId, env e, method f, calldataarg args)
  127. filtered { f -> operateOnProposal(f) }
  128. {
  129. require isExecuted(pId);
  130. requireInvariant noBothExecutedAndCanceled(pId);
  131. requireInvariant executedImplyCreated(pId);
  132. helperFunctionsWithRevert(e, f, pId);
  133. assert lastReverted, "Function was not reverted";
  134. }
  135. /*
  136. ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  137. │ Rule: All proposal specific (non-view) functions should revert if proposal is canceled │
  138. │ │
  139. │ In this rule we show that if a function is executed, i.e. execute() was called on the proposal ID, non of the │
  140. │ proposal specific functions can make changes again. Note that we prove that only the `execute()` function can set |
  141. | isExecuted() to true in in `GorvernorChanges.spec`. |
  142. └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  143. */
  144. rule allFunctionsRevertIfCanceled(uint256 pId, env e, method f, calldataarg args)
  145. filtered { f -> operateOnProposal(f) }
  146. {
  147. require isCanceled(pId);
  148. requireInvariant noBothExecutedAndCanceled(pId);
  149. requireInvariant canceledImplyCreated(pId);
  150. helperFunctionsWithRevert(e, f, pId);
  151. assert lastReverted, "Function was not reverted";
  152. }
  153. /*
  154. ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  155. │ Rule: Update operation are restricted to executor │
  156. └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  157. */
  158. rule privilegedUpdate(env e, method f, calldataarg args)
  159. filtered { f -> !assumedSafe(f) }
  160. {
  161. address executorBefore = getExecutor();
  162. uint256 quorumNumeratorBefore = quorumNumerator();
  163. address timelockBefore = timelock();
  164. f(e, args);
  165. assert quorumNumerator() != quorumNumeratorBefore => e.msg.sender == executorBefore;
  166. assert timelock() != timelockBefore => e.msg.sender == executorBefore;
  167. }