Governor.helpers.spec 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import "helpers.spec"
  2. import "methods/IGovernor.spec"
  3. import "methods/ITimelockController.spec"
  4. /*
  5. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  6. โ”‚ Sanity โ”‚
  7. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  8. */
  9. function clockSanity(env e) returns bool {
  10. return e.block.number < max_uint48()
  11. && e.block.timestamp < max_uint48()
  12. && clock(e) > 0;
  13. }
  14. function validProposal(address[] targets, uint256[] values, bytes[] calldatas) returns bool {
  15. return targets.length > 0
  16. && targets.length == values.length
  17. && targets.length == calldatas.length;
  18. }
  19. function validString(string s) returns bool {
  20. return s.length < 0xffff;
  21. }
  22. function validBytes(bytes b) returns bool {
  23. return b.length < 0xffff;
  24. }
  25. /*
  26. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  27. โ”‚ States โ”‚
  28. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  29. */
  30. definition UNSET() returns uint8 = 255;
  31. definition PENDING() returns uint8 = 0;
  32. definition ACTIVE() returns uint8 = 1;
  33. definition CANCELED() returns uint8 = 2;
  34. definition DEFEATED() returns uint8 = 3;
  35. definition SUCCEEDED() returns uint8 = 4;
  36. definition QUEUED() returns uint8 = 5;
  37. definition EXPIRED() returns uint8 = 6;
  38. definition EXECUTED() returns uint8 = 7;
  39. function safeState(env e, uint256 pId) returns uint8 {
  40. return proposalCreated(pId) ? state(e, pId): UNSET();
  41. }
  42. definition proposalCreated(uint256 pId) returns bool =
  43. proposalSnapshot(pId) > 0 && proposalDeadline(pId) > 0 && proposalProposer(pId) != 0;
  44. /*
  45. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  46. โ”‚ Filters โ”‚
  47. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  48. */
  49. definition skip(method f) returns bool =
  50. f.isView ||
  51. f.isFallback ||
  52. f.selector == relay(address,uint256,bytes).selector ||
  53. f.selector == onERC721Received(address,address,uint256,bytes).selector ||
  54. f.selector == onERC1155Received(address,address,uint256,uint256,bytes).selector ||
  55. f.selector == onERC1155BatchReceived(address,address,uint256[],uint256[],bytes).selector;
  56. definition voting(method f) returns bool =
  57. f.selector == castVote(uint256,uint8).selector ||
  58. f.selector == castVoteWithReason(uint256,uint8,string).selector ||
  59. f.selector == castVoteWithReasonAndParams(uint256,uint8,string,bytes).selector;
  60. definition votingBySig(method f) returns bool =
  61. f.selector == castVoteBySig(uint256,uint8,uint8,bytes32,bytes32).selector ||
  62. f.selector == castVoteWithReasonAndParamsBySig(uint256,uint8,string,bytes,uint8,bytes32,bytes32).selector;
  63. definition votingAll(method f) returns bool =
  64. voting(f) || votingBySig(f);
  65. /*
  66. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  67. โ”‚ Helper functions โ”‚
  68. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  69. */
  70. function helperVoteWithRevert(env e, method f, uint256 pId, address voter, uint8 support) returns uint256 {
  71. if (f.selector == castVote(uint256,uint8).selector)
  72. {
  73. require e.msg.sender == voter;
  74. return castVote@withrevert(e, pId, support);
  75. }
  76. else if (f.selector == castVoteWithReason(uint256,uint8,string).selector)
  77. {
  78. string reason;
  79. require e.msg.sender == voter && validString(reason);
  80. return castVoteWithReason@withrevert(e, pId, support, reason);
  81. }
  82. else if (f.selector == castVoteWithReasonAndParams(uint256,uint8,string,bytes).selector)
  83. {
  84. string reason; bytes params;
  85. require e.msg.sender == voter && validString(reason) && validBytes(params);
  86. return castVoteWithReasonAndParams@withrevert(e, pId, support, reason, params);
  87. }
  88. else
  89. {
  90. calldataarg args;
  91. f(e, args);
  92. return 0;
  93. }
  94. }
  95. function helperFunctionsWithRevert(env e, method f, uint256 pId) {
  96. if (f.selector == propose(address[],uint256[],bytes[],string).selector)
  97. {
  98. address[] targets; uint256[] values; bytes[] calldatas; string descr;
  99. require pId == hashProposal(targets, values, calldatas, descr);
  100. propose@withrevert(e, targets, values, calldatas, descr);
  101. }
  102. else if (f.selector == queue(address[],uint256[],bytes[],bytes32).selector)
  103. {
  104. address[] targets; uint256[] values; bytes[] calldatas; bytes32 descrHash;
  105. require pId == hashProposal(targets, values, calldatas, descrHash);
  106. queue@withrevert(e, targets, values, calldatas, descrHash);
  107. }
  108. else if (f.selector == execute(address[],uint256[],bytes[],bytes32).selector)
  109. {
  110. address[] targets; uint256[] values; bytes[] calldatas; bytes32 descrHash;
  111. require pId == hashProposal(targets, values, calldatas, descrHash);
  112. execute@withrevert(e, targets, values, calldatas, descrHash);
  113. }
  114. else if (f.selector == cancel(address[],uint256[],bytes[],bytes32).selector)
  115. {
  116. address[] targets; uint256[] values; bytes[] calldatas; bytes32 descrHash;
  117. require pId == hashProposal(targets, values, calldatas, descrHash);
  118. cancel@withrevert(e, targets, values, calldatas, descrHash);
  119. }
  120. else if (f.selector == castVote(uint256,uint8).selector)
  121. {
  122. uint8 support;
  123. castVote@withrevert(e, pId, support);
  124. }
  125. else if (f.selector == castVoteWithReason(uint256,uint8,string).selector)
  126. {
  127. uint8 support; string reason;
  128. castVoteWithReason@withrevert(e, pId, support, reason);
  129. }
  130. else if (f.selector == castVoteWithReasonAndParams(uint256,uint8,string,bytes).selector)
  131. {
  132. uint8 support; string reason; bytes params;
  133. castVoteWithReasonAndParams@withrevert(e, pId, support, reason, params);
  134. }
  135. else if (f.selector == castVoteBySig(uint256,uint8,uint8,bytes32,bytes32).selector)
  136. {
  137. uint8 support; uint8 v; bytes32 r; bytes32 s;
  138. castVoteBySig@withrevert(e, pId, support, v, r, s);
  139. }
  140. else if (f.selector == castVoteWithReasonAndParamsBySig(uint256,uint8,string,bytes,uint8,bytes32,bytes32).selector)
  141. {
  142. uint8 support; string reason; bytes params; uint8 v; bytes32 r; bytes32 s;
  143. castVoteWithReasonAndParamsBySig@withrevert(e, pId, support, reason, params, v, r, s);
  144. }
  145. else
  146. {
  147. calldataarg args;
  148. f(e, args);
  149. }
  150. }