GovernorChanges.spec 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import "helpers.spec"
  2. import "Governor.helpers.spec"
  3. import "GovernorInvariants.spec"
  4. use invariant proposalStateConsistency
  5. /*
  6. ┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  7. │ Rule: Proposal can be switched state only by specific functions │
  8. └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  9. */
  10. rule changes(uint256 pId, env e, method f, calldataarg args)
  11. filtered { f -> !assumedSafe(f) }
  12. {
  13. require clockSanity(e);
  14. requireInvariant proposalStateConsistency(pId);
  15. address user;
  16. bool existBefore = proposalCreated(pId);
  17. bool isExecutedBefore = isExecuted(pId);
  18. bool isCanceledBefore = isCanceled(pId);
  19. bool isQueuedBefore = isQueued(pId);
  20. bool hasVotedBefore = hasVoted(pId, user);
  21. uint256 votesAgainstBefore = getAgainstVotes(pId);
  22. uint256 votesForBefore = getForVotes(pId);
  23. uint256 votesAbstainBefore = getAbstainVotes(pId);
  24. f(e, args);
  25. bool existAfter = proposalCreated(pId);
  26. bool isExecutedAfter = isExecuted(pId);
  27. bool isCanceledAfter = isCanceled(pId);
  28. bool isQueuedAfter = isQueued(pId);
  29. bool hasVotedAfter = hasVoted(pId, user);
  30. uint256 votesAgainstAfter = getAgainstVotes(pId);
  31. uint256 votesForAfter = getForVotes(pId);
  32. uint256 votesAbstainAfter = getAbstainVotes(pId);
  33. // propose, execute, cancel
  34. assert existAfter != existBefore => (!existBefore && f.selector == propose(address[],uint256[],bytes[],string).selector);
  35. assert isExecutedAfter != isExecutedBefore => (!isExecutedBefore && f.selector == execute(address[],uint256[],bytes[],bytes32).selector);
  36. assert isCanceledAfter != isCanceledBefore => (!isCanceledBefore && f.selector == cancel(address[],uint256[],bytes[],bytes32).selector);
  37. // queue is cleared on cancel
  38. assert isQueuedAfter != isQueuedBefore => (
  39. (!isQueuedBefore && f.selector == queue(address[],uint256[],bytes[],bytes32).selector) ||
  40. (isQueuedBefore && f.selector == cancel(address[],uint256[],bytes[],bytes32).selector)
  41. );
  42. // votes
  43. assert hasVotedAfter != hasVotedBefore => (!hasVotedBefore && votingAll(f));
  44. assert votesAgainstAfter != votesAgainstBefore => (votesAgainstAfter > votesAgainstBefore && votingAll(f));
  45. assert votesForAfter != votesForBefore => (votesForAfter > votesForBefore && votingAll(f));
  46. assert votesAbstainAfter != votesAbstainBefore => (votesAbstainAfter > votesAbstainBefore && votingAll(f));
  47. }