dao-vote-main.zk 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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,
  17. Base gov_token_id,
  18. Base dao_public_x,
  19. Base dao_public_y,
  20. Base dao_bulla_blind,
  21. # Is the vote yes or no
  22. Base vote_option,
  23. Scalar vote_option_blind,
  24. # Total amount of capital allocated to vote
  25. Base value,
  26. Scalar value_blind,
  27. # Check the inputs and this proof are for the same token
  28. Base gov_token_blind,
  29. }
  30. circuit "DaoVoteMain" {
  31. token_commit = poseidon_hash(gov_token_id, gov_token_blind);
  32. constrain_instance(token_commit);
  33. dao_bulla = poseidon_hash(
  34. dao_proposer_limit,
  35. dao_quorum,
  36. dao_approval_ratio,
  37. gov_token_id,
  38. dao_public_x,
  39. dao_public_y,
  40. dao_bulla_blind,
  41. # @tmp-workaround
  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. # Pedersen commitment for vote option
  62. weighted_vote = base_mul(vote_option, value);
  63. vote_co = ec_mul_short(weighted_vote, VALUE_COMMIT_VALUE);
  64. vote_cr = ec_mul(vote_option_blind, VALUE_COMMIT_RANDOM);
  65. vote_commit = ec_add(vote_co, vote_cr);
  66. # Since vote_commit is a curve point, we fetch its coordinates
  67. # and constrain them:
  68. vote_commit_x = ec_get_x(vote_commit);
  69. vote_commit_y = ec_get_y(vote_commit);
  70. constrain_instance(vote_commit_x);
  71. constrain_instance(vote_commit_y);
  72. # Pedersen commitment for vote value
  73. vcv = ec_mul_short(value, VALUE_COMMIT_VALUE);
  74. vcr = ec_mul(value_blind, VALUE_COMMIT_RANDOM);
  75. value_commit = ec_add(vcv, vcr);
  76. # Since value_commit is a curve point, we fetch its coordinates
  77. # and constrain them:
  78. value_commit_x = ec_get_x(value_commit);
  79. value_commit_y = ec_get_y(value_commit);
  80. constrain_instance(value_commit_x);
  81. constrain_instance(value_commit_y);
  82. # This is the main check
  83. # TODO: vote option should be 0 or 1
  84. #
  85. # assert!(vote_option == 0 || vote_option == 1)
  86. #
  87. }