GovernorStates.spec 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import "helpers/helpers.spec"
  2. import "helpers/Governor.helpers.spec"
  3. import "GovernorInvariants.spec"
  4. use invariant proposalStateConsistency
  5. use invariant votesImplySnapshotPassed
  6. /*
  7. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  8. โ”‚ Rule: state returns one of the value in the enumeration โ”‚
  9. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  10. */
  11. rule stateConsistency(env e, uint256 pId) {
  12. uint8 result = state(e, pId);
  13. assert (
  14. result == PENDING() ||
  15. result == ACTIVE() ||
  16. result == CANCELED() ||
  17. result == DEFEATED() ||
  18. result == SUCCEEDED() ||
  19. result == QUEUED() ||
  20. result == EXECUTED()
  21. );
  22. }
  23. /*
  24. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  25. โ”‚ Rule: State transitions caused by function calls โ”‚
  26. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  27. */
  28. rule stateTransitionFn(uint256 pId, env e, method f, calldataarg args)
  29. filtered { f -> !assumedSafe(f)
  30. && f.selector != castVoteBySig(uint256,uint8,uint8,bytes32,bytes32).selector
  31. && f.selector != castVoteWithReasonAndParams(uint256,uint8,string,bytes).selector
  32. && f.selector != castVoteWithReason(uint256,uint8,string).selector
  33. && f.selector != castVoteWithReasonAndParamsBySig(uint256,uint8,string,bytes,uint8,bytes32,bytes32).selector
  34. }
  35. {
  36. require clockSanity(e);
  37. require quorumNumeratorLength() < max_uint256; // sanity
  38. uint8 stateBefore = state(e, pId);
  39. f(e, args);
  40. uint8 stateAfter = state(e, pId);
  41. assert (stateBefore != stateAfter) => (
  42. (stateBefore == UNSET() && stateAfter == PENDING() && f.selector == propose(address[],uint256[],bytes[],string).selector ) ||
  43. (stateBefore == PENDING() && stateAfter == CANCELED() && f.selector == cancel(address[],uint256[],bytes[],bytes32).selector ) ||
  44. (stateBefore == SUCCEEDED() && stateAfter == QUEUED() && f.selector == queue(address[],uint256[],bytes[],bytes32).selector ) ||
  45. (stateBefore == SUCCEEDED() && stateAfter == EXECUTED() && f.selector == execute(address[],uint256[],bytes[],bytes32).selector) ||
  46. (stateBefore == QUEUED() && stateAfter == EXECUTED() && f.selector == execute(address[],uint256[],bytes[],bytes32).selector)
  47. );
  48. }
  49. /*
  50. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  51. โ”‚ Rule: State transitions caused by time passing โ”‚
  52. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  53. */
  54. // The timelockId can be set in states QUEUED, EXECUTED and CANCELED. However, checking the full scope of this results
  55. // in a timeout. This is a weaker version that is still useful
  56. invariant noTimelockBeforeEndOfVote(env e, uint256 pId)
  57. state(e, pId) == ACTIVE() => timelockId(pId) == 0
  58. rule stateTransitionWait(uint256 pId, env e1, env e2) {
  59. require clockSanity(e1);
  60. require clockSanity(e2);
  61. require clock(e2) > clock(e1);
  62. // Force the state to be consistent with e1 (before). We want the storage related to `pId` to match what is
  63. // possible before the time passes. We don't want the state transition include elements that cannot have happened
  64. // before e1. This ensure that the e1 โ†’ e2 state transition is purelly a consequence of time passing.
  65. requireInvariant votesImplySnapshotPassed(e1, pId);
  66. requireInvariant noTimelockBeforeEndOfVote(e1, pId);
  67. uint8 stateBefore = state(e1, pId);
  68. uint8 stateAfter = state(e2, pId);
  69. assert (stateBefore != stateAfter) => (
  70. (stateBefore == PENDING() && stateAfter == ACTIVE() ) ||
  71. (stateBefore == PENDING() && stateAfter == DEFEATED() ) ||
  72. (stateBefore == ACTIVE() && stateAfter == SUCCEEDED()) ||
  73. (stateBefore == ACTIVE() && stateAfter == DEFEATED() )
  74. );
  75. }
  76. /*
  77. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  78. โ”‚ Rule: State corresponds to the vote timing and results โ”‚
  79. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  80. */
  81. rule stateIsConsistentWithVotes(uint256 pId, env e) {
  82. require clockSanity(e);
  83. requireInvariant proposalStateConsistency(pId);
  84. uint48 currentClock = clock(e);
  85. uint8 currentState = state(e, pId);
  86. uint256 snapshot = proposalSnapshot(pId);
  87. uint256 deadline = proposalDeadline(pId);
  88. bool quorumSuccess = quorumReached(pId);
  89. bool voteSuccess = voteSucceeded(pId);
  90. // Pending: before vote starts
  91. assert currentState == PENDING() => (
  92. snapshot >= currentClock
  93. );
  94. // Active: after vote starts & before vote ends
  95. assert currentState == ACTIVE() => (
  96. snapshot < currentClock &&
  97. deadline >= currentClock
  98. );
  99. // Succeeded: after vote end, with vote successful and quorum reached
  100. assert currentState == SUCCEEDED() => (
  101. deadline < currentClock &&
  102. (
  103. quorumSuccess &&
  104. voteSuccess
  105. )
  106. );
  107. // Defeated: after vote end, with vote not successful or quorum not reached
  108. assert currentState == DEFEATED() => (
  109. deadline < currentClock &&
  110. (
  111. !quorumSuccess ||
  112. !voteSuccess
  113. )
  114. );
  115. }
  116. /*
  117. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  118. โ”‚ [NEED WORK] Rule: `updateQuorumNumerator` cannot cause quorumReached to change. โ”‚
  119. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  120. */
  121. //// This would be nice, but its way to slow to run because "quorumReached" is a FV nightmare
  122. //// Also, for it to work we need to prove that the checkpoints have (strictly) increasing keys.
  123. // rule onlyVoteCanChangeQuorumReached(uint256 pId, env e, method f, calldataarg args)
  124. // filtered { f -> !assumedSafe(f) }
  125. // {
  126. // require clockSanity(e);
  127. // require clock(e) > proposalSnapshot(pId); // vote has started
  128. // require quorumNumeratorLength() < max_uint256; // sanity
  129. //
  130. // bool quorumReachedBefore = quorumReached(pId);
  131. //
  132. // uint256 snapshot = proposalSnapshot(pId);
  133. // uint256 totalSupply = token_getPastTotalSupply(snapshot);
  134. //
  135. // f(e, args);
  136. //
  137. // // Needed because the prover doesn't understand the checkpoint properties of the voting token.
  138. // require clock(e) > snapshot => token_getPastTotalSupply(snapshot) == totalSupply;
  139. //
  140. // assert quorumReached(pId) != quorumReachedBefore => (
  141. // !quorumReachedBefore &&
  142. // votingAll(f)
  143. // );
  144. // }
  145. //// To prove that, we need to prove that the checkpoints have (strictly) increasing keys.
  146. //// otherwise it gives us counter example where the checkpoint history has keys:
  147. //// [ 12,12,13,13,12] and the lookup obviously fail to get the correct value
  148. // rule quorumUpdateDoesntAffectPastProposals(uint256 pId, env e) {
  149. // require clockSanity(e);
  150. // require clock(e) > proposalSnapshot(pId); // vote has started
  151. // require quorumNumeratorLength() < max_uint256; // sanity
  152. //
  153. // bool quorumReachedBefore = quorumReached(pId);
  154. //
  155. // uint256 newQuorumNumerator;
  156. // updateQuorumNumerator(e, newQuorumNumerator);
  157. //
  158. // assert quorumReached(pId) == quorumReachedBefore;
  159. // }