| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- constant "DaoVoteMain" {
- EcFixedPointShort VALUE_COMMIT_VALUE,
- EcFixedPoint VALUE_COMMIT_RANDOM,
- }
- contract "DaoVoteMain" {
- # proposal params
- Base proposal_dest_x,
- Base proposal_dest_y,
- Base proposal_amount,
- Base proposal_serial,
- Base proposal_token_id,
- Base proposal_blind,
- # DAO params
- Base dao_proposer_limit,
- Base dao_quorum,
- Base dao_approval_ratio,
- Base gov_token_id,
- Base dao_public_x,
- Base dao_public_y,
- Base dao_bulla_blind,
- # Is the vote yes or no
- Base vote_option,
- Scalar vote_option_blind,
- # Total amount of capital allocated to vote
- Base value,
- Scalar value_blind,
- # Check the inputs and this proof are for the same token
- Base gov_token_blind,
- }
- circuit "DaoVoteMain" {
- token_commit = poseidon_hash(gov_token_id, gov_token_blind);
- constrain_instance(token_commit);
- dao_bulla = poseidon_hash(
- dao_proposer_limit,
- dao_quorum,
- dao_approval_ratio,
- gov_token_id,
- dao_public_x,
- dao_public_y,
- dao_bulla_blind,
- # @tmp-workaround
- dao_bulla_blind,
- );
- # Proposal bulla is valid means DAO bulla is also valid
- # because of dao-propose-main.zk, already checks that when
- # we first create the proposal. So it is redundant here.
- proposal_bulla = poseidon_hash(
- proposal_dest_x,
- proposal_dest_y,
- proposal_amount,
- proposal_serial,
- proposal_token_id,
- dao_bulla,
- proposal_blind,
- # @tmp-workaround
- proposal_blind,
- );
- constrain_instance(proposal_bulla);
- # TODO: we need to check the proposal isn't invalidated
- # that is expired or already executed.
- # Pedersen commitment for vote option
- weighted_vote = base_mul(vote_option, value);
- vote_co = ec_mul_short(weighted_vote, VALUE_COMMIT_VALUE);
- vote_cr = ec_mul(vote_option_blind, VALUE_COMMIT_RANDOM);
- vote_commit = ec_add(vote_co, vote_cr);
- # Since vote_commit is a curve point, we fetch its coordinates
- # and constrain them:
- vote_commit_x = ec_get_x(vote_commit);
- vote_commit_y = ec_get_y(vote_commit);
- constrain_instance(vote_commit_x);
- constrain_instance(vote_commit_y);
- # Pedersen commitment for vote value
- vcv = ec_mul_short(value, VALUE_COMMIT_VALUE);
- vcr = ec_mul(value_blind, VALUE_COMMIT_RANDOM);
- value_commit = ec_add(vcv, vcr);
- # Since value_commit is a curve point, we fetch its coordinates
- # and constrain them:
- value_commit_x = ec_get_x(value_commit);
- value_commit_y = ec_get_y(value_commit);
- constrain_instance(value_commit_x);
- constrain_instance(value_commit_y);
- # This is the main check
- # TODO: vote option should be 0 or 1
- #
- # assert!(vote_option == 0 || vote_option == 1)
- #
- }
|