Governor.helpers.spec 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import "helpers.spec"
  2. import "methods/IGovernor.spec"
  3. /*
  4. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  5. โ”‚ Sanity โ”‚
  6. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  7. */
  8. function clockSanity(env e) returns bool {
  9. return e.block.number < max_uint48()
  10. && e.block.timestamp < max_uint48()
  11. && clock(e) > 0;
  12. }
  13. function validProposal(address[] targets, uint256[] values, bytes[] calldatas) returns bool {
  14. return targets.length > 0
  15. && targets.length == values.length
  16. && targets.length == calldatas.length;
  17. }
  18. function validString(string s) returns bool {
  19. return s.length < 0xffff;
  20. }
  21. function validBytes(bytes b) returns bool {
  22. return b.length < 0xffff;
  23. }
  24. /*
  25. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  26. โ”‚ States โ”‚
  27. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  28. */
  29. definition UNSET() returns uint8 = 255;
  30. definition PENDING() returns uint8 = 0;
  31. definition ACTIVE() returns uint8 = 1;
  32. definition CANCELED() returns uint8 = 2;
  33. definition DEFEATED() returns uint8 = 3;
  34. definition SUCCEEDED() returns uint8 = 4;
  35. definition QUEUED() returns uint8 = 5;
  36. definition EXPIRED() returns uint8 = 6;
  37. definition EXECUTED() returns uint8 = 7;
  38. function safeState(env e, uint256 pId) returns uint8 {
  39. return proposalCreated(pId) ? state(e, pId): UNSET();
  40. }
  41. definition proposalCreated(uint256 pId) returns bool =
  42. proposalSnapshot(pId) > 0 && proposalDeadline(pId) > 0 && proposalProposer(pId) != 0;
  43. /*
  44. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  45. โ”‚ Filters โ”‚
  46. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  47. */
  48. definition skip(method f) returns bool =
  49. f.isView ||
  50. f.isFallback ||
  51. f.selector == relay(address,uint256,bytes).selector ||
  52. f.selector == 0xb9a61961 || // __acceptAdmin()
  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 == propose@withrevert(e, targets, values, calldatas, descr);
  100. }
  101. else if (f.selector == queue(address[],uint256[],bytes[],bytes32).selector)
  102. {
  103. address[] targets; uint256[] values; bytes[] calldatas; bytes32 descrHash;
  104. require pId == queue@withrevert(e, targets, values, calldatas, descrHash);
  105. }
  106. else if (f.selector == execute(address[],uint256[],bytes[],bytes32).selector)
  107. {
  108. address[] targets; uint256[] values; bytes[] calldatas; bytes32 descrHash;
  109. require pId == execute@withrevert(e, targets, values, calldatas, descrHash);
  110. }
  111. else if (f.selector == cancel(address[],uint256[],bytes[],bytes32).selector)
  112. {
  113. address[] targets; uint256[] values; bytes[] calldatas; bytes32 descrHash;
  114. require pId == cancel@withrevert(e, targets, values, calldatas, descrHash);
  115. }
  116. else if (f.selector == castVote(uint256,uint8).selector)
  117. {
  118. uint8 support;
  119. castVote@withrevert(e, pId, support);
  120. }
  121. else if (f.selector == castVoteWithReason(uint256,uint8,string).selector)
  122. {
  123. uint8 support; string reason;
  124. castVoteWithReason@withrevert(e, pId, support, reason);
  125. }
  126. else if (f.selector == castVoteWithReasonAndParams(uint256,uint8,string,bytes).selector)
  127. {
  128. uint8 support; string reason; bytes params;
  129. castVoteWithReasonAndParams@withrevert(e, pId, support, reason, params);
  130. }
  131. else if (f.selector == castVoteBySig(uint256,uint8,uint8,bytes32,bytes32).selector)
  132. {
  133. uint8 support; uint8 v; bytes32 r; bytes32 s;
  134. castVoteBySig@withrevert(e, pId, support, v, r, s);
  135. }
  136. else if (f.selector == castVoteWithReasonAndParamsBySig(uint256,uint8,string,bytes,uint8,bytes32,bytes32).selector)
  137. {
  138. uint8 support; string reason; bytes params; uint8 v; bytes32 r; bytes32 s;
  139. castVoteWithReasonAndParamsBySig@withrevert(e, pId, support, reason, params, v, r, s);
  140. }
  141. else
  142. {
  143. calldataarg args;
  144. f(e, args);
  145. }
  146. }