mint.zk 1.3 KB

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