Governor.helpers.spec 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import "methods/IGovernor.spec"
  2. /*
  3. ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  4. │ States │
  5. └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  6. */
  7. definition UNSET() returns uint8 = 255;
  8. definition PENDING() returns uint8 = 0;
  9. definition ACTIVE() returns uint8 = 1;
  10. definition CANCELED() returns uint8 = 2;
  11. definition DEFEATED() returns uint8 = 3;
  12. definition SUCCEEDED() returns uint8 = 4;
  13. definition QUEUED() returns uint8 = 5;
  14. definition EXPIRED() returns uint8 = 6;
  15. definition EXECUTED() returns uint8 = 7;
  16. function safeState(env e, uint256 pId) returns uint8 {
  17. uint8 result = state@withrevert(e, pId);
  18. return lastReverted ? UNSET() : result;
  19. }
  20. /*
  21. ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  22. │ Filters │
  23. └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  24. */
  25. definition skip(method f) returns bool =
  26. f.isView ||
  27. f.isFallback ||
  28. f.selector == relay(address,uint256,bytes).selector ||
  29. f.selector == 0xb9a61961 || // __acceptAdmin()
  30. f.selector == onERC721Received(address,address,uint256,bytes).selector ||
  31. f.selector == onERC1155Received(address,address,uint256,uint256,bytes).selector ||
  32. f.selector == onERC1155BatchReceived(address,address,uint256[],uint256[],bytes).selector;
  33. definition voting(method f) returns bool =
  34. f.selector == castVote(uint256,uint8).selector ||
  35. f.selector == castVoteWithReason(uint256,uint8,string).selector ||
  36. f.selector == castVoteWithReasonAndParams(uint256,uint8,string,bytes).selector;
  37. /*
  38. ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  39. │ Helper functions │
  40. └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  41. */
  42. function helperVoteWithRevert(env e, method f, uint256 pId, address voter, uint8 support) returns uint256 {
  43. string reason; bytes params; uint8 v; bytes32 s; bytes32 r;
  44. if (f.selector == castVote(uint256,uint8).selector)
  45. {
  46. require e.msg.sender == voter;
  47. return castVote@withrevert(e, pId, support);
  48. }
  49. else if (f.selector == castVoteWithReason(uint256,uint8,string).selector)
  50. {
  51. require e.msg.sender == voter;
  52. return castVoteWithReason@withrevert(e, pId, support, reason);
  53. }
  54. else if (f.selector == castVoteWithReasonAndParams(uint256,uint8,string,bytes).selector)
  55. {
  56. require e.msg.sender == voter;
  57. return castVoteWithReasonAndParams@withrevert(e, pId, support, reason, params);
  58. }
  59. else
  60. {
  61. calldataarg args;
  62. f@withrevert(e, args);
  63. return 0;
  64. }
  65. }
  66. function helperFunctionsWithRevert(env e, method f, uint256 pId) {
  67. if (f.selector == propose(address[], uint256[], bytes[], string).selector)
  68. {
  69. address[] targets; uint256[] values; bytes[] calldatas; string description;
  70. require pId == propose@withrevert(e, targets, values, calldatas, description);
  71. }
  72. else if (f.selector == queue(address[], uint256[], bytes[], bytes32).selector)
  73. {
  74. address[] targets; uint256[] values; bytes[] calldatas; bytes32 description;
  75. require pId == queue@withrevert(e, targets, values, calldatas, description);
  76. }
  77. else if (f.selector == execute(address[], uint256[], bytes[], bytes32).selector)
  78. {
  79. address[] targets; uint256[] values; bytes[] calldatas; bytes32 description;
  80. require pId == execute@withrevert(e, targets, values, calldatas, description);
  81. }
  82. else if (f.selector == cancel(address[], uint256[], bytes[], bytes32).selector)
  83. {
  84. address[] targets; uint256[] values; bytes[] calldatas; bytes32 description;
  85. require pId == cancel@withrevert(e, targets, values, calldatas, description);
  86. }
  87. else if (f.selector == castVote(uint256, uint8).selector)
  88. {
  89. uint8 support;
  90. castVote@withrevert(e, pId, support);
  91. }
  92. else if (f.selector == castVoteWithReason(uint256, uint8, string).selector)
  93. {
  94. uint8 support; string reason;
  95. castVoteWithReason@withrevert(e, pId, support, reason);
  96. }
  97. else if (f.selector == castVoteWithReasonAndParams(uint256,uint8,string,bytes).selector)
  98. {
  99. uint8 support; string reason; bytes params;
  100. castVoteWithReasonAndParams@withrevert(e, pId, support, reason, params);
  101. }
  102. else if (f.selector == castVoteBySig(uint256, uint8,uint8, bytes32, bytes32).selector)
  103. {
  104. uint8 support; uint8 v; bytes32 r; bytes32 s;
  105. castVoteBySig@withrevert(e, pId, support, v, r, s);
  106. }
  107. else if (f.selector == castVoteWithReasonAndParamsBySig(uint256,uint8,string,bytes,uint8,bytes32,bytes32).selector)
  108. {
  109. uint8 support; string reason; bytes params; uint8 v; bytes32 r; bytes32 s;
  110. castVoteWithReasonAndParamsBySig@withrevert(e, pId, support, reason, params, v, r, s);
  111. }
  112. else
  113. {
  114. calldataarg args;
  115. f@withrevert(e, args);
  116. }
  117. }