opcodes.zk 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. k = 13;
  2. field = "pallas";
  3. constant "Opcodes" {
  4. EcFixedPointShort VALUE_COMMIT_VALUE,
  5. EcFixedPoint VALUE_COMMIT_RANDOM,
  6. EcFixedPointBase NULLIFIER_K,
  7. }
  8. witness "Opcodes" {
  9. Base value,
  10. Scalar value_blind,
  11. Base blind,
  12. Base a,
  13. Base b,
  14. Base secret,
  15. EcNiPoint pubkey,
  16. Base ephem_secret,
  17. Uint32 leaf_pos,
  18. MerklePath path,
  19. Base cond,
  20. }
  21. circuit "Opcodes" {
  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. value_commit_x = ec_get_x(value_commit);
  26. value_commit_y = ec_get_y(value_commit);
  27. constrain_instance(ec_get_x(value_commit));
  28. constrain_instance(ec_get_y(value_commit));
  29. vcv2 = ec_mul_short(value, VALUE_COMMIT_VALUE);
  30. vcr2 = ec_mul(value_blind, VALUE_COMMIT_RANDOM);
  31. value_commit2 = ec_add(vcv2, vcr2);
  32. constrain_equal_point(value_commit, value_commit2);
  33. zero = witness_base(0);
  34. one = witness_base(1);
  35. two = witness_base(2);
  36. c = poseidon_hash(one, two, blind);
  37. constrain_instance(c);
  38. d = poseidon_hash(one, blind, ec_get_x(value_commit), ec_get_y(value_commit));
  39. constrain_instance(d);
  40. d2 = poseidon_hash(one, blind, ec_get_x(value_commit2), ec_get_y(value_commit2));
  41. constrain_equal_base(d, d2);
  42. range_check(64, a);
  43. range_check(253, b);
  44. less_than_strict(a, b);
  45. less_than_loose(a, b);
  46. root = merkle_root(leaf_pos, path, c);
  47. constrain_instance(root);
  48. public = ec_mul_base(secret, NULLIFIER_K);
  49. constrain_instance(ec_get_x(public));
  50. constrain_instance(ec_get_y(public));
  51. bool_check(one);
  52. ephem_public = ec_mul_var_base(ephem_secret, pubkey);
  53. constrain_instance(ec_get_x(ephem_public));
  54. constrain_instance(ec_get_y(ephem_public));
  55. out = cond_select(cond, a, b);
  56. constrain_instance(out);
  57. zz = zero_cond(zero, c);
  58. constrain_instance(zz);
  59. }