GovernorBase.spec 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. // internal functions made public in harness:
  9. _quorumReached(uint256) returns bool envfree
  10. _voteSucceeded(uint256) returns bool envfree
  11. }
  12. //////////////////////////////////////////////////////////////////////////////
  13. ////////////////////////////// INVARIANTS ////////////////////////////////////
  14. //////////////////////////////////////////////////////////////////////////////
  15. /**
  16. * A proposal cannot end unless it started.
  17. */
  18. //invariant voteStartBeforeVoteEnd1(uint256 pId) proposalSnapshot(pId) < proposalDeadline(pId)
  19. invariant voteStartBeforeVoteEnd(uint256 pId)
  20. (proposalSnapshot(pId) > 0 => proposalSnapshot(pId) < proposalDeadline(pId))
  21. && (proposalSnapshot(pId) == 0 => proposalDeadline(pId) == 0)
  22. /**
  23. * A proposal cannot be both executed and canceled.
  24. */
  25. invariant noBothExecutedAndCanceled(uint256 pId) !isExecuted(pId) || !isCanceled(pId)
  26. /**
  27. * A proposal cannot be neither executed nor canceled before it starts
  28. */
  29. invariant noExecuteOrCancelBeforeStarting(env e, uint256 pId) e.block.number < proposalSnapshot(pId)
  30. => !isExecuted(pId) && !isCanceled(pId)
  31. /**
  32. * A proposal could be executed only if quorum was reached and vote succeeded
  33. */
  34. invariant executionOnlyIfQuoromReachedAndVoteSucceeded(uint256 pId) isExecuted(pId) => _quorumReached(pId) && _voteSucceeded(pId)
  35. /*
  36. * No functions should be allowed to run after a job is deemed as canceled
  37. */
  38. invariant cannotSetIfCanceled(uint256 pId)
  39. isCanceled(pId) => lastReverted == true
  40. /*
  41. * No functions should be allowed to run after a job is deemed as executed
  42. */
  43. invariant cannotSetIfExecuted(uint256 pId)
  44. isExecuted(pId) => lastReverted == true
  45. //////////////////////////////////////////////////////////////////////////////
  46. /////////////////////////////////// RULES ////////////////////////////////////
  47. //////////////////////////////////////////////////////////////////////////////
  48. /**
  49. * The voting must start not before the proposal’s creation time
  50. */
  51. rule noStartBeforeCreation(uint256 pId) {
  52. uint previousStart = proposalSnapshot(pId);
  53. require previousStart == 0;
  54. env e;
  55. calldataarg arg;
  56. propose(e, arg);
  57. uint newStart = proposalSnapshot(pId);
  58. // if created, start is after creation
  59. assert newStart != 0 => newStart >= e.block.number;
  60. }
  61. /**
  62. * Check hashProposal hashing is reliable (different inputs lead to different buffers hashed)
  63. */
  64. /*
  65. rule checkHashProposal {
  66. address[] t1;
  67. address[] t2;
  68. uint256[] v1;
  69. uint256[] v2;
  70. bytes[] c1;
  71. bytes[] c2;
  72. bytes32 d1;
  73. bytes32 d2;
  74. uint256 h1 = hashProposal(t1,v1,c1,d1);
  75. uint256 h2 = hashProposal(t2,v2,c2,d2);
  76. bool equalHashes = h1 == h2;
  77. assert equalHashes => t1.length == t2.length;
  78. assert equalHashes => v1.length == v2.length;
  79. assert equalHashes => c1.length == c2.length;
  80. assert equalHashes => d1 == d2;
  81. }
  82. */
  83. /**
  84. * Once a proposal is created, voteStart and voteEnd are immutable
  85. */
  86. rule immutableFieldsAfterProposalCreation(uint256 pId, method f) {
  87. uint _voteStart = proposalSnapshot(pId);
  88. uint _voteEnd = proposalDeadline(pId);
  89. require _voteStart > 0; // proposal was created
  90. env e;
  91. calldataarg arg;
  92. f(e, arg);
  93. uint voteStart_ = proposalSnapshot(pId);
  94. uint voteEnd_ = proposalDeadline(pId);
  95. assert _voteStart == voteStart_;
  96. assert _voteEnd == voteEnd_;
  97. }