opcodes.zk 1.4 KB

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