mint_v1.zk 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # The k parameter defining the number of rows used in our circuit (2^k)
  2. k = 13;
  3. field = "pallas";
  4. # The constants we define for our circuit
  5. constant "Mint_V1" {
  6. EcFixedPointShort VALUE_COMMIT_VALUE,
  7. EcFixedPoint VALUE_COMMIT_RANDOM,
  8. EcFixedPointBase NULLIFIER_K,
  9. }
  10. # The witness values we define for our circuit
  11. witness "Mint_V1" {
  12. # X coordinate for public key
  13. Base pub_x,
  14. # Y coordinate for public key
  15. Base pub_y,
  16. # The value of this coin
  17. Base value,
  18. # The token ID
  19. Base token,
  20. # Unique serial number corresponding to this coin
  21. Base serial,
  22. # Allows composing this ZK proof to invoke other contracts
  23. Base spend_hook,
  24. # Data passed from this coin to the invoked contract
  25. Base user_data,
  26. # Random blinding factor for the value commitment
  27. Scalar value_blind,
  28. # Random blinding factor for the token ID
  29. Base token_blind,
  30. }
  31. # The definition of our circuit
  32. circuit "Mint_V1" {
  33. # Poseidon hash of the coin
  34. C = poseidon_hash(
  35. pub_x,
  36. pub_y,
  37. value,
  38. token,
  39. serial,
  40. spend_hook,
  41. user_data,
  42. );
  43. constrain_instance(C);
  44. # Pedersen commitment for coin's value
  45. vcv = ec_mul_short(value, VALUE_COMMIT_VALUE);
  46. vcr = ec_mul(value_blind, VALUE_COMMIT_RANDOM);
  47. value_commit = ec_add(vcv, vcr);
  48. # Since the value commit is a curve point, we fetch its coordinates
  49. # and constrain them:
  50. constrain_instance(ec_get_x(value_commit));
  51. constrain_instance(ec_get_y(value_commit));
  52. # Commitment for coin's token ID. We do a poseidon hash since it's
  53. # cheaper than EC operations and doesn't need the homomorphic prop.
  54. token_commit = poseidon_hash(token, token_blind);
  55. constrain_instance(token_commit);
  56. # At this point we've enforced all of our public inputs.
  57. }