vote-input.zk 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. k = 14;
  2. field = "pallas";
  3. constant "VoteInput" {
  4. EcFixedPointBase NULLIFIER_K,
  5. EcFixedPoint VALUE_COMMIT_RANDOM,
  6. EcFixedPointShort VALUE_COMMIT_VALUE,
  7. }
  8. witness "VoteInput" {
  9. Base coin_secret,
  10. Base coin_value,
  11. Base coin_gov_token_id,
  12. Base coin_spend_hook,
  13. Base coin_user_data,
  14. Base coin_blind,
  15. Base proposal_bulla,
  16. Scalar value_blind,
  17. Base gov_token_blind,
  18. Uint32 leaf_pos,
  19. MerklePath coin_path,
  20. SparseMerklePath null_path,
  21. Base signature_secret,
  22. }
  23. circuit "VoteInput" {
  24. pub = ec_mul_base(coin_secret, NULLIFIER_K);
  25. pub_x = ec_get_x(pub);
  26. pub_y = ec_get_y(pub);
  27. coin = poseidon_hash(
  28. pub_x,
  29. pub_y,
  30. coin_value,
  31. coin_gov_token_id,
  32. coin_spend_hook,
  33. coin_user_data,
  34. coin_blind,
  35. );
  36. # We need this to detect whether the above coin was already spent.
  37. # Use a SMT, and show that at this position, the leaf is ZERO
  38. ZERO = witness_base(0);
  39. nullifier = poseidon_hash(coin_secret, coin);
  40. null_tree_root = sparse_merkle_root(
  41. nullifier, # Position
  42. null_path, # Path to root
  43. ZERO, # Leaf value
  44. );
  45. constrain_instance(null_tree_root);
  46. # Include some secret information in vote nullifier to defeat correlation
  47. # attacks. We reveal the proposal_bulla in vote-main.zk as well.
  48. vote_nullifier = poseidon_hash(nullifier, coin_secret, proposal_bulla);
  49. constrain_instance(proposal_bulla);
  50. constrain_instance(vote_nullifier);
  51. vcv = ec_mul_short(coin_value, VALUE_COMMIT_VALUE);
  52. vcr = ec_mul(value_blind, VALUE_COMMIT_RANDOM);
  53. coin_value_commit = ec_add(vcv, vcr);
  54. constrain_instance(ec_get_x(coin_value_commit));
  55. constrain_instance(ec_get_y(coin_value_commit));
  56. token_commit = poseidon_hash(coin_gov_token_id, gov_token_blind);
  57. constrain_instance(token_commit);
  58. # Merkle root
  59. merkle_coin_root = merkle_root(leaf_pos, coin_path, coin);
  60. constrain_instance(merkle_coin_root);
  61. signature_public = ec_mul_base(signature_secret, NULLIFIER_K);
  62. constrain_instance(ec_get_x(signature_public));
  63. constrain_instance(ec_get_y(signature_public));
  64. }