mint.zk 1.2 KB

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