opcodes.zk 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. one = witness_base(1);
  25. c = poseidon_hash(one, blind);
  26. constrain_instance(c);
  27. d = poseidon_hash(one, blind, ec_get_x(value_commit), ec_get_y(value_commit));
  28. constrain_instance(d);
  29. range_check(64, a);
  30. range_check(253, b);
  31. less_than(a, b);
  32. root = merkle_root(leaf_pos, path, c);
  33. constrain_instance(root);
  34. public = ec_mul_base(secret, NULLIFIER_K);
  35. constrain_instance(ec_get_x(public));
  36. constrain_instance(ec_get_y(public));
  37. bool_check(one);
  38. }