AccessManaged.spec 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. // Summarization for external calls (cause havoc in isConsumingScheduledOpClean invariant):
  10. // Called by AccessManager.updateAuthority() on target contracts. This modifies
  11. // the target contract's authority but doesn't affect the AccessManager's _consumingSchedule state.
  12. function _.setAuthority(address) external => NONDET;
  13. // Called by AccessManaged._checkCanCall() to consume scheduled operations on the AccessManager.
  14. // This function should complete successfully and only affect the AccessManager's internal state,
  15. // not the _consumingSchedule state of the calling AccessManaged contract.
  16. function _.consumeScheduledOp(address, bytes) external => NONDET;
  17. // For unresolved external calls (like low-level target.call{value: value}(data))
  18. // made via Address.functionCallWithValue in AccessManager.execute().
  19. unresolved external in _._ => DISPATCH [] default NONDET;
  20. }
  21. invariant isConsumingScheduledOpClean()
  22. isConsumingScheduledOp() == to_bytes4(0);
  23. rule callRestrictedFunction(env e) {
  24. bool immediate = authority_canCall_immediate(e, e.msg.sender);
  25. uint32 delay = authority_canCall_delay(e, e.msg.sender);
  26. uint48 scheduleBefore = authority_getSchedule(e, e.msg.sender);
  27. someFunction@withrevert(e);
  28. bool success = !lastReverted;
  29. uint48 scheduleAfter = authority_getSchedule(e, e.msg.sender);
  30. // can only call if immediate, or (with delay) by consuming a scheduled op
  31. assert success => (
  32. immediate ||
  33. (
  34. delay > 0 &&
  35. isSetAndPast(e, scheduleBefore) &&
  36. scheduleAfter == 0
  37. )
  38. );
  39. }