opcodes.zk 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. constant "Opcodes" {
  2. EcFixedPointShort VALUE_COMMIT_VALUE,
  3. EcFixedPoint VALUE_COMMIT_RANDOM,
  4. EcFixedPointBase NULLIFIER_K,
  5. }
  6. witness "Opcodes" {
  7. Base value,
  8. Scalar value_blind,
  9. Base blind,
  10. Base a,
  11. Base b,
  12. Base secret,
  13. EcNiPoint pubkey,
  14. Base ephem_secret,
  15. Uint32 leaf_pos,
  16. MerklePath path,
  17. }
  18. circuit "Opcodes" {
  19. vcv = ec_mul_short(value, VALUE_COMMIT_VALUE);
  20. vcr = ec_mul(value_blind, VALUE_COMMIT_RANDOM);
  21. value_commit = ec_add(vcv, vcr);
  22. value_commit_x = ec_get_x(value_commit);
  23. value_commit_y = ec_get_y(value_commit);
  24. constrain_instance(ec_get_x(value_commit));
  25. constrain_instance(ec_get_y(value_commit));
  26. vcv2 = ec_mul_short(value, VALUE_COMMIT_VALUE);
  27. vcr2 = ec_mul(value_blind, VALUE_COMMIT_RANDOM);
  28. value_commit2 = ec_add(vcv2, vcr2);
  29. constrain_equal_point(value_commit, value_commit2);
  30. one = witness_base(1);
  31. two = witness_base(2);
  32. c = poseidon_hash(one, two, blind);
  33. constrain_instance(c);
  34. d = poseidon_hash(one, blind, ec_get_x(value_commit), ec_get_y(value_commit));
  35. constrain_instance(d);
  36. d2 = poseidon_hash(one, blind, ec_get_x(value_commit2), ec_get_y(value_commit2));
  37. constrain_equal_base(d, d2);
  38. range_check(64, a);
  39. range_check(253, b);
  40. less_than_strict(a, b);
  41. less_than_loose(a, b);
  42. root = merkle_root(leaf_pos, path, c);
  43. constrain_instance(root);
  44. public = ec_mul_base(secret, NULLIFIER_K);
  45. constrain_instance(ec_get_x(public));
  46. constrain_instance(ec_get_y(public));
  47. bool_check(one);
  48. ephem_public = ec_mul_var_base(ephem_secret, pubkey);
  49. constrain_instance(ec_get_x(ephem_public));
  50. constrain_instance(ec_get_y(ephem_public));
  51. }