dao-propose-main.zk 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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_dest_x,
  13. Base proposal_dest_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 = merkle_root(dao_leaf_pos, dao_path, dao_bulla);
  44. constrain_instance(dao_root);
  45. # Proves this DAO is valid
  46. proposal_bulla = poseidon_hash(
  47. proposal_dest_x,
  48. proposal_dest_y,
  49. proposal_amount,
  50. proposal_serial,
  51. proposal_token_id,
  52. dao_bulla,
  53. proposal_blind,
  54. # @tmp-workaround
  55. proposal_blind,
  56. );
  57. constrain_instance(proposal_bulla);
  58. # Rangeproof check for proposal amount
  59. # TODO: waiting on this opcode in zkas
  60. #
  61. # greater_than_zero(amount)
  62. #
  63. # Use this temporary workaround. ec_mul_short() does an internal rangeproof
  64. rangeproof = ec_mul_short(proposal_amount, VALUE_COMMIT_VALUE);
  65. # This is the main check
  66. # TODO: check total_funds >= proposer_limit
  67. #
  68. # greater_than_or_equal(total_funds, proposer_limit)
  69. #
  70. # Pedersen commitment for coin's value
  71. vcv = ec_mul_short(total_funds, VALUE_COMMIT_VALUE);
  72. vcr = ec_mul(total_funds_blind, VALUE_COMMIT_RANDOM);
  73. total_funds_commit = ec_add(vcv, vcr);
  74. # Since total_funds_commit is a curve point, we fetch its coordinates
  75. # and constrain them:
  76. total_funds_commit_x = ec_get_x(total_funds_commit);
  77. total_funds_commit_y = ec_get_y(total_funds_commit);
  78. constrain_instance(total_funds_commit_x);
  79. constrain_instance(total_funds_commit_y);
  80. }