Governor.helpers.spec 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 == onERC721Received(address,address,uint256,bytes).selector ||
  53. f.selector == onERC1155Received(address,address,uint256,uint256,bytes).selector ||
  54. f.selector == onERC1155BatchReceived(address,address,uint256[],uint256[],bytes).selector;
  55. definition voting(method f) returns bool =
  56. f.selector == castVote(uint256,uint8).selector ||
  57. f.selector == castVoteWithReason(uint256,uint8,string).selector ||
  58. f.selector == castVoteWithReasonAndParams(uint256,uint8,string,bytes).selector;
  59. definition votingBySig(method f) returns bool =
  60. f.selector == castVoteBySig(uint256,uint8,uint8,bytes32,bytes32).selector ||
  61. f.selector == castVoteWithReasonAndParamsBySig(uint256,uint8,string,bytes,uint8,bytes32,bytes32).selector;
  62. definition votingAll(method f) returns bool =
  63. voting(f) || votingBySig(f);
  64. /*
  65. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  66. โ”‚ Helper functions โ”‚
  67. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  68. */
  69. function helperVoteWithRevert(env e, method f, uint256 pId, address voter, uint8 support) returns uint256 {
  70. if (f.selector == castVote(uint256,uint8).selector)
  71. {
  72. require e.msg.sender == voter;
  73. return castVote@withrevert(e, pId, support);
  74. }
  75. else if (f.selector == castVoteWithReason(uint256,uint8,string).selector)
  76. {
  77. string reason;
  78. require e.msg.sender == voter && validString(reason);
  79. return castVoteWithReason@withrevert(e, pId, support, reason);
  80. }
  81. else if (f.selector == castVoteWithReasonAndParams(uint256,uint8,string,bytes).selector)
  82. {
  83. string reason; bytes params;
  84. require e.msg.sender == voter && validString(reason) && validBytes(params);
  85. return castVoteWithReasonAndParams@withrevert(e, pId, support, reason, params);
  86. }
  87. else
  88. {
  89. calldataarg args;
  90. f(e, args);
  91. return 0;
  92. }
  93. }
  94. function helperFunctionsWithRevert(env e, method f, uint256 pId) {
  95. if (f.selector == propose(address[],uint256[],bytes[],string).selector)
  96. {
  97. address[] targets; uint256[] values; bytes[] calldatas; string descr;
  98. require pId == propose@withrevert(e, targets, values, calldatas, descr);
  99. }
  100. else if (f.selector == queue(address[],uint256[],bytes[],bytes32).selector)
  101. {
  102. address[] targets; uint256[] values; bytes[] calldatas; bytes32 descrHash;
  103. require pId == queue@withrevert(e, targets, values, calldatas, descrHash);
  104. }
  105. else if (f.selector == execute(address[],uint256[],bytes[],bytes32).selector)
  106. {
  107. address[] targets; uint256[] values; bytes[] calldatas; bytes32 descrHash;
  108. require pId == execute@withrevert(e, targets, values, calldatas, descrHash);
  109. }
  110. else if (f.selector == cancel(address[],uint256[],bytes[],bytes32).selector)
  111. {
  112. address[] targets; uint256[] values; bytes[] calldatas; bytes32 descrHash;
  113. require pId == cancel@withrevert(e, targets, values, calldatas, descrHash);
  114. }
  115. else if (f.selector == castVote(uint256,uint8).selector)
  116. {
  117. uint8 support;
  118. castVote@withrevert(e, pId, support);
  119. }
  120. else if (f.selector == castVoteWithReason(uint256,uint8,string).selector)
  121. {
  122. uint8 support; string reason;
  123. castVoteWithReason@withrevert(e, pId, support, reason);
  124. }
  125. else if (f.selector == castVoteWithReasonAndParams(uint256,uint8,string,bytes).selector)
  126. {
  127. uint8 support; string reason; bytes params;
  128. castVoteWithReasonAndParams@withrevert(e, pId, support, reason, params);
  129. }
  130. else if (f.selector == castVoteBySig(uint256,uint8,uint8,bytes32,bytes32).selector)
  131. {
  132. uint8 support; uint8 v; bytes32 r; bytes32 s;
  133. castVoteBySig@withrevert(e, pId, support, v, r, s);
  134. }
  135. else if (f.selector == castVoteWithReasonAndParamsBySig(uint256,uint8,string,bytes,uint8,bytes32,bytes32).selector)
  136. {
  137. uint8 support; string reason; bytes params; uint8 v; bytes32 r; bytes32 s;
  138. castVoteWithReasonAndParamsBySig@withrevert(e, pId, support, reason, params, v, r, s);
  139. }
  140. else
  141. {
  142. calldataarg args;
  143. f(e, args);
  144. }
  145. }