dao.zk 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. constant "DAO" {
  2. EcFixedPointShort VALUE_COMMIT_VALUE,
  3. EcFixedPoint VALUE_COMMIT_RANDOM,
  4. }
  5. contract "DAO" {
  6. Base spend_contract,
  7. Base cur_balance,
  8. Base old_serial,
  9. Base old_bulla_blind,
  10. Uint32 leaf_pos,
  11. MerklePath merkle_path,
  12. Base amount_to_send,
  13. Base pub_x,
  14. Base pub_y,
  15. Base proposal_blind,
  16. Scalar proposal_value_blind,
  17. Base new_serial,
  18. Base new_bulla_blind,
  19. }
  20. circuit "DAO" {
  21. # Enforce spend contract
  22. constrain_instance(spend_contract);
  23. # Reveal serial number
  24. constrain_instance(old_serial);
  25. # Poseidon hash of the current treasury
  26. bulla = poseidon_hash(
  27. spend_contract,
  28. cur_balance,
  29. old_serial,
  30. old_bulla_blind,
  31. );
  32. # Enforce the merkle root
  33. D = calculate_merkle_root(leaf_pos, merkle_path, bulla);
  34. constrain_instance(D);
  35. # Poseidon hash of the proposal (output 0)
  36. proposal = poseidon_hash(amount_to_send, pub_x, pub_y, proposal_blind);
  37. constrain_instance(proposal);
  38. # Pedersen commitment to the amount we're sending
  39. valc_v = ec_mul_short(amount_to_send, VALUE_COMMIT_VALUE);
  40. valc_r = ec_mul(proposal_value_blind, VALUE_COMMIT_RANDOM);
  41. value_commit = ec_add(valc_v, valc_r);
  42. value_commit_x = ec_get_x(value_commit);
  43. value_commit_y = ec_get_y(value_commit);
  44. constrain_instance(value_commit_x);
  45. constrain_instance(value_commit_y);
  46. # Calculate remaining balance in treasury
  47. new_balance = base_sub(cur_balance, amount_to_send);
  48. # Poseidon hash of the new treasury
  49. new_bulla = poseidon_hash(
  50. spend_contract,
  51. new_balance,
  52. new_serial,
  53. new_bulla_blind,
  54. );
  55. constrain_instance(new_bulla);
  56. }