GovernorBase.spec 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // Governor.sol base definitions
  2. methods {
  3. proposalSnapshot(uint256) returns uint256 envfree // matches proposalVoteStart
  4. proposalDeadline(uint256) returns uint256 envfree
  5. hashProposal(address[],uint256[],bytes[],bytes32) returns uint256 envfree
  6. isExecuted(uint256) returns bool envfree
  7. isCanceled(uint256) returns bool envfree
  8. initialized(uint256) returns bool envfree
  9. hasVoted(uint256, address) returns bool
  10. castVote(uint256, uint8) returns uint256
  11. // internal functions made public in harness:
  12. _quorumReached(uint256) returns bool envfree
  13. _voteSucceeded(uint256) returns bool envfree
  14. }
  15. //////////////////////////////////////////////////////////////////////////////
  16. ////////////////////////////// INVARIANTS ////////////////////////////////////
  17. //////////////////////////////////////////////////////////////////////////////
  18. /**
  19. * A proposal cannot end unless it started.
  20. */
  21. //invariant voteStartBeforeVoteEnd1(uint256 pId) proposalSnapshot(pId) < proposalDeadline(pId)
  22. invariant voteStartBeforeVoteEnd(uint256 pId)
  23. (proposalSnapshot(pId) > 0 => proposalSnapshot(pId) < proposalDeadline(pId))
  24. && (proposalSnapshot(pId) == 0 => proposalDeadline(pId) == 0)
  25. /*
  26. proposalSnapshot(pId) < proposalDeadline(pId) || (proposalSnapshot(pId) == 0 && proposalDeadline(pId) == 0)
  27. { preserved {
  28. require initialized(pId) == true;
  29. }}
  30. */
  31. /**
  32. * A proposal cannot be both executed and canceled.
  33. */
  34. invariant noBothExecutedAndCanceled(uint256 pId) !isExecuted(pId) || !isCanceled(pId)
  35. /**
  36. * A proposal cannot be neither executed nor canceled before it starts
  37. */
  38. invariant noExecuteOrCancelBeforeStarting(env e, uint256 pId) e.block.number < proposalSnapshot(pId)
  39. => !isExecuted(pId) && !isCanceled(pId)
  40. /**
  41. * A proposal could be executed only if quorum was reached and vote succeeded
  42. */
  43. invariant executionOnlyIfQuoromReachedAndVoteSucceeded(uint256 pId) isExecuted(pId) => _quorumReached(pId) && _voteSucceeded(pId)
  44. /*
  45. * No functions should be allowed to run after a job is deemed as canceled
  46. */
  47. invariant cannotSetIfCanceled(uint256 pId)
  48. isCanceled(pId) => lastReverted == true
  49. /*
  50. * No functions should be allowed to run after a job is deemed as executed
  51. */
  52. invariant cannotSetIfExecuted(uint256 pId)
  53. isExecuted(pId) => lastReverted == true
  54. {
  55. preserved execute(address[] targets, uint256[] values, bytes[] calldatas, bytes32 descriptionHash) with (env e)
  56. {
  57. require(isExecuted(pId));
  58. }
  59. }
  60. //////////////////////////////////////////////////////////////////////////////
  61. /////////////////////////////////// RULES ////////////////////////////////////
  62. //////////////////////////////////////////////////////////////////////////////
  63. /**
  64. * The voting must start not before the proposal’s creation time
  65. */
  66. rule noStartBeforeCreation(uint256 pId) {
  67. uint previousStart = proposalSnapshot(pId);
  68. require previousStart == 0;
  69. env e;
  70. calldataarg arg;
  71. propose(e, arg);
  72. uint newStart = proposalSnapshot(pId);
  73. // if created, start is after creation
  74. assert newStart != 0 => newStart >= e.block.number;
  75. }
  76. /**
  77. * Check hashProposal hashing is reliable (different inputs lead to different buffers hashed)
  78. */
  79. /*
  80. rule checkHashProposal {
  81. address[] t1;
  82. address[] t2;
  83. uint256[] v1;
  84. uint256[] v2;
  85. bytes[] c1;
  86. bytes[] c2;
  87. bytes32 d1;
  88. bytes32 d2;
  89. uint256 h1 = hashProposal(t1,v1,c1,d1);
  90. uint256 h2 = hashProposal(t2,v2,c2,d2);
  91. bool equalHashes = h1 == h2;
  92. assert equalHashes => t1.length == t2.length;
  93. assert equalHashes => v1.length == v2.length;
  94. assert equalHashes => c1.length == c2.length;
  95. assert equalHashes => d1 == d2;
  96. }
  97. */
  98. /**
  99. * Once a proposal is created, voteStart and voteEnd are immutable
  100. */
  101. rule immutableFieldsAfterProposalCreation(uint256 pId, method f) {
  102. uint _voteStart = proposalSnapshot(pId);
  103. uint _voteEnd = proposalDeadline(pId);
  104. require _voteStart > 0; // proposal was created
  105. env e;
  106. calldataarg arg;
  107. f(e, arg);
  108. uint voteStart_ = proposalSnapshot(pId);
  109. uint voteEnd_ = proposalDeadline(pId);
  110. assert _voteStart == voteStart_;
  111. assert _voteEnd == voteEnd_;
  112. }
  113. /**
  114. * Check if it's possible to vote two time. Relevant to GovernorCountingSimpleHarness.sol contract
  115. */
  116. rule doubleVoting(uint256 pId, uint8 sup) {
  117. env e;
  118. address user = e.msg.sender;
  119. bool votedCheck = hasVoted(e, pId, user);
  120. require votedCheck == true;
  121. castVote@withrevert(e, pId, sup);
  122. bool reverted = lastReverted;
  123. assert reverted, "double voting accured";
  124. }
  125. /**
  126. *
  127. */
  128. rule votingSumAndPower(uint256 pId, uint8 sup, method f) {
  129. }