GovernorCountingSimple.spec 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import "GovernorBase.spec"
  2. methods {
  3. ghost_sum_vote_power_by_id(uint256) returns uint256 envfree
  4. }
  5. //////////////////////////////////////////////////////////////////////////////
  6. ///////////////////////////////// GHOSTS /////////////////////////////////////
  7. //////////////////////////////////////////////////////////////////////////////
  8. ghost sum_all_votes_power() returns uint256 {
  9. init_state axiom sum_all_votes_power() == 0;
  10. }
  11. hook Sstore ghost_sum_vote_power_by_id[KEY uint256 pId] uint256 current_power (uint256 old_power) STORAGE{
  12. havoc sum_all_votes_power assuming sum_all_votes_power@new() == sum_all_votes_power@old() - old_power + current_power;
  13. }
  14. ghost tracked_weight(uint256) returns uint256 {
  15. init_state axiom forall uint256 p. tracked_weight(p) == 0;
  16. }
  17. ghost sum_tracked_weight() returns uint256 {
  18. init_state axiom sum_tracked_weight() == 0;
  19. }
  20. hook Sstore _proposalVotes[KEY uint256 pId].againstVotes uint256 votes (uint256 old_votes) STORAGE {
  21. havoc tracked_weight assuming forall uint256 p. (p == pId => tracked_weight@new(p) == tracked_weight@old(p) - old_votes + votes) &&
  22. (p != pId => tracked_weight@new(p) == tracked_weight@old(p));
  23. havoc sum_tracked_weight assuming sum_tracked_weight@new() == sum_tracked_weight@old() - old_votes + votes;
  24. }
  25. hook Sstore _proposalVotes[KEY uint256 pId].forVotes uint256 votes (uint256 old_votes) STORAGE {
  26. havoc tracked_weight assuming forall uint256 p. (p == pId => tracked_weight@new(p) == tracked_weight@old(p) - old_votes + votes) &&
  27. (p != pId => tracked_weight@new(p) == tracked_weight@old(p));
  28. havoc sum_tracked_weight assuming sum_tracked_weight@new() == sum_tracked_weight@old() - old_votes + votes;
  29. }
  30. hook Sstore _proposalVotes[KEY uint256 pId].abstainVotes uint256 votes (uint256 old_votes) STORAGE {
  31. havoc tracked_weight assuming forall uint256 p. (p == pId => tracked_weight@new(p) == tracked_weight@old(p) - old_votes + votes) &&
  32. (p != pId => tracked_weight@new(p) == tracked_weight@old(p));
  33. havoc sum_tracked_weight assuming sum_tracked_weight@new() == sum_tracked_weight@old() - old_votes + votes;
  34. }
  35. //////////////////////////////////////////////////////////////////////////////
  36. ////////////////////////////// INVARIANTS ////////////////////////////////////
  37. //////////////////////////////////////////////////////////////////////////////
  38. /*
  39. * sum of all votes casted is equal to the sum of voting power of those who voted, per each proposal
  40. */
  41. invariant SumOfVotesCastEqualSumOfPowerOfVotedPerProposal(uint256 pId)
  42. tracked_weight(pId) == ghost_sum_vote_power_by_id(pId)
  43. /*
  44. * sum of all votes casted is equal to the sum of voting power of those who voted
  45. */
  46. invariant SumOfVotesCastEqualSumOfPowerOfVoted()
  47. sum_tracked_weight() == sum_all_votes_power()