dao-vote-main.zk 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. constant "DaoVoteMain" {
  2. EcFixedPointShort VALUE_COMMIT_VALUE,
  3. EcFixedPoint VALUE_COMMIT_RANDOM,
  4. }
  5. contract "DaoVoteMain" {
  6. # proposal params
  7. Base proposal_dest_x,
  8. Base proposal_dest_y,
  9. Base proposal_amount,
  10. Base proposal_serial,
  11. Base proposal_token_id,
  12. Base proposal_blind,
  13. # DAO params
  14. Base dao_proposer_limit,
  15. Base dao_quorum,
  16. Base dao_approval_ratio_quot,
  17. Base dao_approval_ratio_base,
  18. Base gov_token_id,
  19. Base dao_public_x,
  20. Base dao_public_y,
  21. Base dao_bulla_blind,
  22. # Is the vote yes or no
  23. Base vote_option,
  24. Scalar yes_vote_blind,
  25. # Total amount of capital allocated to vote
  26. Base all_votes_value,
  27. Scalar all_votes_blind,
  28. # Check the inputs and this proof are for the same token
  29. Base gov_token_blind,
  30. }
  31. circuit "DaoVoteMain" {
  32. token_commit = poseidon_hash(gov_token_id, gov_token_blind);
  33. constrain_instance(token_commit);
  34. dao_bulla = poseidon_hash(
  35. dao_proposer_limit,
  36. dao_quorum,
  37. dao_approval_ratio_quot,
  38. dao_approval_ratio_base,
  39. gov_token_id,
  40. dao_public_x,
  41. dao_public_y,
  42. dao_bulla_blind,
  43. );
  44. # Proposal bulla is valid means DAO bulla is also valid
  45. # because of dao-propose-main.zk, already checks that when
  46. # we first create the proposal. So it is redundant here.
  47. proposal_bulla = poseidon_hash(
  48. proposal_dest_x,
  49. proposal_dest_y,
  50. proposal_amount,
  51. proposal_serial,
  52. proposal_token_id,
  53. dao_bulla,
  54. proposal_blind,
  55. # @tmp-workaround
  56. proposal_blind,
  57. );
  58. constrain_instance(proposal_bulla);
  59. # TODO: we need to check the proposal isn't invalidated
  60. # that is expired or already executed.
  61. # normally we call this yes vote
  62. # Pedersen commitment for vote option
  63. yes_votes_value = base_mul(vote_option, all_votes_value);
  64. yes_votes_value_c = ec_mul_short(yes_votes_value, VALUE_COMMIT_VALUE);
  65. yes_votes_blind_c = ec_mul(yes_vote_blind, VALUE_COMMIT_RANDOM);
  66. yes_votes_commit = ec_add(yes_votes_value_c, yes_votes_blind_c);
  67. # get curve points and constrain
  68. yes_votes_commit_x = ec_get_x(yes_votes_commit);
  69. yes_votes_commit_y = ec_get_y(yes_votes_commit);
  70. constrain_instance(yes_votes_commit_x);
  71. constrain_instance(yes_votes_commit_y);
  72. # Pedersen commitment for vote value
  73. all_votes_c = ec_mul_short(all_votes_value, VALUE_COMMIT_VALUE);
  74. all_votes_blind_c = ec_mul(all_votes_blind, VALUE_COMMIT_RANDOM);
  75. all_votes_commit = ec_add(all_votes_c, all_votes_blind_c);
  76. # get curve points and constrain
  77. all_votes_commit_x = ec_get_x(all_votes_commit);
  78. all_votes_commit_y = ec_get_y(all_votes_commit);
  79. constrain_instance(all_votes_commit_x);
  80. constrain_instance(all_votes_commit_y);
  81. # Vote option should be 0 or 1
  82. bool_check(vote_option);
  83. }