burn.zk 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. constant "Burn" {
  2. EcFixedPointShort VALUE_COMMIT_VALUE,
  3. EcFixedPoint VALUE_COMMIT_RANDOM,
  4. EcFixedPointBase NULLIFIER_K,
  5. }
  6. witness "Burn" {
  7. Base secret,
  8. Base serial,
  9. Base value,
  10. Base token,
  11. Scalar value_blind,
  12. Scalar token_blind,
  13. Uint32 leaf_pos,
  14. MerklePath path,
  15. Base signature_secret,
  16. }
  17. circuit "Burn" {
  18. # Poseidon hash of the nullifier
  19. nullifier = poseidon_hash(secret, serial);
  20. constrain_instance(nullifier);
  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 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. # Coin hash
  42. pub = ec_mul_base(secret, NULLIFIER_K);
  43. pub_x = ec_get_x(pub);
  44. pub_y = ec_get_y(pub);
  45. C = poseidon_hash(pub_x, pub_y, value, token, serial);
  46. # Merkle root
  47. root = merkle_root(leaf_pos, path, C);
  48. constrain_instance(root);
  49. # Finally, we derive a public key for the signature and
  50. # constrain its coordinates:
  51. signature_public = ec_mul_base(signature_secret, NULLIFIER_K);
  52. signature_x = ec_get_x(signature_public);
  53. signature_y = ec_get_y(signature_public);
  54. constrain_instance(signature_x);
  55. constrain_instance(signature_y);
  56. # At this point we've enforced all of our public inputs.
  57. }