GovernorBase.spec 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. /////////////////////////////////// RULES ////////////////////////////////////
  56. //////////////////////////////////////////////////////////////////////////////
  57. /**
  58. * The voting must start not before the proposal’s creation time
  59. */
  60. rule noStartBeforeCreation(uint256 pId) {
  61. uint previousStart = proposalSnapshot(pId);
  62. require previousStart == 0;
  63. env e;
  64. calldataarg arg;
  65. propose(e, arg);
  66. uint newStart = proposalSnapshot(pId);
  67. // if created, start is after creation
  68. assert newStart != 0 => newStart >= e.block.number;
  69. }
  70. /**
  71. * Check hashProposal hashing is reliable (different inputs lead to different buffers hashed)
  72. */
  73. /*
  74. rule checkHashProposal {
  75. address[] t1;
  76. address[] t2;
  77. uint256[] v1;
  78. uint256[] v2;
  79. bytes[] c1;
  80. bytes[] c2;
  81. bytes32 d1;
  82. bytes32 d2;
  83. uint256 h1 = hashProposal(t1,v1,c1,d1);
  84. uint256 h2 = hashProposal(t2,v2,c2,d2);
  85. bool equalHashes = h1 == h2;
  86. assert equalHashes => t1.length == t2.length;
  87. assert equalHashes => v1.length == v2.length;
  88. assert equalHashes => c1.length == c2.length;
  89. assert equalHashes => d1 == d2;
  90. }
  91. */
  92. /**
  93. * Once a proposal is created, voteStart and voteEnd are immutable
  94. */
  95. rule immutableFieldsAfterProposalCreation(uint256 pId, method f) {
  96. uint _voteStart = proposalSnapshot(pId);
  97. uint _voteEnd = proposalDeadline(pId);
  98. require _voteStart > 0; // proposal was created
  99. env e;
  100. calldataarg arg;
  101. f(e, arg);
  102. uint voteStart_ = proposalSnapshot(pId);
  103. uint voteEnd_ = proposalDeadline(pId);
  104. assert _voteStart == voteStart_;
  105. assert _voteEnd == voteEnd_;
  106. }
  107. /**
  108. * Check if it's possible to vote two time. Relevant to GovernorCountingSimpleHarness.sol contract
  109. */
  110. rule doubleVoting(uint256 pId, uint8 sup) {
  111. env e;
  112. address user = e.msg.sender;
  113. bool votedCheck = hasVoted(e, pId, user);
  114. require votedCheck == true;
  115. castVote@withrevert(e, pId, sup);
  116. bool reverted = lastReverted;
  117. assert reverted, "double voting accured";
  118. }
  119. /**
  120. *
  121. */
  122. rule votingSumAndPower(uint256 pId, uint8 sup, method f) {
  123. }