AccessManaged.spec 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import "helpers/helpers.spec";
  2. import "methods/IAccessManaged.spec";
  3. methods {
  4. // FV
  5. function someFunction() external;
  6. function authority_canCall_immediate(address) external returns (bool);
  7. function authority_canCall_delay(address) external returns (uint32);
  8. function authority_getSchedule(address) external returns (uint48);
  9. function _hasCode(address) external returns (bool) envfree;
  10. // Summaries
  11. function _.setAuthority(address) external => DISPATCHER(true);
  12. }
  13. invariant isConsumingScheduledOpClean()
  14. isConsumingScheduledOp() == to_bytes4(0);
  15. rule callRestrictedFunction(env e) {
  16. bool immediate = authority_canCall_immediate(e, e.msg.sender);
  17. uint32 delay = authority_canCall_delay(e, e.msg.sender);
  18. uint48 scheduleBefore = authority_getSchedule(e, e.msg.sender);
  19. someFunction@withrevert(e);
  20. bool success = !lastReverted;
  21. uint48 scheduleAfter = authority_getSchedule(e, e.msg.sender);
  22. // can only call if immediate, or (with delay) by consuming a scheduled op
  23. assert success => (
  24. immediate ||
  25. (
  26. delay > 0 &&
  27. isSetAndPast(e, scheduleBefore) &&
  28. scheduleAfter == 0
  29. )
  30. );
  31. }
  32. /*
  33. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  34. โ”‚ Rule: Only valid authorities can be set by the current authority โ”‚
  35. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  36. */
  37. rule setAuthority(env e) {
  38. require nonpayable(e);
  39. address newAuthority;
  40. address previousAuthority = authority();
  41. setAuthority@withrevert(e, newAuthority);
  42. bool success = !lastReverted;
  43. assert success <=> (
  44. previousAuthority == e.msg.sender &&
  45. _hasCode(newAuthority)
  46. );
  47. assert success => newAuthority == authority();
  48. }