dao-propose-main.zk 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. constant "DaoProposeMain" {
  2. EcFixedPointShort VALUE_COMMIT_VALUE,
  3. EcFixedPoint VALUE_COMMIT_RANDOM,
  4. }
  5. contract "DaoProposeMain" {
  6. # Proposers total number of gov tokens
  7. Base total_funds,
  8. Scalar total_funds_blind,
  9. # Check the inputs and this proof are for the same token
  10. Base gov_token_blind,
  11. # proposal params
  12. Base proposal_x,
  13. Base proposal_y,
  14. Base proposal_amount,
  15. Base proposal_serial,
  16. Base proposal_token_id,
  17. Base proposal_blind,
  18. # DAO params
  19. Base dao_proposer_limit,
  20. Base dao_quorum,
  21. Base dao_approval_ratio,
  22. Base gov_token_id,
  23. Base dao_public_x,
  24. Base dao_public_y,
  25. Base dao_bulla_blind,
  26. Uint32 dao_leaf_pos,
  27. MerklePath dao_path,
  28. }
  29. circuit "DaoProposeMain" {
  30. token_commit = poseidon_hash(gov_token_id, gov_token_blind);
  31. constrain_instance(token_commit);
  32. dao_bulla = poseidon_hash(
  33. dao_proposer_limit,
  34. dao_quorum,
  35. dao_approval_ratio,
  36. gov_token_id,
  37. dao_public_x,
  38. dao_public_y,
  39. dao_bulla_blind,
  40. # @tmp-workaround
  41. dao_bulla_blind,
  42. );
  43. dao_root = calculate_merkle_root(dao_leaf_pos, dao_path, dao_bulla);
  44. constrain_instance(dao_root);
  45. # Proves this DAO is valid
  46. # Rangeproof check for proposal amount
  47. # TODO: waiting on this opcode in zkas
  48. #
  49. # greater_than_zero(amount)
  50. #
  51. # Use this temporary workaround. ec_mul_short() does an internal rangeproof
  52. rangeproof = ec_mul_short(proposal_amount, VALUE_COMMIT_VALUE);
  53. # TODO: check total_funds >= proposer_limit
  54. #
  55. # greater_than_or_equal(total_funds, proposer_limit)
  56. #
  57. # Pedersen commitment for coin's value
  58. vcv = ec_mul_short(total_funds, VALUE_COMMIT_VALUE);
  59. vcr = ec_mul(total_funds_blind, VALUE_COMMIT_RANDOM);
  60. total_funds_commit = ec_add(vcv, vcr);
  61. # Since total_funds_commit is a curve point, we fetch its coordinates
  62. # and constrain them:
  63. total_funds_commit_x = ec_get_x(total_funds_commit);
  64. total_funds_commit_y = ec_get_y(total_funds_commit);
  65. constrain_instance(total_funds_commit_x);
  66. constrain_instance(total_funds_commit_y);
  67. }