GovernorCountingSimple.spec 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import "GovernorBase.spec"
  2. methods {
  3. ghost_sum_vote_power_by_id(uint256) returns uint256 envfree
  4. //_getVotes(address, uint256) returns uint256
  5. }
  6. //////////////////////////////////////////////////////////////////////////////
  7. ///////////////////////////////// GHOSTS /////////////////////////////////////
  8. //////////////////////////////////////////////////////////////////////////////
  9. ghost sum_all_votes_power() returns uint256 {
  10. init_state axiom sum_all_votes_power() == 0;
  11. }
  12. hook Sstore ghost_sum_vote_power_by_id[KEY uint256 pId] uint256 current_power (uint256 old_power) STORAGE{
  13. havoc sum_all_votes_power assuming sum_all_votes_power@new() == sum_all_votes_power@old() - old_power + current_power;
  14. }
  15. ghost tracked_weight(uint256) returns uint256 {
  16. init_state axiom forall uint256 p. tracked_weight(p) == 0;
  17. }
  18. ghost sum_tracked_weight() returns uint256 {
  19. init_state axiom sum_tracked_weight() == 0;
  20. }
  21. hook Sstore _proposalVotes[KEY uint256 pId].againstVotes uint256 votes (uint256 old_votes) STORAGE {
  22. havoc tracked_weight assuming forall uint256 p. (p == pId => tracked_weight@new(p) == tracked_weight@old(p) - old_votes + votes) &&
  23. (p != pId => tracked_weight@new(p) == tracked_weight@old(p));
  24. havoc sum_tracked_weight assuming sum_tracked_weight@new() == sum_tracked_weight@old() - old_votes + votes;
  25. }
  26. hook Sstore _proposalVotes[KEY uint256 pId].forVotes uint256 votes (uint256 old_votes) STORAGE {
  27. havoc tracked_weight assuming forall uint256 p. (p == pId => tracked_weight@new(p) == tracked_weight@old(p) - old_votes + votes) &&
  28. (p != pId => tracked_weight@new(p) == tracked_weight@old(p));
  29. havoc sum_tracked_weight assuming sum_tracked_weight@new() == sum_tracked_weight@old() - old_votes + votes;
  30. }
  31. hook Sstore _proposalVotes[KEY uint256 pId].abstainVotes uint256 votes (uint256 old_votes) STORAGE {
  32. havoc tracked_weight assuming forall uint256 p. (p == pId => tracked_weight@new(p) == tracked_weight@old(p) - old_votes + votes) &&
  33. (p != pId => tracked_weight@new(p) == tracked_weight@old(p));
  34. havoc sum_tracked_weight assuming sum_tracked_weight@new() == sum_tracked_weight@old() - old_votes + votes;
  35. }
  36. /*
  37. ghost totalVotesPossible() returns uint256{
  38. init_state axiom totalVotesPossible() == 0;
  39. }
  40. hook Sstore _getVotes[KEY address pId][KEY uint256 blockNumber] uint256 voteWeight (uint old_voteWeight) STORAGE
  41. */
  42. //////////////////////////////////////////////////////////////////////////////
  43. ////////////////////////////// INVARIANTS ////////////////////////////////////
  44. //////////////////////////////////////////////////////////////////////////////
  45. /*
  46. * sum of all votes casted is equal to the sum of voting power of those who voted, per each proposal
  47. */
  48. invariant SumOfVotesCastEqualSumOfPowerOfVotedPerProposal(uint256 pId)
  49. tracked_weight(pId) == ghost_sum_vote_power_by_id(pId)
  50. /*
  51. * sum of all votes casted is equal to the sum of voting power of those who voted
  52. */
  53. // invariant SumOfVotesCastEqualSumOfPowerOfVoted()
  54. // sum_tracked_weight() == sum_all_votes_power()
  55. /*
  56. * totalVoted >= vote(id)
  57. */
  58. invariant OneIsNotMoreThanAll(uint256 pId)
  59. sum_all_votes_power() >= tracked_weight(pId)
  60. /*
  61. * totalVotesPossible (supply/weight) >= votePower(id)
  62. */
  63. invariant possibleTotalVotes(uint pId)