dao-exec.zk 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. constant "DaoExec" {
  2. EcFixedPointShort VALUE_COMMIT_VALUE,
  3. EcFixedPoint VALUE_COMMIT_RANDOM,
  4. }
  5. contract "DaoExec" {
  6. # Main attributes for DAO
  7. Base treasury_value,
  8. Base authority_key_x,
  9. Base authority_key_y,
  10. Base governance_token_id,
  11. Base treasury_token_id,
  12. # Used for proving old bulla is in the set
  13. Uint32 leaf_pos,
  14. MerklePath path,
  15. Base old_bulla_serial,
  16. Base old_bulla_blind,
  17. Base coin_serial,
  18. Base coin_blind,
  19. Base new_bulla_serial,
  20. Base new_bulla_blind,
  21. ###
  22. # Instruction data
  23. Base instr_value,
  24. Base instr_key_x,
  25. Base instr_key_y,
  26. Base instr_token_id,
  27. Base message_blind,
  28. # Same blinding factor used for governance token ID hash on votes
  29. Base governance_token_id_blind,
  30. # Votes info
  31. Base vote_value,
  32. Scalar vote_blind,
  33. }
  34. circuit "DaoExec" {
  35. # instr = OPCODE, u, P
  36. message = poseidon_hash(instr_value, instr_key_x, instr_key_y,
  37. instr_token_id, message_blind);
  38. constrain_instance(message);
  39. # Vote commitment
  40. vote_cv = ec_mul_short(vote_value, VALUE_COMMIT_VALUE);
  41. vote_cr = ec_mul(vote_blind, VALUE_COMMIT_RANDOM);
  42. vote_commit = ec_add(vote_cv, vote_cr);
  43. vote_commit_x = ec_get_x(vote_commit);
  44. vote_commit_y = ec_get_y(vote_commit);
  45. constrain_instance(vote_commit_x);
  46. constrain_instance(vote_commit_y);
  47. gov_token_id_commit = poseidon_hash(
  48. governance_token_id, governance_token_id_blind);
  49. constrain_instance(gov_token_id_commit);
  50. change_value = base_sub(treasury_value, instr_value);
  51. # TODO: missing instructions
  52. # greater_than_zero(instr_value);
  53. # greater_than_or_equal_zero(change_value);
  54. # bulla_smash
  55. # Poseidon hash of the nullifier
  56. nullifier = poseidon_hash(old_bulla_serial);
  57. constrain_instance(nullifier);
  58. old_bulla = poseidon_hash(
  59. treasury_value,
  60. authority_key_x,
  61. authority_key_y,
  62. governance_token_id,
  63. treasury_token_id,
  64. old_bulla_serial,
  65. old_bulla_blind
  66. );
  67. # Merkle root
  68. root = calculate_merkle_root(leaf_pos, path, old_bulla);
  69. constrain_instance(root);
  70. # coin_mint
  71. # Poseidon hash of the coin
  72. coin = poseidon_hash(
  73. instr_key_x,
  74. instr_key_y,
  75. instr_value,
  76. instr_token_id,
  77. coin_serial,
  78. coin_blind
  79. );
  80. constrain_instance(coin);
  81. # bulla_mint
  82. bulla = poseidon_hash(
  83. change_value,
  84. authority_key_x,
  85. authority_key_y,
  86. governance_token_id,
  87. treasury_token_id,
  88. new_bulla_serial,
  89. new_bulla_blind
  90. );
  91. constrain_instance(bulla);
  92. }