mint.zk 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. k = 13;
  2. field = "pallas";
  3. constant "Mint" {
  4. EcFixedPointShort VALUE_COMMIT_VALUE,
  5. EcFixedPoint VALUE_COMMIT_RANDOM,
  6. EcFixedPointBase NULLIFIER_K,
  7. }
  8. witness "Mint" {
  9. Base pub_x,
  10. Base pub_y,
  11. Base value,
  12. Base token,
  13. Base serial,
  14. Scalar value_blind,
  15. Scalar token_blind,
  16. }
  17. circuit "Mint" {
  18. # Poseidon hash of the coin
  19. C = poseidon_hash(pub_x, pub_y, value, token, serial);
  20. constrain_instance(C);
  21. # Pedersen commitment for coin's value
  22. vcv = ec_mul_short(value, VALUE_COMMIT_VALUE);
  23. vcr = ec_mul(value_blind, VALUE_COMMIT_RANDOM);
  24. value_commit = ec_add(vcv, vcr);
  25. # Since the value commit is a curve point, we fetch its coordinates
  26. # and constrain them:
  27. value_commit_x = ec_get_x(value_commit);
  28. value_commit_y = ec_get_y(value_commit);
  29. constrain_instance(value_commit_x);
  30. constrain_instance(value_commit_y);
  31. # Pedersen commitment for coin's token ID
  32. tcv = ec_mul_base(token, NULLIFIER_K);
  33. tcr = ec_mul(token_blind, VALUE_COMMIT_RANDOM);
  34. token_commit = ec_add(tcv, tcr);
  35. # Since token_commit is also a curve point, we'll do the same
  36. # coordinate dance:
  37. token_commit_x = ec_get_x(token_commit);
  38. token_commit_y = ec_get_y(token_commit);
  39. constrain_instance(token_commit_x);
  40. constrain_instance(token_commit_y);
  41. # At this point we've enforced all of our public inputs.
  42. }