GovernorCountingSimple.spec 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //////////////////////////////////////////////////////////////////////////////
  2. ///////////////////// Governor.sol base definitions //////////////////////////
  3. //////////////////////////////////////////////////////////////////////////////
  4. methods {
  5. proposalSnapshot(uint256) returns uint256 envfree // matches proposalVoteStart
  6. proposalDeadline(uint256) returns uint256 envfree
  7. hashProposal(address[],uint256[],bytes[],bytes32) returns uint256 envfree
  8. isExecuted(uint256) returns bool envfree
  9. isCanceled(uint256) returns bool envfree
  10. // initialized(uint256) returns bool envfree
  11. hasVoted(uint256, address) returns bool
  12. castVote(uint256, uint8) returns uint256
  13. // internal functions made public in harness:
  14. _quorumReached(uint256) returns bool envfre
  15. _voteSucceeded(uint256) returns bool envfree
  16. // getter for checking the sums
  17. ghost_sum_vote_power_by_id(uint256) returns uint256 envfree
  18. }
  19. //////////////////////////////////////////////////////////////////////////////
  20. ///////////////////////////////// GHOSTS /////////////////////////////////////
  21. //////////////////////////////////////////////////////////////////////////////
  22. ghost sum_all_votes_power() returns uint256 {
  23. init_state axiom sum_all_votes_power() == 0;
  24. }
  25. hook Sstore ghost_sum_vote_power_by_id[KEY uint256 pId] uint256 current_power (uint256 old_power) STORAGE{
  26. havoc sum_all_votes_power assuming sum_all_votes_power@new() == sum_all_votes_power@old() - old_power + current_power;
  27. }
  28. ghost tracked_weight(uint256) returns uint256 {
  29. init_state axiom forall uint256 p. tracked_weight(p) == 0;
  30. }
  31. ghost sum_tracked_weight() returns uint256 {
  32. init_state axiom sum_tracked_weight() == 0;
  33. }
  34. /*
  35. function update_tracked_weights(uint256 pId, uint256 votes, uint256 old_votes) {
  36. havoc tracked_weight assuming forall uint256 p. (p == pId => tracked_weight@new(p) == tracked_weight@old(p) - old_votes + votes) &&
  37. (p != pId => tracked_weight@new(p) == tracked_weight@old(p));
  38. havoc sum_tracked_weight assuming sum_tracked_weight@new() == sum_tracked_weight@old() - old_votes + votes;
  39. }*/
  40. hook Sstore _proposalVotes[KEY uint256 pId].againstVotes uint256 votes (uint256 old_votes) STORAGE {
  41. //update_tracked_weights(pId, votes, old_votes);
  42. havoc tracked_weight assuming forall uint256 p. (p == pId => tracked_weight@new(p) == tracked_weight@old(p) - old_votes + votes) &&
  43. (p != pId => tracked_weight@new(p) == tracked_weight@old(p));
  44. havoc sum_tracked_weight assuming sum_tracked_weight@new() == sum_tracked_weight@old() - old_votes + votes;
  45. }
  46. hook Sstore _proposalVotes[KEY uint256 pId].forVotes uint256 votes (uint256 old_votes) STORAGE {
  47. //update_tracked_weights(pId, votes, old_votes);
  48. havoc tracked_weight assuming forall uint256 p. (p == pId => tracked_weight@new(p) == tracked_weight@old(p) - old_votes + votes) &&
  49. (p != pId => tracked_weight@new(p) == tracked_weight@old(p));
  50. havoc sum_tracked_weight assuming sum_tracked_weight@new() == sum_tracked_weight@old() - old_votes + votes;
  51. }
  52. hook Sstore _proposalVotes[KEY uint256 pId].abstainVotes uint256 votes (uint256 old_votes) STORAGE {
  53. //update_tracked_weights(pId, votes, old_votes);
  54. havoc tracked_weight assuming forall uint256 p. (p == pId => tracked_weight@new(p) == tracked_weight@old(p) - old_votes + votes) &&
  55. (p != pId => tracked_weight@new(p) == tracked_weight@old(p));
  56. havoc sum_tracked_weight assuming sum_tracked_weight@new() == sum_tracked_weight@old() - old_votes + votes;
  57. }
  58. //////////////////////////////////////////////////////////////////////////////
  59. ////////////////////////////// INVARIANTS ////////////////////////////////////
  60. //////////////////////////////////////////////////////////////////////////////
  61. /*
  62. * sum of all votes casted is equal to the sum of voting power of those who voted, per each proposal
  63. */
  64. invariant SumOfVotesCastEqualSumOfPowerOfVotedPerProposal(uint256 pId)
  65. tracked_weight(pId) == ghost_sum_vote_power_by_id(pId)
  66. /*
  67. * sum of all votes casted is equal to the sum of voting power of those who voted
  68. */
  69. invariant SumOfVotesCastEqualSumOfPowerOfVoted()
  70. sum_tracked_weight() == sum_all_votes_power()