@sip-protocol/sdk 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -58,7 +58,6 @@ __export(index_exports, {
58
58
  NATIVE_TOKENS: () => import_types33.NATIVE_TOKENS,
59
59
  NEARIntentsAdapter: () => NEARIntentsAdapter,
60
60
  NetworkError: () => NetworkError,
61
- NoirProofProvider: () => NoirProofProvider,
62
61
  ORACLE_DOMAIN: () => ORACLE_DOMAIN,
63
62
  OneClickClient: () => OneClickClient,
64
63
  OneClickDepositMode: () => import_types37.OneClickDepositMode,
@@ -3145,16 +3144,25 @@ var MockProofProvider = class {
3145
3144
  framework = "mock";
3146
3145
  _isReady = false;
3147
3146
  _warningShown = false;
3147
+ _silent;
3148
+ /**
3149
+ * Create a new MockProofProvider
3150
+ *
3151
+ * @param options - Configuration options
3152
+ */
3153
+ constructor(options) {
3154
+ this._silent = options?.silent ?? false;
3155
+ }
3148
3156
  get isReady() {
3149
3157
  return this._isReady;
3150
3158
  }
3151
3159
  /**
3152
3160
  * Initialize the mock provider
3153
3161
  *
3154
- * Logs a warning to console about mock usage.
3162
+ * Logs a warning to console about mock usage (unless silent mode is enabled).
3155
3163
  */
3156
3164
  async initialize() {
3157
- if (!this._warningShown) {
3165
+ if (!this._warningShown && !this._silent) {
3158
3166
  console.warn(WARNING_MESSAGE);
3159
3167
  this._warningShown = true;
3160
3168
  }
@@ -3301,1763 +3309,6 @@ var MockProofProvider = class {
3301
3309
  }
3302
3310
  };
3303
3311
 
3304
- // src/proofs/noir.ts
3305
- var import_noir_js = require("@noir-lang/noir_js");
3306
- var import_bb = require("@aztec/bb.js");
3307
- var import_secp256k13 = require("@noble/curves/secp256k1");
3308
-
3309
- // src/proofs/circuits/funding_proof.json
3310
- var funding_proof_default = { noir_version: "1.0.0-beta.15+83245db91dcf63420ef4bcbbd85b98f397fee663", hash: "13977419962319221401", abi: { parameters: [{ name: "commitment_hash", type: { kind: "field" }, visibility: "public" }, { name: "minimum_required", type: { kind: "integer", sign: "unsigned", width: 64 }, visibility: "public" }, { name: "asset_id", type: { kind: "field" }, visibility: "public" }, { name: "balance", type: { kind: "integer", sign: "unsigned", width: 64 }, visibility: "private" }, { name: "blinding", type: { kind: "field" }, visibility: "private" }], return_type: null, error_types: { "2900908756532713827": { error_kind: "string", string: "Insufficient balance" }, "15764276373176857197": { error_kind: "string", string: "Stack too deep" }, "17719928407928969950": { error_kind: "string", string: "Commitment hash mismatch" } } }, bytecode: "H4sIAAAAAAAA/+VYbUhTURg+d7vTTdfmnJlK1g360LJolUEUJaUZ/qgooS9Taq5aoCudlhHV6LuglPplBH0gLUuiCCv6osA+LImItCQ0wUyRTJSJWkG7ds58PV53PzT60Qt3z+65z/ue533u8exeGfQnWIxZm+zZ4V4043PGe6gx8kcCNabGYyw+V6HBQcY4jDMzl+c0WC7E3l2ZVO5yrd0YM7t5WcG9HUVLGjxn2nEdDkkKRi3OZfxd5JC0XNiXBmMAYRAz+IEEqgJLTfS3mh+ibiGuy2hkaAhAykxlZPYKNYn1yvqZmJ5XrJaEReMLeOMDMWppknoYAsRMChyam0ZxGa10DWgkDWWRMkN1GINoklxDoQAxQ3VIuqFB0jX0mcbfgAAwxmHULiwwfYjX5ce2B+RZfo6u/FXgPtf2al7hIvuaOKsjZT3kRu1P7y3bb0mbdDWiU/+iZvai19f21Lw0htW5HlTE9JzZCLlSgnA1Ke7tua9OzFmVvuFRdeP8i5Gnjhgz5q2cfHpnfVLRw0YV5HLn3zyO+7Gmp4t1JNZEPevtzkm98TxhL9u6OWrz0conkyFXLOBCC0T9PvGowxhEaRUJJtj7ofceo9DILuRgpGwhGzAaaZLchQwFiC1kA5K+kI1I2Q0bJBDJ60ePlBkagtFEk+QaCgWIGRqCpBtqQv/GUBVSZmgoRjNNkmsoFCBmaCiSbqhZugbfFqIHYxzG/3mrhdyxiR0l3F7X0xMHJ5S40ppvWkIm3v9mjoi8X+u5VOZOXga56tK2uU2Lp0YzRdapz9YVt7SWXI8b437JlS64cfJ4RbcbcuVomN59L+HLccNy867Pq3N7m4qj81bY45uuHCjfctZp6aiqgtwZVcfertv6YPXdw0UzRoUf2ZR6vbz06bvu9CmV+77felJ4EHLFgjyg8evEgNGIMQSjCWMoRjOlXSTUMrhy6jJh3o/R3iOcuiD3LQpypcwpkevTwRvAov79o68QGrjpCL01WT92dk2MXBwDa5LNqa7Ycwe9b/HQ+eTnNdNmdWTtcOTaMrbZs53j8KiWYpNXMg5JCgauFvn5B5Lp1wGZ8yeTh6Hh6Cc5CvJ9D6yJIJ/Wwoce9f8fAFE5/IOdAXw3ghw+kkA9hrq2VGDeYfaURPJZZfmqUDR4flKLf1jle4zA52oBLlxLGsAR8hUJjDECdWhv4H3gMJotqGZ8fXzBtPC5jhX5h+pTy/aFXY79aoxoy1uQ3/PJQfei8qNd70eDXqAf6A/5m1Dm/+5kMifRpUGD/YL1WYofjVEH5oc6OeQ/ais81bdTZmWZqHw+SM98n1H4e6Y9x2Z12vNtGd6NybbVlpOxM8/htNuyncQJLcgiFeWsSJIfrCx/wGsporTAur4JMbICecwQ5yoK/XHpcTimF7hGapLfCqiX9PEbVAIFlc4UAAA=", debug_symbols: "pZbNbsMgDMffhXMO2HwE8irTVKUtmyJFaZUlk6aq7z6TQpYcYBW9QN3k/4sx2PjGzu44fx664ePyxZq3GzuOXd93n4f+cmqn7jLQvzfG/QCaNVgxqB+TYY2gybJGVgzpDXm/VyzKDtPonFdtOES/tqMbJtYMc99X7Lvt5+Wlr2s7LPPUjvSUV8wNZ5oJ+NH1zv+6V39qnpYajkFsUK9yqHd6SOu1lEGvlSjRG4h6Y4r0cfE1T34/t36I/hsJq149HT/gwgYAcKWKCGBWgq5ThDpD0BCDCHrjA9gdwWQI1kYfkGOSYNMECaACQYIyJQQUdSRgrcoI8CoBxROEbCSNjnthbQkBuYpHEgEhRfDhTiGEkjEQQnNe4gRgvTqhRdKJzKmUysZ1SC03tUUXImwKkUsukLG+AdhkemIGgWjW3BDbGrkPBWaKFBpct9So5JYivpxfWcRzCfYPAl5GPJVi2XBaHmsuWrAlCAE83hsCQJQh/pIMbP0qAtN5mjvfyNfLAyXfne93stpTN+5bE6SHFRPLKJdRLaP210/FqFkB2h/zsOzDAupW/CUF4HOAZoIglTkQwZbBVsHWwfatjw29jz/23+3YtcfeeU+8r/Nwio6ROf1c45PYVV3Hy8md59H5RWxaKxrfKKfQvt/9Qn8B", file_map: { "16": { source: "use crate::cmp::Eq;\nuse crate::hash::Hash;\nuse crate::ops::arith::{Add, Neg, Sub};\n\n/// A point on the embedded elliptic curve\n/// By definition, the base field of the embedded curve is the scalar field of the proof system curve, i.e the Noir Field.\n/// x and y denotes the Weierstrass coordinates of the point, if is_infinite is false.\npub struct EmbeddedCurvePoint {\n pub x: Field,\n pub y: Field,\n pub is_infinite: bool,\n}\n\nimpl EmbeddedCurvePoint {\n /// Elliptic curve point doubling operation\n /// returns the doubled point of a point P, i.e P+P\n pub fn double(self) -> EmbeddedCurvePoint {\n embedded_curve_add(self, self)\n }\n\n /// Returns the null element of the curve; 'the point at infinity'\n pub fn point_at_infinity() -> EmbeddedCurvePoint {\n EmbeddedCurvePoint { x: 0, y: 0, is_infinite: true }\n }\n\n /// Returns the curve's generator point.\n pub fn generator() -> EmbeddedCurvePoint {\n // Generator point for the grumpkin curve (y^2 = x^3 - 17)\n EmbeddedCurvePoint {\n x: 1,\n y: 17631683881184975370165255887551781615748388533673675138860, // sqrt(-16)\n is_infinite: false,\n }\n }\n}\n\nimpl Add for EmbeddedCurvePoint {\n /// Adds two points P+Q, using the curve addition formula, and also handles point at infinity\n fn add(self, other: EmbeddedCurvePoint) -> EmbeddedCurvePoint {\n embedded_curve_add(self, other)\n }\n}\n\nimpl Sub for EmbeddedCurvePoint {\n /// Points subtraction operation, using addition and negation\n fn sub(self, other: EmbeddedCurvePoint) -> EmbeddedCurvePoint {\n self + other.neg()\n }\n}\n\nimpl Neg for EmbeddedCurvePoint {\n /// Negates a point P, i.e returns -P, by negating the y coordinate.\n /// If the point is at infinity, then the result is also at infinity.\n fn neg(self) -> EmbeddedCurvePoint {\n EmbeddedCurvePoint { x: self.x, y: -self.y, is_infinite: self.is_infinite }\n }\n}\n\nimpl Eq for EmbeddedCurvePoint {\n /// Checks whether two points are equal\n fn eq(self: Self, b: EmbeddedCurvePoint) -> bool {\n (self.is_infinite & b.is_infinite)\n | ((self.is_infinite == b.is_infinite) & (self.x == b.x) & (self.y == b.y))\n }\n}\n\nimpl Hash for EmbeddedCurvePoint {\n fn hash<H>(self, state: &mut H)\n where\n H: crate::hash::Hasher,\n {\n if self.is_infinite {\n self.is_infinite.hash(state);\n } else {\n self.x.hash(state);\n self.y.hash(state);\n }\n }\n}\n\n/// Scalar for the embedded curve represented as low and high limbs\n/// By definition, the scalar field of the embedded curve is base field of the proving system curve.\n/// It may not fit into a Field element, so it is represented with two Field elements; its low and high limbs.\npub struct EmbeddedCurveScalar {\n pub lo: Field,\n pub hi: Field,\n}\n\nimpl EmbeddedCurveScalar {\n pub fn new(lo: Field, hi: Field) -> Self {\n EmbeddedCurveScalar { lo, hi }\n }\n\n #[field(bn254)]\n pub fn from_field(scalar: Field) -> EmbeddedCurveScalar {\n let (a, b) = crate::field::bn254::decompose(scalar);\n EmbeddedCurveScalar { lo: a, hi: b }\n }\n\n //Bytes to scalar: take the first (after the specified offset) 16 bytes of the input as the lo value, and the next 16 bytes as the hi value\n #[field(bn254)]\n pub(crate) fn from_bytes(bytes: [u8; 64], offset: u32) -> EmbeddedCurveScalar {\n let mut v = 1;\n let mut lo = 0 as Field;\n let mut hi = 0 as Field;\n for i in 0..16 {\n lo = lo + (bytes[offset + 31 - i] as Field) * v;\n hi = hi + (bytes[offset + 15 - i] as Field) * v;\n v = v * 256;\n }\n let sig_s = crate::embedded_curve_ops::EmbeddedCurveScalar { lo, hi };\n sig_s\n }\n}\n\nimpl Eq for EmbeddedCurveScalar {\n fn eq(self, other: Self) -> bool {\n (other.hi == self.hi) & (other.lo == self.lo)\n }\n}\n\nimpl Hash for EmbeddedCurveScalar {\n fn hash<H>(self, state: &mut H)\n where\n H: crate::hash::Hasher,\n {\n self.hi.hash(state);\n self.lo.hash(state);\n }\n}\n\n// Computes a multi scalar multiplication over the embedded curve.\n// For bn254, We have Grumpkin and Baby JubJub.\n// For bls12-381, we have JubJub and Bandersnatch.\n//\n// The embedded curve being used is decided by the\n// underlying proof system.\n// docs:start:multi_scalar_mul\npub fn multi_scalar_mul<let N: u32>(\n points: [EmbeddedCurvePoint; N],\n scalars: [EmbeddedCurveScalar; N],\n) -> EmbeddedCurvePoint\n// docs:end:multi_scalar_mul\n{\n multi_scalar_mul_array_return(points, scalars, true)[0]\n}\n\n#[foreign(multi_scalar_mul)]\npub(crate) fn multi_scalar_mul_array_return<let N: u32>(\n points: [EmbeddedCurvePoint; N],\n scalars: [EmbeddedCurveScalar; N],\n predicate: bool,\n) -> [EmbeddedCurvePoint; 1] {}\n\n// docs:start:fixed_base_scalar_mul\npub fn fixed_base_scalar_mul(scalar: EmbeddedCurveScalar) -> EmbeddedCurvePoint\n// docs:end:fixed_base_scalar_mul\n{\n multi_scalar_mul([EmbeddedCurvePoint::generator()], [scalar])\n}\n\n/// This function only assumes that the points are on the curve\n/// It handles corner cases around the infinity point causing some overhead compared to embedded_curve_add_not_nul and embedded_curve_add_unsafe\n// docs:start:embedded_curve_add\npub fn embedded_curve_add(\n point1: EmbeddedCurvePoint,\n point2: EmbeddedCurvePoint,\n) -> EmbeddedCurvePoint {\n // docs:end:embedded_curve_add\n if crate::runtime::is_unconstrained() {\n // `embedded_curve_add_unsafe` requires the inputs not to be the infinity point, so we check it here.\n // This is because `embedded_curve_add_unsafe` uses the `embedded_curve_add` opcode.\n // For efficiency, the backend does not check the inputs for the infinity point, but it assumes that they are not the infinity point\n // so that it can apply the ec addition formula directly.\n if point1.is_infinite {\n point2\n } else if point2.is_infinite {\n point1\n } else {\n embedded_curve_add_unsafe(point1, point2)\n }\n } else {\n // In a constrained context, we also need to check the inputs are not the infinity point because we also use `embedded_curve_add_unsafe`\n // However we also need to identify the case where the two inputs are the same, because then\n // the addition formula does not work and we need to use the doubling formula instead.\n // In unconstrained context, we can check directly if the input values are the same when solving the opcode, so it is not an issue.\n\n // x_coordinates_match is true if both abscissae are the same\n let x_coordinates_match = point1.x == point2.x;\n // y_coordinates_match is true if both ordinates are the same\n let y_coordinates_match = point1.y == point2.y;\n // double_predicate is true if both abscissae and ordinates are the same\n let double_predicate = (x_coordinates_match & y_coordinates_match);\n // If the abscissae are the same, but not the ordinates, then one point is the opposite of the other\n let infinity_predicate = (x_coordinates_match & !y_coordinates_match);\n\n // `embedded_curve_add_unsafe` would not perform doubling, even if the inputs point1 and point2 are the same, because it cannot know this without adding some logic (and some constraints)\n // However we did this logic when we computed `double_predicate`, so we set the result to 2*point1 if point1 and point2 are the same\n let mut result = if double_predicate {\n // `embedded_curve_add_unsafe` is doing a doubling if the input is the same variable, because in this case it is guaranteed (at 'compile time') that the input is the same.\n embedded_curve_add_unsafe(point1, point1)\n } else {\n let point1_1 = EmbeddedCurvePoint {\n x: point1.x + (x_coordinates_match as Field),\n y: point1.y,\n is_infinite: false,\n };\n let point2_1 = EmbeddedCurvePoint { x: point2.x, y: point2.y, is_infinite: false };\n // point1_1 is guaranteed to have a different abscissa than point2:\n // - if x_coordinates_match is 0, that means point1.x != point2.x, and point1_1.x = point1.x + 0\n // - if x_coordinates_match is 1, that means point1.x = point2.x, but point1_1.x = point1.x + 1 in this case\n // Because the abscissa is different, the addition formula is guaranteed to succeed, so we can safely use `embedded_curve_add_unsafe`\n // Note that this computation may be garbage: if x_coordinates_match is 1, or if one of the input is the point at infinity.\n // therefore we only want to do this if we need the result, otherwise it needs to be eliminated as a dead instruction, lest we want the circuit to fail.\n embedded_curve_add_unsafe(point1_1, point2_1)\n };\n\n // Same logic as above for unconstrained context, we set the proper result when one of the inputs is the infinity point\n if point1.is_infinite {\n result = point2;\n }\n if point2.is_infinite {\n result = point1;\n }\n\n // Finally, we set the is_infinity flag of the result:\n // Opposite points should sum into the infinity point, however, if one of them is point at infinity, their coordinates are not meaningful\n // so we should not use the fact that the inputs are opposite in this case:\n let mut result_is_infinity =\n infinity_predicate & (!point1.is_infinite & !point2.is_infinite);\n // However, if both of them are at infinity, then the result is also at infinity\n result.is_infinite = result_is_infinity | (point1.is_infinite & point2.is_infinite);\n result\n }\n}\n\n#[foreign(embedded_curve_add)]\nfn embedded_curve_add_array_return(\n _point1: EmbeddedCurvePoint,\n _point2: EmbeddedCurvePoint,\n _predicate: bool,\n) -> [EmbeddedCurvePoint; 1] {}\n\n/// This function assumes that:\n/// The points are on the curve, and\n/// The points don't share an x-coordinate, and\n/// Neither point is the infinity point.\n/// If it is used with correct input, the function ensures the correct non-zero result is returned.\n/// Except for points on the curve, the other assumptions are checked by the function. It will cause assertion failure if they are not respected.\npub fn embedded_curve_add_not_nul(\n point1: EmbeddedCurvePoint,\n point2: EmbeddedCurvePoint,\n) -> EmbeddedCurvePoint {\n assert(point1.x != point2.x);\n assert(!point1.is_infinite);\n assert(!point2.is_infinite);\n // Ensure is_infinite is comptime\n let point1_1 = EmbeddedCurvePoint { x: point1.x, y: point1.y, is_infinite: false };\n let point2_1 = EmbeddedCurvePoint { x: point2.x, y: point2.y, is_infinite: false };\n embedded_curve_add_unsafe(point1_1, point2_1)\n}\n\n/// Unsafe ec addition\n/// If the inputs are the same, it will perform a doubling, but only if point1 and point2 are the same variable.\n/// If they have the same value but are different variables, the result will be incorrect because in this case\n/// it assumes (but does not check) that the points' x-coordinates are not equal.\n/// It also assumes neither point is the infinity point.\npub fn embedded_curve_add_unsafe(\n point1: EmbeddedCurvePoint,\n point2: EmbeddedCurvePoint,\n) -> EmbeddedCurvePoint {\n embedded_curve_add_array_return(point1, point2, true)[0]\n}\n", path: "std/embedded_curve_ops.nr" }, "17": { source: `use crate::field::field_less_than;
3311
- use crate::runtime::is_unconstrained;
3312
-
3313
- // The low and high decomposition of the field modulus
3314
- global PLO: Field = 53438638232309528389504892708671455233;
3315
- global PHI: Field = 64323764613183177041862057485226039389;
3316
-
3317
- pub(crate) global TWO_POW_128: Field = 0x100000000000000000000000000000000;
3318
-
3319
- // Decomposes a single field into two 16 byte fields.
3320
- fn compute_decomposition(x: Field) -> (Field, Field) {
3321
- // Here's we're taking advantage of truncating 128 bit limbs from the input field
3322
- // and then subtracting them from the input such the field division is equivalent to integer division.
3323
- let low = (x as u128) as Field;
3324
- let high = (x - low) / TWO_POW_128;
3325
-
3326
- (low, high)
3327
- }
3328
-
3329
- pub(crate) unconstrained fn decompose_hint(x: Field) -> (Field, Field) {
3330
- compute_decomposition(x)
3331
- }
3332
-
3333
- unconstrained fn lte_hint(x: Field, y: Field) -> bool {
3334
- if x == y {
3335
- true
3336
- } else {
3337
- field_less_than(x, y)
3338
- }
3339
- }
3340
-
3341
- // Assert that (alo > blo && ahi >= bhi) || (alo <= blo && ahi > bhi)
3342
- fn assert_gt_limbs(a: (Field, Field), b: (Field, Field)) {
3343
- let (alo, ahi) = a;
3344
- let (blo, bhi) = b;
3345
- // Safety: borrow is enforced to be boolean due to its type.
3346
- // if borrow is 0, it asserts that (alo > blo && ahi >= bhi)
3347
- // if borrow is 1, it asserts that (alo <= blo && ahi > bhi)
3348
- unsafe {
3349
- let borrow = lte_hint(alo, blo);
3350
-
3351
- let rlo = alo - blo - 1 + (borrow as Field) * TWO_POW_128;
3352
- let rhi = ahi - bhi - (borrow as Field);
3353
-
3354
- rlo.assert_max_bit_size::<128>();
3355
- rhi.assert_max_bit_size::<128>();
3356
- }
3357
- }
3358
-
3359
- /// Decompose a single field into two 16 byte fields.
3360
- pub fn decompose(x: Field) -> (Field, Field) {
3361
- if is_unconstrained() {
3362
- compute_decomposition(x)
3363
- } else {
3364
- // Safety: decomposition is properly checked below
3365
- unsafe {
3366
- // Take hints of the decomposition
3367
- let (xlo, xhi) = decompose_hint(x);
3368
-
3369
- // Range check the limbs
3370
- xlo.assert_max_bit_size::<128>();
3371
- xhi.assert_max_bit_size::<128>();
3372
-
3373
- // Check that the decomposition is correct
3374
- assert_eq(x, xlo + TWO_POW_128 * xhi);
3375
-
3376
- // Assert that the decomposition of P is greater than the decomposition of x
3377
- assert_gt_limbs((PLO, PHI), (xlo, xhi));
3378
- (xlo, xhi)
3379
- }
3380
- }
3381
- }
3382
-
3383
- pub fn assert_gt(a: Field, b: Field) {
3384
- if is_unconstrained() {
3385
- assert(
3386
- // Safety: already unconstrained
3387
- unsafe { field_less_than(b, a) },
3388
- );
3389
- } else {
3390
- // Decompose a and b
3391
- let a_limbs = decompose(a);
3392
- let b_limbs = decompose(b);
3393
-
3394
- // Assert that a_limbs is greater than b_limbs
3395
- assert_gt_limbs(a_limbs, b_limbs)
3396
- }
3397
- }
3398
-
3399
- pub fn assert_lt(a: Field, b: Field) {
3400
- assert_gt(b, a);
3401
- }
3402
-
3403
- pub fn gt(a: Field, b: Field) -> bool {
3404
- if is_unconstrained() {
3405
- // Safety: unsafe in unconstrained
3406
- unsafe {
3407
- field_less_than(b, a)
3408
- }
3409
- } else if a == b {
3410
- false
3411
- } else {
3412
- // Safety: Take a hint of the comparison and verify it
3413
- unsafe {
3414
- if field_less_than(a, b) {
3415
- assert_gt(b, a);
3416
- false
3417
- } else {
3418
- assert_gt(a, b);
3419
- true
3420
- }
3421
- }
3422
- }
3423
- }
3424
-
3425
- pub fn lt(a: Field, b: Field) -> bool {
3426
- gt(b, a)
3427
- }
3428
-
3429
- mod tests {
3430
- // TODO: Allow imports from "super"
3431
- use crate::field::bn254::{assert_gt, decompose, gt, lt, lte_hint, PHI, PLO, TWO_POW_128};
3432
-
3433
- #[test]
3434
- fn check_decompose() {
3435
- assert_eq(decompose(TWO_POW_128), (0, 1));
3436
- assert_eq(decompose(TWO_POW_128 + 0x1234567890), (0x1234567890, 1));
3437
- assert_eq(decompose(0x1234567890), (0x1234567890, 0));
3438
- }
3439
-
3440
- #[test]
3441
- unconstrained fn check_lte_hint() {
3442
- assert(lte_hint(0, 1));
3443
- assert(lte_hint(0, 0x100));
3444
- assert(lte_hint(0x100, TWO_POW_128 - 1));
3445
- assert(!lte_hint(0 - 1, 0));
3446
-
3447
- assert(lte_hint(0, 0));
3448
- assert(lte_hint(0x100, 0x100));
3449
- assert(lte_hint(0 - 1, 0 - 1));
3450
- }
3451
-
3452
- #[test]
3453
- fn check_gt() {
3454
- assert(gt(1, 0));
3455
- assert(gt(0x100, 0));
3456
- assert(gt((0 - 1), (0 - 2)));
3457
- assert(gt(TWO_POW_128, 0));
3458
- assert(!gt(0, 0));
3459
- assert(!gt(0, 0x100));
3460
- assert(gt(0 - 1, 0 - 2));
3461
- assert(!gt(0 - 2, 0 - 1));
3462
- assert_gt(0 - 1, 0);
3463
- }
3464
-
3465
- #[test]
3466
- fn check_plo_phi() {
3467
- assert_eq(PLO + PHI * TWO_POW_128, 0);
3468
- let p_bytes = crate::field::modulus_le_bytes();
3469
- let mut p_low: Field = 0;
3470
- let mut p_high: Field = 0;
3471
-
3472
- let mut offset = 1;
3473
- for i in 0..16 {
3474
- p_low += (p_bytes[i] as Field) * offset;
3475
- p_high += (p_bytes[i + 16] as Field) * offset;
3476
- offset *= 256;
3477
- }
3478
- assert_eq(p_low, PLO);
3479
- assert_eq(p_high, PHI);
3480
- }
3481
-
3482
- #[test]
3483
- fn check_decompose_edge_cases() {
3484
- assert_eq(decompose(0), (0, 0));
3485
- assert_eq(decompose(TWO_POW_128 - 1), (TWO_POW_128 - 1, 0));
3486
- assert_eq(decompose(TWO_POW_128 + 1), (1, 1));
3487
- assert_eq(decompose(TWO_POW_128 * 2), (0, 2));
3488
- assert_eq(decompose(TWO_POW_128 * 2 + 0x1234567890), (0x1234567890, 2));
3489
- }
3490
-
3491
- #[test]
3492
- fn check_decompose_large_values() {
3493
- let large_field = 0xffffffffffffffff;
3494
- let (lo, hi) = decompose(large_field);
3495
- assert_eq(large_field, lo + TWO_POW_128 * hi);
3496
-
3497
- let large_value = large_field - TWO_POW_128;
3498
- let (lo2, hi2) = decompose(large_value);
3499
- assert_eq(large_value, lo2 + TWO_POW_128 * hi2);
3500
- }
3501
-
3502
- #[test]
3503
- fn check_lt_comprehensive() {
3504
- assert(lt(0, 1));
3505
- assert(!lt(1, 0));
3506
- assert(!lt(0, 0));
3507
- assert(!lt(42, 42));
3508
-
3509
- assert(lt(TWO_POW_128 - 1, TWO_POW_128));
3510
- assert(!lt(TWO_POW_128, TWO_POW_128 - 1));
3511
- }
3512
- }
3513
- `, path: "std/field/bn254.nr" }, "19": { source: '// Exposed only for usage in `std::meta`\npub(crate) mod poseidon2;\n\nuse crate::default::Default;\nuse crate::embedded_curve_ops::{\n EmbeddedCurvePoint, EmbeddedCurveScalar, multi_scalar_mul, multi_scalar_mul_array_return,\n};\nuse crate::meta::derive_via;\n\n#[foreign(sha256_compression)]\n// docs:start:sha256_compression\npub fn sha256_compression(input: [u32; 16], state: [u32; 8]) -> [u32; 8] {}\n// docs:end:sha256_compression\n\n#[foreign(keccakf1600)]\n// docs:start:keccakf1600\npub fn keccakf1600(input: [u64; 25]) -> [u64; 25] {}\n// docs:end:keccakf1600\n\npub mod keccak {\n #[deprecated("This function has been moved to std::hash::keccakf1600")]\n pub fn keccakf1600(input: [u64; 25]) -> [u64; 25] {\n super::keccakf1600(input)\n }\n}\n\n#[foreign(blake2s)]\n// docs:start:blake2s\npub fn blake2s<let N: u32>(input: [u8; N]) -> [u8; 32]\n// docs:end:blake2s\n{}\n\n// docs:start:blake3\npub fn blake3<let N: u32>(input: [u8; N]) -> [u8; 32]\n// docs:end:blake3\n{\n if crate::runtime::is_unconstrained() {\n // Temporary measure while Barretenberg is main proving system.\n // Please open an issue if you\'re working on another proving system and running into problems due to this.\n crate::static_assert(\n N <= 1024,\n "Barretenberg cannot prove blake3 hashes with inputs larger than 1024 bytes",\n );\n }\n __blake3(input)\n}\n\n#[foreign(blake3)]\nfn __blake3<let N: u32>(input: [u8; N]) -> [u8; 32] {}\n\n// docs:start:pedersen_commitment\npub fn pedersen_commitment<let N: u32>(input: [Field; N]) -> EmbeddedCurvePoint {\n // docs:end:pedersen_commitment\n pedersen_commitment_with_separator(input, 0)\n}\n\n#[inline_always]\npub fn pedersen_commitment_with_separator<let N: u32>(\n input: [Field; N],\n separator: u32,\n) -> EmbeddedCurvePoint {\n let mut points = [EmbeddedCurveScalar { lo: 0, hi: 0 }; N];\n for i in 0..N {\n // we use the unsafe version because the multi_scalar_mul will constrain the scalars.\n points[i] = from_field_unsafe(input[i]);\n }\n let generators = derive_generators("DEFAULT_DOMAIN_SEPARATOR".as_bytes(), separator);\n multi_scalar_mul(generators, points)\n}\n\n// docs:start:pedersen_hash\npub fn pedersen_hash<let N: u32>(input: [Field; N]) -> Field\n// docs:end:pedersen_hash\n{\n pedersen_hash_with_separator(input, 0)\n}\n\n#[no_predicates]\npub fn pedersen_hash_with_separator<let N: u32>(input: [Field; N], separator: u32) -> Field {\n let mut scalars: [EmbeddedCurveScalar; N + 1] = [EmbeddedCurveScalar { lo: 0, hi: 0 }; N + 1];\n let mut generators: [EmbeddedCurvePoint; N + 1] =\n [EmbeddedCurvePoint::point_at_infinity(); N + 1];\n let domain_generators: [EmbeddedCurvePoint; N] =\n derive_generators("DEFAULT_DOMAIN_SEPARATOR".as_bytes(), separator);\n\n for i in 0..N {\n scalars[i] = from_field_unsafe(input[i]);\n generators[i] = domain_generators[i];\n }\n scalars[N] = EmbeddedCurveScalar { lo: N as Field, hi: 0 as Field };\n\n let length_generator: [EmbeddedCurvePoint; 1] =\n derive_generators("pedersen_hash_length".as_bytes(), 0);\n generators[N] = length_generator[0];\n multi_scalar_mul_array_return(generators, scalars, true)[0].x\n}\n\n#[field(bn254)]\n#[inline_always]\npub fn derive_generators<let N: u32, let M: u32>(\n domain_separator_bytes: [u8; M],\n starting_index: u32,\n) -> [EmbeddedCurvePoint; N] {\n crate::assert_constant(domain_separator_bytes);\n // TODO(https://github.com/noir-lang/noir/issues/5672): Add back assert_constant on starting_index\n __derive_generators(domain_separator_bytes, starting_index)\n}\n\n#[builtin(derive_pedersen_generators)]\n#[field(bn254)]\nfn __derive_generators<let N: u32, let M: u32>(\n domain_separator_bytes: [u8; M],\n starting_index: u32,\n) -> [EmbeddedCurvePoint; N] {}\n\n#[field(bn254)]\n// Same as from_field but:\n// does not assert the limbs are 128 bits\n// does not assert the decomposition does not overflow the EmbeddedCurveScalar\nfn from_field_unsafe(scalar: Field) -> EmbeddedCurveScalar {\n // Safety: xlo and xhi decomposition is checked below\n let (xlo, xhi) = unsafe { crate::field::bn254::decompose_hint(scalar) };\n // Check that the decomposition is correct\n assert_eq(scalar, xlo + crate::field::bn254::TWO_POW_128 * xhi);\n EmbeddedCurveScalar { lo: xlo, hi: xhi }\n}\n\npub fn poseidon2_permutation<let N: u32>(input: [Field; N], state_len: u32) -> [Field; N] {\n assert_eq(input.len(), state_len);\n poseidon2_permutation_internal(input)\n}\n\n#[foreign(poseidon2_permutation)]\nfn poseidon2_permutation_internal<let N: u32>(input: [Field; N]) -> [Field; N] {}\n\n// Generic hashing support.\n// Partially ported and impacted by rust.\n\n// Hash trait shall be implemented per type.\n#[derive_via(derive_hash)]\npub trait Hash {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher;\n}\n\n// docs:start:derive_hash\ncomptime fn derive_hash(s: TypeDefinition) -> Quoted {\n let name = quote { $crate::hash::Hash };\n let signature = quote { fn hash<H>(_self: Self, _state: &mut H) where H: $crate::hash::Hasher };\n let for_each_field = |name| quote { _self.$name.hash(_state); };\n crate::meta::make_trait_impl(\n s,\n name,\n signature,\n for_each_field,\n quote {},\n |fields| fields,\n )\n}\n// docs:end:derive_hash\n\n// Hasher trait shall be implemented by algorithms to provide hash-agnostic means.\n// TODO: consider making the types generic here ([u8], [Field], etc.)\npub trait Hasher {\n fn finish(self) -> Field;\n\n fn write(&mut self, input: Field);\n}\n\n// BuildHasher is a factory trait, responsible for production of specific Hasher.\npub trait BuildHasher {\n type H: Hasher;\n\n fn build_hasher(self) -> H;\n}\n\npub struct BuildHasherDefault<H>;\n\nimpl<H> BuildHasher for BuildHasherDefault<H>\nwhere\n H: Hasher + Default,\n{\n type H = H;\n\n fn build_hasher(_self: Self) -> H {\n H::default()\n }\n}\n\nimpl<H> Default for BuildHasherDefault<H>\nwhere\n H: Hasher + Default,\n{\n fn default() -> Self {\n BuildHasherDefault {}\n }\n}\n\nimpl Hash for Field {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self);\n }\n}\n\nimpl Hash for u1 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for u8 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for u16 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for u32 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for u64 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for u128 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for i8 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as u8 as Field);\n }\n}\n\nimpl Hash for i16 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as u16 as Field);\n }\n}\n\nimpl Hash for i32 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as u32 as Field);\n }\n}\n\nimpl Hash for i64 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as u64 as Field);\n }\n}\n\nimpl Hash for bool {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for () {\n fn hash<H>(_self: Self, _state: &mut H)\n where\n H: Hasher,\n {}\n}\n\nimpl<T, let N: u32> Hash for [T; N]\nwhere\n T: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n for elem in self {\n elem.hash(state);\n }\n }\n}\n\nimpl<T> Hash for [T]\nwhere\n T: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n self.len().hash(state);\n for elem in self {\n elem.hash(state);\n }\n }\n}\n\nimpl<A, B> Hash for (A, B)\nwhere\n A: Hash,\n B: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n self.0.hash(state);\n self.1.hash(state);\n }\n}\n\nimpl<A, B, C> Hash for (A, B, C)\nwhere\n A: Hash,\n B: Hash,\n C: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n self.0.hash(state);\n self.1.hash(state);\n self.2.hash(state);\n }\n}\n\nimpl<A, B, C, D> Hash for (A, B, C, D)\nwhere\n A: Hash,\n B: Hash,\n C: Hash,\n D: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n self.0.hash(state);\n self.1.hash(state);\n self.2.hash(state);\n self.3.hash(state);\n }\n}\n\nimpl<A, B, C, D, E> Hash for (A, B, C, D, E)\nwhere\n A: Hash,\n B: Hash,\n C: Hash,\n D: Hash,\n E: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n self.0.hash(state);\n self.1.hash(state);\n self.2.hash(state);\n self.3.hash(state);\n self.4.hash(state);\n }\n}\n\n// Some test vectors for Pedersen hash and Pedersen Commitment.\n// They have been generated using the same functions so the tests are for now useless\n// but they will be useful when we switch to Noir implementation.\n#[test]\nfn assert_pedersen() {\n assert_eq(\n pedersen_hash_with_separator([1], 1),\n 0x1b3f4b1a83092a13d8d1a59f7acb62aba15e7002f4440f2275edb99ebbc2305f,\n );\n assert_eq(\n pedersen_commitment_with_separator([1], 1),\n EmbeddedCurvePoint {\n x: 0x054aa86a73cb8a34525e5bbed6e43ba1198e860f5f3950268f71df4591bde402,\n y: 0x209dcfbf2cfb57f9f6046f44d71ac6faf87254afc7407c04eb621a6287cac126,\n is_infinite: false,\n },\n );\n\n assert_eq(\n pedersen_hash_with_separator([1, 2], 2),\n 0x26691c129448e9ace0c66d11f0a16d9014a9e8498ee78f4d69f0083168188255,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2], 2),\n EmbeddedCurvePoint {\n x: 0x2e2b3b191e49541fe468ec6877721d445dcaffe41728df0a0eafeb15e87b0753,\n y: 0x2ff4482400ad3a6228be17a2af33e2bcdf41be04795f9782bd96efe7e24f8778,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3], 3),\n 0x0bc694b7a1f8d10d2d8987d07433f26bd616a2d351bc79a3c540d85b6206dbe4,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3], 3),\n EmbeddedCurvePoint {\n x: 0x1fee4e8cf8d2f527caa2684236b07c4b1bad7342c01b0f75e9a877a71827dc85,\n y: 0x2f9fedb9a090697ab69bf04c8bc15f7385b3e4b68c849c1536e5ae15ff138fd1,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4], 4),\n 0xdae10fb32a8408521803905981a2b300d6a35e40e798743e9322b223a5eddc,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4], 4),\n EmbeddedCurvePoint {\n x: 0x07ae3e202811e1fca39c2d81eabe6f79183978e6f12be0d3b8eda095b79bdbc9,\n y: 0x0afc6f892593db6fbba60f2da558517e279e0ae04f95758587760ba193145014,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5], 5),\n 0xfc375b062c4f4f0150f7100dfb8d9b72a6d28582dd9512390b0497cdad9c22,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5], 5),\n EmbeddedCurvePoint {\n x: 0x1754b12bd475a6984a1094b5109eeca9838f4f81ac89c5f0a41dbce53189bb29,\n y: 0x2da030e3cfcdc7ddad80eaf2599df6692cae0717d4e9f7bfbee8d073d5d278f7,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5, 6], 6),\n 0x1696ed13dc2730062a98ac9d8f9de0661bb98829c7582f699d0273b18c86a572,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5, 6], 6),\n EmbeddedCurvePoint {\n x: 0x190f6c0e97ad83e1e28da22a98aae156da083c5a4100e929b77e750d3106a697,\n y: 0x1f4b60f34ef91221a0b49756fa0705da93311a61af73d37a0c458877706616fb,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5, 6, 7], 7),\n 0x128c0ff144fc66b6cb60eeac8a38e23da52992fc427b92397a7dffd71c45ede3,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5, 6, 7], 7),\n EmbeddedCurvePoint {\n x: 0x015441e9d29491b06563fac16fc76abf7a9534c715421d0de85d20dbe2965939,\n y: 0x1d2575b0276f4e9087e6e07c2cb75aa1baafad127af4be5918ef8a2ef2fea8fc,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5, 6, 7, 8], 8),\n 0x2f960e117482044dfc99d12fece2ef6862fba9242be4846c7c9a3e854325a55c,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5, 6, 7, 8], 8),\n EmbeddedCurvePoint {\n x: 0x1657737676968887fceb6dd516382ea13b3a2c557f509811cd86d5d1199bc443,\n y: 0x1f39f0cb569040105fa1e2f156521e8b8e08261e635a2b210bdc94e8d6d65f77,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5, 6, 7, 8, 9], 9),\n 0x0c96db0790602dcb166cc4699e2d306c479a76926b81c2cb2aaa92d249ec7be7,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5, 6, 7, 8, 9], 9),\n EmbeddedCurvePoint {\n x: 0x0a3ceae42d14914a432aa60ec7fded4af7dad7dd4acdbf2908452675ec67e06d,\n y: 0xfc19761eaaf621ad4aec9a8b2e84a4eceffdba78f60f8b9391b0bd9345a2f2,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 10),\n 0x2cd37505871bc460a62ea1e63c7fe51149df5d0801302cf1cbc48beb8dff7e94,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 10),\n EmbeddedCurvePoint {\n x: 0x2fb3f8b3d41ddde007c8c3c62550f9a9380ee546fcc639ffbb3fd30c8d8de30c,\n y: 0x300783be23c446b11a4c0fabf6c91af148937cea15fcf5fb054abf7f752ee245,\n is_infinite: false,\n },\n );\n}\n', path: "std/hash/mod.nr" }, "50": { source: `/// Funding Proof Circuit
3514
- ///
3515
- /// Proves: "I have sufficient funds to fulfill this intent, without revealing
3516
- /// my exact balance, wallet address, or source of funds."
3517
- ///
3518
- /// @see docs/specs/FUNDING-PROOF.md
3519
-
3520
- use std::hash::pedersen_hash;
3521
- use std::hash::pedersen_commitment;
3522
-
3523
- // --- Main Circuit ---
3524
-
3525
- /// Main funding proof entry point
3526
- ///
3527
- /// Public inputs: commitment_hash, minimum_required, asset_id
3528
- /// Private inputs: balance, blinding
3529
- ///
3530
- /// Constraints:
3531
- /// 1. balance >= minimum_required (range proof via u64)
3532
- /// 2. commitment = Pedersen(balance, blinding)
3533
- /// 3. hash(commitment, asset_id) == commitment_hash
3534
- pub fn main(
3535
- commitment_hash: pub Field,
3536
- minimum_required: pub u64,
3537
- asset_id: pub Field,
3538
- balance: u64,
3539
- blinding: Field,
3540
- ) {
3541
- // Constraint 1: Sufficient Funds
3542
- assert(balance >= minimum_required, "Insufficient balance");
3543
-
3544
- // Constraint 2: Compute Pedersen Commitment
3545
- // Uses Noir's built-in pedersen_commitment which returns (x, y) point
3546
- let commitment = pedersen_commitment([balance as Field, blinding]);
3547
-
3548
- // Constraint 3: Verify Commitment Hash
3549
- let computed_hash = pedersen_hash([commitment.x, commitment.y, asset_id]);
3550
- assert(computed_hash == commitment_hash, "Commitment hash mismatch");
3551
- }
3552
-
3553
- // --- Tests ---
3554
-
3555
- #[test]
3556
- fn test_valid_funding_proof() {
3557
- let balance: u64 = 100;
3558
- let minimum_required: u64 = 50;
3559
- let blinding: Field = 12345;
3560
- let asset_id: Field = 0xABCD;
3561
-
3562
- // Compute commitment using same method as circuit
3563
- let commitment = pedersen_commitment([balance as Field, blinding]);
3564
- let commitment_hash = pedersen_hash([commitment.x, commitment.y, asset_id]);
3565
-
3566
- // This should pass
3567
- main(commitment_hash, minimum_required, asset_id, balance, blinding);
3568
- }
3569
-
3570
- #[test(should_fail_with = "Insufficient balance")]
3571
- fn test_insufficient_balance() {
3572
- let balance: u64 = 50;
3573
- let minimum_required: u64 = 100;
3574
- let blinding: Field = 12345;
3575
- let asset_id: Field = 0xABCD;
3576
-
3577
- let commitment = pedersen_commitment([balance as Field, blinding]);
3578
- let commitment_hash = pedersen_hash([commitment.x, commitment.y, asset_id]);
3579
-
3580
- // This should fail - balance < minimum
3581
- main(commitment_hash, minimum_required, asset_id, balance, blinding);
3582
- }
3583
-
3584
- #[test(should_fail_with = "Commitment hash mismatch")]
3585
- fn test_wrong_commitment_hash() {
3586
- let balance: u64 = 100;
3587
- let minimum_required: u64 = 50;
3588
- let blinding: Field = 12345;
3589
- let asset_id: Field = 0xABCD;
3590
- let wrong_hash: Field = 0xDEADBEEF;
3591
-
3592
- // This should fail - wrong hash
3593
- main(wrong_hash, minimum_required, asset_id, balance, blinding);
3594
- }
3595
-
3596
- #[test(should_fail_with = "Commitment hash mismatch")]
3597
- fn test_wrong_blinding() {
3598
- let balance: u64 = 100;
3599
- let minimum_required: u64 = 50;
3600
- let correct_blinding: Field = 12345;
3601
- let wrong_blinding: Field = 54321;
3602
- let asset_id: Field = 0xABCD;
3603
-
3604
- // Compute hash with correct blinding
3605
- let commitment = pedersen_commitment([balance as Field, correct_blinding]);
3606
- let commitment_hash = pedersen_hash([commitment.x, commitment.y, asset_id]);
3607
-
3608
- // Try to prove with wrong blinding - should fail
3609
- main(commitment_hash, minimum_required, asset_id, balance, wrong_blinding);
3610
- }
3611
- `, path: "/Users/rz/local-dev/sip-protocol/packages/circuits/funding_proof/src/main.nr" } }, expression_width: { Bounded: { width: 4 } } };
3612
-
3613
- // src/proofs/circuits/validity_proof.json
3614
- var validity_proof_default = { noir_version: "1.0.0-beta.15+83245db91dcf63420ef4bcbbd85b98f397fee663", hash: "17105369051450454041", abi: { parameters: [{ name: "intent_hash", type: { kind: "field" }, visibility: "public" }, { name: "sender_commitment_x", type: { kind: "field" }, visibility: "public" }, { name: "sender_commitment_y", type: { kind: "field" }, visibility: "public" }, { name: "nullifier", type: { kind: "field" }, visibility: "public" }, { name: "timestamp", type: { kind: "integer", sign: "unsigned", width: 64 }, visibility: "public" }, { name: "expiry", type: { kind: "integer", sign: "unsigned", width: 64 }, visibility: "public" }, { name: "sender_address", type: { kind: "field" }, visibility: "private" }, { name: "sender_blinding", type: { kind: "field" }, visibility: "private" }, { name: "sender_secret", type: { kind: "field" }, visibility: "private" }, { name: "pub_key_x", type: { kind: "array", length: 32, type: { kind: "integer", sign: "unsigned", width: 8 } }, visibility: "private" }, { name: "pub_key_y", type: { kind: "array", length: 32, type: { kind: "integer", sign: "unsigned", width: 8 } }, visibility: "private" }, { name: "signature", type: { kind: "array", length: 64, type: { kind: "integer", sign: "unsigned", width: 8 } }, visibility: "private" }, { name: "message_hash", type: { kind: "array", length: 32, type: { kind: "integer", sign: "unsigned", width: 8 } }, visibility: "private" }, { name: "nonce", type: { kind: "field" }, visibility: "private" }], return_type: null, error_types: { "4743545721632785176": { error_kind: "string", string: "Nullifier mismatch" }, "4924752953922582949": { error_kind: "string", string: "Invalid ECDSA signature" }, "5940733937471987676": { error_kind: "string", string: "Intent expired" }, "9872184990886929843": { error_kind: "string", string: "Sender commitment X mismatch" }, "14620555433709191364": { error_kind: "string", string: "Sender commitment Y mismatch" }, "15764276373176857197": { error_kind: "string", string: "Stack too deep" } } }, bytecode: "H4sIAAAAAAAA/+WZaXBV5QGGz81CAwTCTogsF2XfJEBQBCFAQjAqIETZQgIkAYJmXyCIkMgaUEgENxBli8SQlEpCCAK1MsVWLNPptCMdxyl1xlI7Tqm1QwdoO9O85D345fAm997AjD88M+FJnvOdc77zeXPufaLLatgCyLQlqeln61nHn131X/4kxkQ6XKBwreu/ghyujXBthQsWrp1w7YULEa6DcB2F6yRcZ+G6CNdVuG7CdRcuVLgewoUJd59wPYXrJVxv4foI5xaur3D3C/eAcP2E6y/cAOEGCjdIuMHCDRFuqHDDhBsu3AjhHhRupHDhwo0SbrRwY4SLEG6scA8J97Bw44R7RLjxwk0Q7lHhJgo3SbhI4SYLN0W4qcJFCRct3DThYoSbLtxjwsUK97hwTwj3pHAzhJsp3CzhnhJutnBzhIsT7mnhnhFurnDzhJsv3ALhFgoXL9wi4RKESxRusXBLhFsqXJJwycKlCLdMuOXCrRAuVbiVwj0r3HPCpQmXLlyGcJnCZQmXLVyOcLnC5QmXL9wq4VYLVyDcGuGeF26tcC8It0649cIVClck3IvCbRBuo3CbhNss3BbhtgpXLNw24bYL95JwLwu3Q7idwpUIVyrcK8LtEm63cK8K95pwrwv3hnBvCrdHuL3CvSXcPuHeFu4d4fYLd0C4g8IdEu6wcGXCvSvcEeHK6ex+cVl3brZzW15trlbej7X8jO8ryKPOQf53MYGRyTOyvwzfP7huVnRtUdG8RYNGfz294FRm6dQvr+36lhdtYmy8Y6zrqPdzuKcL+hOrZQtaSVY5B/m6oOYEPC1opeX9glZ5P4dbi4ZXaivDucmgiQUd/xjROn/wt63ywv/b9cL/Csr3Xv10XMmk1LnDkjJiF5hjw9Yn3KxaHx7f/73QfwX/+tLoSb85uubSJyFd/lR05vygG7sWmWO92eyxgbHlK3M+3TZmdsLCn3/21fgDPXZsDkkcN2vAzqzL0aVnv/Izx7r3/fbDYf+Ze+PfARlRl8I+vnk9O+7YryLXBnyzNGzplgsfDTDHetrMF1oFeZSsJKscc/WwuX5a/8+x+q+fOXb4Oc7j6bXgsny7ppdj72pOfpb3czpmtWxOLh/n9L7l/Zxw7la8RmuyDdmWDCbbke3JELID2ZHsRHYmu5BdyW5kdzKU7EGGkfeRPcleZG+yj/X9awLsS95PPkD2I/uTA8iB5CByMDmEHEoOI4eTI8gHyZFkODmKHE2OISPIseRD5MPkOPIRcjw5gXyUnEhOIiPJyeQUcioZRUaT08gYcjr5GBlLPk4+QT5JziBnkrPIp8jZ5BwyjnyafIacS84j55MLyIVkPLmITCATycXkEnIpmUQmkynkMnI5uYJMJVeSz5LPkWlkOplBZpJZZDaZQ+aSeWQ+uYpcTRaQa8jnybXkC+Q6cj1ZSBaRL5IbyI3kJnIzuYXcShaT28jt5Evky+QOcidZQpaSr5C7yN3kq+Rr5OvkG+Sb5B5yL/kWuY98m3yH3E8eIA+Sh8jDZBn5LnmELCfx3DxuNd5cpNvyanMdN8Z6ek7fyw91Qd6PbfShrpqscQ7y9UOdOQFPN17d9Ng7PtTVeD+He7qgPoxttKAnyFrnIF8X1BzraUFPWN4vaK31wyzoe1bLFvQkWecc5OuCmhPwtKAnLe8XtM77OdxaNPymBBvOTf6Ys8Mc2zPquzL32qJz2zb0LSuK//r98A79Tv+9c2iP059fO1hVHjPdHOtfcXXslSlDerlKk4Z8PH/P374pqxzWvfwTd8WEY9uLz18vN8f6Mofh109F/qW4/YzOq/48J+fmlT298mamRlw5Uli7bHdu+HcXL5pjR1zc+rv5y8/MqdtUOqJdt81L4iprK879/nrCwAvr/nH8o5IN5lhPWxCJ10k1WUOeIGvJk2SdY+4eNn8fxvpyXtep+n8+qP867djha1L5W75d08uxtx5mLqvxw6WpOXq6boDl/f0Eej6vq7mdbsu7Y837OkOetUfYf6GDiHScIcC7C92+YEtvvomxJfaD9IwP5z1rtWxRne9anq5jzsnTdphET+NvXPhlRlOjp9HSeOijodHPaGd0M5oZvYxWRiejkdHHaGN0MZoYPYwWRgejgdG/fTivvlZD76J10bloXDx50bboWjQtehYti45Fw6Jf0a7oVjQrehWtik5Fo6JP0aboUjQpehQtig5Fg6I/0Z6RVkNzojfRmuhMNCb6Em2JJzWaEj2JlkRHoiHRj2hHdCOaEb2IVkQnohHRh2hDdCGaEO98aEF0IN7Z0H9ov8VWQ/Oh99B66Dw0HvoObYeuQ9Oh59By6Dg0HPoN7YZuQ7Oh19Bq6DQ0GvoMbYYuQ5Ohx9Bi6DA0GPoL7VVoNTQXegtPeXQWGgt9hbZCV6Gp0FNoKXQUGgr9hHZCN6GZ0EtoJXQSGgl9hDZCF6GJ0ENoIXQQGgj9g/bZbzU0D3oHrYPXHxoHfYO2wbsfPvSYf+O0H4B4HuD3ONDYZ35/hKzuf+74P9u6io1dt86L7Ze/6BdRU3blgrnP/mt7WUHPHnUT5kWZ++zWCPX/sLQ67w+TzX32p7wv+rgz23yQNdv29kOtPZmckpSRlpmRk5K4IjU9tzdtkGO0/cRzW15tLvNt1/fjC2OCnCf06Xgrxv7/KHczf/uYFhx/+xUSZRzvnAs2+y+B5qPVPgZPvPbG9yHGMdiijfO5HPumieve5T1F28cHtOx4v07Wnde3z4UnOu4xlD/7i7HmaynQGKPW1RLOJc7jXBvzv4Ob7BxuXepzOaJgaLexGTPzN16Oq1rX5dDgv4aEXs2bkH/jiwznvfg1M/fgZuYQLO7HXB/7d6Jl6786xr6mPa9A6871Ms8f4Bjfi2xtXN+cp9tqfvv8/LXPamJHpXV0HI/NvmfcZxi/T07NTknKTc1PSax/MKUsT8lOzMrLyE1NSc+1VyLIOMo+oy+vSPv4ti07vtH7gOWYi3ne2xckA8RxriZ+9nOwubFOb7pgsc8+ZyfSnK99H/8HYaTeT0IrAAA=", debug_symbols: "pZbNjuIwDIDfJeceYsf541VGI1SgM6pUFdSBlVaId9+YxaU9JMuGS+O69dfYsV1f1aHbXb63/fh1/FGbj6vaTf0w9N/b4bhvz/1xTNqr0nwBpzbYKPB/l6A2Ji1RbahRmN6g261RYrY9T13HVgtOop/aqRvPajNehqFRv9rhcn/p59SO9/XcTumpblQ3HtKagF/90LF0a57WOm8aND6MA7rZHPzKHvL2juhh76ypsQ8g9iFU2YvzXme/X/AfCCQAQO4ZAbuOoC0QHIgL4Kx97iGuCK5AiDE8CKgxS/B5AgHYB4HAhhoCGi8E9LaOAO8S0LxAKEYyODmLGGsIqK0kNAJCjgAmjzCWJBDGaV2zCUA/b8KZ7CYKWUk2ih/kaFHZrhIRc4hicfkox2GBcsVVIlinZ8LiQP+D4IOUBgQKOQKWENpJXgKYRSDo5U0EN/eI4HWFGykvYU4JDVk3CnmJGOY2Y5bNfp1VSAVEwLk6gs1WB9q3W1UR8Vqv+gcC3ka81K2K4Yxa6gMjxBqEAS0FYlJy1iGe/QqifxeB+ZZXym+AZ9+lmkJHREksRDIrwme6a/f9tJ7SwGEae9JM5gxXNgv0UFhROO53LHguXRYCu8VC5K3yfKdFAP40C4mLbOUNnywLJBorGicaLxqeEO/miWyIR0bNfxMWQAQUwbBw43BMfbsbOvaIfb6Me3Ew3Z5/n+SJDKqn6bjvDpep42AsptV0/UhnjPHzxgH7Aw==", file_map: { "14": { source: "// docs:start:ecdsa_secp256k1\n/// Verifies a ECDSA signature over the secp256k1 curve.\n/// - inputs:\n/// - x coordinate of public key as 32 bytes\n/// - y coordinate of public key as 32 bytes\n/// - the signature, as a 64 bytes array\n/// The signature internally will be represented as `(r, s)`,\n/// where `r` and `s` are fixed-sized big endian scalar values.\n/// As the `secp256k1` has a 256-bit modulus, we have a 64 byte signature\n/// while `r` and `s` will both be 32 bytes.\n/// We expect `s` to be normalized. This means given the curve's order,\n/// `s` should be less than or equal to `order / 2`.\n/// This is done to prevent malleability.\n/// For more context regarding malleability you can reference BIP 0062.\n/// - the hash of the message, as a vector of bytes\n/// - output: false for failure and true for success\npub fn verify_signature(\n public_key_x: [u8; 32],\n public_key_y: [u8; 32],\n signature: [u8; 64],\n message_hash: [u8; 32],\n) -> bool\n// docs:end:ecdsa_secp256k1\n{\n _verify_signature(public_key_x, public_key_y, signature, message_hash, true)\n}\n\n#[foreign(ecdsa_secp256k1)]\npub fn _verify_signature(\n public_key_x: [u8; 32],\n public_key_y: [u8; 32],\n signature: [u8; 64],\n message_hash: [u8; 32],\n predicate: bool,\n) -> bool {}\n", path: "std/ecdsa_secp256k1.nr" }, "16": { source: "use crate::cmp::Eq;\nuse crate::hash::Hash;\nuse crate::ops::arith::{Add, Neg, Sub};\n\n/// A point on the embedded elliptic curve\n/// By definition, the base field of the embedded curve is the scalar field of the proof system curve, i.e the Noir Field.\n/// x and y denotes the Weierstrass coordinates of the point, if is_infinite is false.\npub struct EmbeddedCurvePoint {\n pub x: Field,\n pub y: Field,\n pub is_infinite: bool,\n}\n\nimpl EmbeddedCurvePoint {\n /// Elliptic curve point doubling operation\n /// returns the doubled point of a point P, i.e P+P\n pub fn double(self) -> EmbeddedCurvePoint {\n embedded_curve_add(self, self)\n }\n\n /// Returns the null element of the curve; 'the point at infinity'\n pub fn point_at_infinity() -> EmbeddedCurvePoint {\n EmbeddedCurvePoint { x: 0, y: 0, is_infinite: true }\n }\n\n /// Returns the curve's generator point.\n pub fn generator() -> EmbeddedCurvePoint {\n // Generator point for the grumpkin curve (y^2 = x^3 - 17)\n EmbeddedCurvePoint {\n x: 1,\n y: 17631683881184975370165255887551781615748388533673675138860, // sqrt(-16)\n is_infinite: false,\n }\n }\n}\n\nimpl Add for EmbeddedCurvePoint {\n /// Adds two points P+Q, using the curve addition formula, and also handles point at infinity\n fn add(self, other: EmbeddedCurvePoint) -> EmbeddedCurvePoint {\n embedded_curve_add(self, other)\n }\n}\n\nimpl Sub for EmbeddedCurvePoint {\n /// Points subtraction operation, using addition and negation\n fn sub(self, other: EmbeddedCurvePoint) -> EmbeddedCurvePoint {\n self + other.neg()\n }\n}\n\nimpl Neg for EmbeddedCurvePoint {\n /// Negates a point P, i.e returns -P, by negating the y coordinate.\n /// If the point is at infinity, then the result is also at infinity.\n fn neg(self) -> EmbeddedCurvePoint {\n EmbeddedCurvePoint { x: self.x, y: -self.y, is_infinite: self.is_infinite }\n }\n}\n\nimpl Eq for EmbeddedCurvePoint {\n /// Checks whether two points are equal\n fn eq(self: Self, b: EmbeddedCurvePoint) -> bool {\n (self.is_infinite & b.is_infinite)\n | ((self.is_infinite == b.is_infinite) & (self.x == b.x) & (self.y == b.y))\n }\n}\n\nimpl Hash for EmbeddedCurvePoint {\n fn hash<H>(self, state: &mut H)\n where\n H: crate::hash::Hasher,\n {\n if self.is_infinite {\n self.is_infinite.hash(state);\n } else {\n self.x.hash(state);\n self.y.hash(state);\n }\n }\n}\n\n/// Scalar for the embedded curve represented as low and high limbs\n/// By definition, the scalar field of the embedded curve is base field of the proving system curve.\n/// It may not fit into a Field element, so it is represented with two Field elements; its low and high limbs.\npub struct EmbeddedCurveScalar {\n pub lo: Field,\n pub hi: Field,\n}\n\nimpl EmbeddedCurveScalar {\n pub fn new(lo: Field, hi: Field) -> Self {\n EmbeddedCurveScalar { lo, hi }\n }\n\n #[field(bn254)]\n pub fn from_field(scalar: Field) -> EmbeddedCurveScalar {\n let (a, b) = crate::field::bn254::decompose(scalar);\n EmbeddedCurveScalar { lo: a, hi: b }\n }\n\n //Bytes to scalar: take the first (after the specified offset) 16 bytes of the input as the lo value, and the next 16 bytes as the hi value\n #[field(bn254)]\n pub(crate) fn from_bytes(bytes: [u8; 64], offset: u32) -> EmbeddedCurveScalar {\n let mut v = 1;\n let mut lo = 0 as Field;\n let mut hi = 0 as Field;\n for i in 0..16 {\n lo = lo + (bytes[offset + 31 - i] as Field) * v;\n hi = hi + (bytes[offset + 15 - i] as Field) * v;\n v = v * 256;\n }\n let sig_s = crate::embedded_curve_ops::EmbeddedCurveScalar { lo, hi };\n sig_s\n }\n}\n\nimpl Eq for EmbeddedCurveScalar {\n fn eq(self, other: Self) -> bool {\n (other.hi == self.hi) & (other.lo == self.lo)\n }\n}\n\nimpl Hash for EmbeddedCurveScalar {\n fn hash<H>(self, state: &mut H)\n where\n H: crate::hash::Hasher,\n {\n self.hi.hash(state);\n self.lo.hash(state);\n }\n}\n\n// Computes a multi scalar multiplication over the embedded curve.\n// For bn254, We have Grumpkin and Baby JubJub.\n// For bls12-381, we have JubJub and Bandersnatch.\n//\n// The embedded curve being used is decided by the\n// underlying proof system.\n// docs:start:multi_scalar_mul\npub fn multi_scalar_mul<let N: u32>(\n points: [EmbeddedCurvePoint; N],\n scalars: [EmbeddedCurveScalar; N],\n) -> EmbeddedCurvePoint\n// docs:end:multi_scalar_mul\n{\n multi_scalar_mul_array_return(points, scalars, true)[0]\n}\n\n#[foreign(multi_scalar_mul)]\npub(crate) fn multi_scalar_mul_array_return<let N: u32>(\n points: [EmbeddedCurvePoint; N],\n scalars: [EmbeddedCurveScalar; N],\n predicate: bool,\n) -> [EmbeddedCurvePoint; 1] {}\n\n// docs:start:fixed_base_scalar_mul\npub fn fixed_base_scalar_mul(scalar: EmbeddedCurveScalar) -> EmbeddedCurvePoint\n// docs:end:fixed_base_scalar_mul\n{\n multi_scalar_mul([EmbeddedCurvePoint::generator()], [scalar])\n}\n\n/// This function only assumes that the points are on the curve\n/// It handles corner cases around the infinity point causing some overhead compared to embedded_curve_add_not_nul and embedded_curve_add_unsafe\n// docs:start:embedded_curve_add\npub fn embedded_curve_add(\n point1: EmbeddedCurvePoint,\n point2: EmbeddedCurvePoint,\n) -> EmbeddedCurvePoint {\n // docs:end:embedded_curve_add\n if crate::runtime::is_unconstrained() {\n // `embedded_curve_add_unsafe` requires the inputs not to be the infinity point, so we check it here.\n // This is because `embedded_curve_add_unsafe` uses the `embedded_curve_add` opcode.\n // For efficiency, the backend does not check the inputs for the infinity point, but it assumes that they are not the infinity point\n // so that it can apply the ec addition formula directly.\n if point1.is_infinite {\n point2\n } else if point2.is_infinite {\n point1\n } else {\n embedded_curve_add_unsafe(point1, point2)\n }\n } else {\n // In a constrained context, we also need to check the inputs are not the infinity point because we also use `embedded_curve_add_unsafe`\n // However we also need to identify the case where the two inputs are the same, because then\n // the addition formula does not work and we need to use the doubling formula instead.\n // In unconstrained context, we can check directly if the input values are the same when solving the opcode, so it is not an issue.\n\n // x_coordinates_match is true if both abscissae are the same\n let x_coordinates_match = point1.x == point2.x;\n // y_coordinates_match is true if both ordinates are the same\n let y_coordinates_match = point1.y == point2.y;\n // double_predicate is true if both abscissae and ordinates are the same\n let double_predicate = (x_coordinates_match & y_coordinates_match);\n // If the abscissae are the same, but not the ordinates, then one point is the opposite of the other\n let infinity_predicate = (x_coordinates_match & !y_coordinates_match);\n\n // `embedded_curve_add_unsafe` would not perform doubling, even if the inputs point1 and point2 are the same, because it cannot know this without adding some logic (and some constraints)\n // However we did this logic when we computed `double_predicate`, so we set the result to 2*point1 if point1 and point2 are the same\n let mut result = if double_predicate {\n // `embedded_curve_add_unsafe` is doing a doubling if the input is the same variable, because in this case it is guaranteed (at 'compile time') that the input is the same.\n embedded_curve_add_unsafe(point1, point1)\n } else {\n let point1_1 = EmbeddedCurvePoint {\n x: point1.x + (x_coordinates_match as Field),\n y: point1.y,\n is_infinite: false,\n };\n let point2_1 = EmbeddedCurvePoint { x: point2.x, y: point2.y, is_infinite: false };\n // point1_1 is guaranteed to have a different abscissa than point2:\n // - if x_coordinates_match is 0, that means point1.x != point2.x, and point1_1.x = point1.x + 0\n // - if x_coordinates_match is 1, that means point1.x = point2.x, but point1_1.x = point1.x + 1 in this case\n // Because the abscissa is different, the addition formula is guaranteed to succeed, so we can safely use `embedded_curve_add_unsafe`\n // Note that this computation may be garbage: if x_coordinates_match is 1, or if one of the input is the point at infinity.\n // therefore we only want to do this if we need the result, otherwise it needs to be eliminated as a dead instruction, lest we want the circuit to fail.\n embedded_curve_add_unsafe(point1_1, point2_1)\n };\n\n // Same logic as above for unconstrained context, we set the proper result when one of the inputs is the infinity point\n if point1.is_infinite {\n result = point2;\n }\n if point2.is_infinite {\n result = point1;\n }\n\n // Finally, we set the is_infinity flag of the result:\n // Opposite points should sum into the infinity point, however, if one of them is point at infinity, their coordinates are not meaningful\n // so we should not use the fact that the inputs are opposite in this case:\n let mut result_is_infinity =\n infinity_predicate & (!point1.is_infinite & !point2.is_infinite);\n // However, if both of them are at infinity, then the result is also at infinity\n result.is_infinite = result_is_infinity | (point1.is_infinite & point2.is_infinite);\n result\n }\n}\n\n#[foreign(embedded_curve_add)]\nfn embedded_curve_add_array_return(\n _point1: EmbeddedCurvePoint,\n _point2: EmbeddedCurvePoint,\n _predicate: bool,\n) -> [EmbeddedCurvePoint; 1] {}\n\n/// This function assumes that:\n/// The points are on the curve, and\n/// The points don't share an x-coordinate, and\n/// Neither point is the infinity point.\n/// If it is used with correct input, the function ensures the correct non-zero result is returned.\n/// Except for points on the curve, the other assumptions are checked by the function. It will cause assertion failure if they are not respected.\npub fn embedded_curve_add_not_nul(\n point1: EmbeddedCurvePoint,\n point2: EmbeddedCurvePoint,\n) -> EmbeddedCurvePoint {\n assert(point1.x != point2.x);\n assert(!point1.is_infinite);\n assert(!point2.is_infinite);\n // Ensure is_infinite is comptime\n let point1_1 = EmbeddedCurvePoint { x: point1.x, y: point1.y, is_infinite: false };\n let point2_1 = EmbeddedCurvePoint { x: point2.x, y: point2.y, is_infinite: false };\n embedded_curve_add_unsafe(point1_1, point2_1)\n}\n\n/// Unsafe ec addition\n/// If the inputs are the same, it will perform a doubling, but only if point1 and point2 are the same variable.\n/// If they have the same value but are different variables, the result will be incorrect because in this case\n/// it assumes (but does not check) that the points' x-coordinates are not equal.\n/// It also assumes neither point is the infinity point.\npub fn embedded_curve_add_unsafe(\n point1: EmbeddedCurvePoint,\n point2: EmbeddedCurvePoint,\n) -> EmbeddedCurvePoint {\n embedded_curve_add_array_return(point1, point2, true)[0]\n}\n", path: "std/embedded_curve_ops.nr" }, "17": { source: `use crate::field::field_less_than;
3615
- use crate::runtime::is_unconstrained;
3616
-
3617
- // The low and high decomposition of the field modulus
3618
- global PLO: Field = 53438638232309528389504892708671455233;
3619
- global PHI: Field = 64323764613183177041862057485226039389;
3620
-
3621
- pub(crate) global TWO_POW_128: Field = 0x100000000000000000000000000000000;
3622
-
3623
- // Decomposes a single field into two 16 byte fields.
3624
- fn compute_decomposition(x: Field) -> (Field, Field) {
3625
- // Here's we're taking advantage of truncating 128 bit limbs from the input field
3626
- // and then subtracting them from the input such the field division is equivalent to integer division.
3627
- let low = (x as u128) as Field;
3628
- let high = (x - low) / TWO_POW_128;
3629
-
3630
- (low, high)
3631
- }
3632
-
3633
- pub(crate) unconstrained fn decompose_hint(x: Field) -> (Field, Field) {
3634
- compute_decomposition(x)
3635
- }
3636
-
3637
- unconstrained fn lte_hint(x: Field, y: Field) -> bool {
3638
- if x == y {
3639
- true
3640
- } else {
3641
- field_less_than(x, y)
3642
- }
3643
- }
3644
-
3645
- // Assert that (alo > blo && ahi >= bhi) || (alo <= blo && ahi > bhi)
3646
- fn assert_gt_limbs(a: (Field, Field), b: (Field, Field)) {
3647
- let (alo, ahi) = a;
3648
- let (blo, bhi) = b;
3649
- // Safety: borrow is enforced to be boolean due to its type.
3650
- // if borrow is 0, it asserts that (alo > blo && ahi >= bhi)
3651
- // if borrow is 1, it asserts that (alo <= blo && ahi > bhi)
3652
- unsafe {
3653
- let borrow = lte_hint(alo, blo);
3654
-
3655
- let rlo = alo - blo - 1 + (borrow as Field) * TWO_POW_128;
3656
- let rhi = ahi - bhi - (borrow as Field);
3657
-
3658
- rlo.assert_max_bit_size::<128>();
3659
- rhi.assert_max_bit_size::<128>();
3660
- }
3661
- }
3662
-
3663
- /// Decompose a single field into two 16 byte fields.
3664
- pub fn decompose(x: Field) -> (Field, Field) {
3665
- if is_unconstrained() {
3666
- compute_decomposition(x)
3667
- } else {
3668
- // Safety: decomposition is properly checked below
3669
- unsafe {
3670
- // Take hints of the decomposition
3671
- let (xlo, xhi) = decompose_hint(x);
3672
-
3673
- // Range check the limbs
3674
- xlo.assert_max_bit_size::<128>();
3675
- xhi.assert_max_bit_size::<128>();
3676
-
3677
- // Check that the decomposition is correct
3678
- assert_eq(x, xlo + TWO_POW_128 * xhi);
3679
-
3680
- // Assert that the decomposition of P is greater than the decomposition of x
3681
- assert_gt_limbs((PLO, PHI), (xlo, xhi));
3682
- (xlo, xhi)
3683
- }
3684
- }
3685
- }
3686
-
3687
- pub fn assert_gt(a: Field, b: Field) {
3688
- if is_unconstrained() {
3689
- assert(
3690
- // Safety: already unconstrained
3691
- unsafe { field_less_than(b, a) },
3692
- );
3693
- } else {
3694
- // Decompose a and b
3695
- let a_limbs = decompose(a);
3696
- let b_limbs = decompose(b);
3697
-
3698
- // Assert that a_limbs is greater than b_limbs
3699
- assert_gt_limbs(a_limbs, b_limbs)
3700
- }
3701
- }
3702
-
3703
- pub fn assert_lt(a: Field, b: Field) {
3704
- assert_gt(b, a);
3705
- }
3706
-
3707
- pub fn gt(a: Field, b: Field) -> bool {
3708
- if is_unconstrained() {
3709
- // Safety: unsafe in unconstrained
3710
- unsafe {
3711
- field_less_than(b, a)
3712
- }
3713
- } else if a == b {
3714
- false
3715
- } else {
3716
- // Safety: Take a hint of the comparison and verify it
3717
- unsafe {
3718
- if field_less_than(a, b) {
3719
- assert_gt(b, a);
3720
- false
3721
- } else {
3722
- assert_gt(a, b);
3723
- true
3724
- }
3725
- }
3726
- }
3727
- }
3728
-
3729
- pub fn lt(a: Field, b: Field) -> bool {
3730
- gt(b, a)
3731
- }
3732
-
3733
- mod tests {
3734
- // TODO: Allow imports from "super"
3735
- use crate::field::bn254::{assert_gt, decompose, gt, lt, lte_hint, PHI, PLO, TWO_POW_128};
3736
-
3737
- #[test]
3738
- fn check_decompose() {
3739
- assert_eq(decompose(TWO_POW_128), (0, 1));
3740
- assert_eq(decompose(TWO_POW_128 + 0x1234567890), (0x1234567890, 1));
3741
- assert_eq(decompose(0x1234567890), (0x1234567890, 0));
3742
- }
3743
-
3744
- #[test]
3745
- unconstrained fn check_lte_hint() {
3746
- assert(lte_hint(0, 1));
3747
- assert(lte_hint(0, 0x100));
3748
- assert(lte_hint(0x100, TWO_POW_128 - 1));
3749
- assert(!lte_hint(0 - 1, 0));
3750
-
3751
- assert(lte_hint(0, 0));
3752
- assert(lte_hint(0x100, 0x100));
3753
- assert(lte_hint(0 - 1, 0 - 1));
3754
- }
3755
-
3756
- #[test]
3757
- fn check_gt() {
3758
- assert(gt(1, 0));
3759
- assert(gt(0x100, 0));
3760
- assert(gt((0 - 1), (0 - 2)));
3761
- assert(gt(TWO_POW_128, 0));
3762
- assert(!gt(0, 0));
3763
- assert(!gt(0, 0x100));
3764
- assert(gt(0 - 1, 0 - 2));
3765
- assert(!gt(0 - 2, 0 - 1));
3766
- assert_gt(0 - 1, 0);
3767
- }
3768
-
3769
- #[test]
3770
- fn check_plo_phi() {
3771
- assert_eq(PLO + PHI * TWO_POW_128, 0);
3772
- let p_bytes = crate::field::modulus_le_bytes();
3773
- let mut p_low: Field = 0;
3774
- let mut p_high: Field = 0;
3775
-
3776
- let mut offset = 1;
3777
- for i in 0..16 {
3778
- p_low += (p_bytes[i] as Field) * offset;
3779
- p_high += (p_bytes[i + 16] as Field) * offset;
3780
- offset *= 256;
3781
- }
3782
- assert_eq(p_low, PLO);
3783
- assert_eq(p_high, PHI);
3784
- }
3785
-
3786
- #[test]
3787
- fn check_decompose_edge_cases() {
3788
- assert_eq(decompose(0), (0, 0));
3789
- assert_eq(decompose(TWO_POW_128 - 1), (TWO_POW_128 - 1, 0));
3790
- assert_eq(decompose(TWO_POW_128 + 1), (1, 1));
3791
- assert_eq(decompose(TWO_POW_128 * 2), (0, 2));
3792
- assert_eq(decompose(TWO_POW_128 * 2 + 0x1234567890), (0x1234567890, 2));
3793
- }
3794
-
3795
- #[test]
3796
- fn check_decompose_large_values() {
3797
- let large_field = 0xffffffffffffffff;
3798
- let (lo, hi) = decompose(large_field);
3799
- assert_eq(large_field, lo + TWO_POW_128 * hi);
3800
-
3801
- let large_value = large_field - TWO_POW_128;
3802
- let (lo2, hi2) = decompose(large_value);
3803
- assert_eq(large_value, lo2 + TWO_POW_128 * hi2);
3804
- }
3805
-
3806
- #[test]
3807
- fn check_lt_comprehensive() {
3808
- assert(lt(0, 1));
3809
- assert(!lt(1, 0));
3810
- assert(!lt(0, 0));
3811
- assert(!lt(42, 42));
3812
-
3813
- assert(lt(TWO_POW_128 - 1, TWO_POW_128));
3814
- assert(!lt(TWO_POW_128, TWO_POW_128 - 1));
3815
- }
3816
- }
3817
- `, path: "std/field/bn254.nr" }, "19": { source: '// Exposed only for usage in `std::meta`\npub(crate) mod poseidon2;\n\nuse crate::default::Default;\nuse crate::embedded_curve_ops::{\n EmbeddedCurvePoint, EmbeddedCurveScalar, multi_scalar_mul, multi_scalar_mul_array_return,\n};\nuse crate::meta::derive_via;\n\n#[foreign(sha256_compression)]\n// docs:start:sha256_compression\npub fn sha256_compression(input: [u32; 16], state: [u32; 8]) -> [u32; 8] {}\n// docs:end:sha256_compression\n\n#[foreign(keccakf1600)]\n// docs:start:keccakf1600\npub fn keccakf1600(input: [u64; 25]) -> [u64; 25] {}\n// docs:end:keccakf1600\n\npub mod keccak {\n #[deprecated("This function has been moved to std::hash::keccakf1600")]\n pub fn keccakf1600(input: [u64; 25]) -> [u64; 25] {\n super::keccakf1600(input)\n }\n}\n\n#[foreign(blake2s)]\n// docs:start:blake2s\npub fn blake2s<let N: u32>(input: [u8; N]) -> [u8; 32]\n// docs:end:blake2s\n{}\n\n// docs:start:blake3\npub fn blake3<let N: u32>(input: [u8; N]) -> [u8; 32]\n// docs:end:blake3\n{\n if crate::runtime::is_unconstrained() {\n // Temporary measure while Barretenberg is main proving system.\n // Please open an issue if you\'re working on another proving system and running into problems due to this.\n crate::static_assert(\n N <= 1024,\n "Barretenberg cannot prove blake3 hashes with inputs larger than 1024 bytes",\n );\n }\n __blake3(input)\n}\n\n#[foreign(blake3)]\nfn __blake3<let N: u32>(input: [u8; N]) -> [u8; 32] {}\n\n// docs:start:pedersen_commitment\npub fn pedersen_commitment<let N: u32>(input: [Field; N]) -> EmbeddedCurvePoint {\n // docs:end:pedersen_commitment\n pedersen_commitment_with_separator(input, 0)\n}\n\n#[inline_always]\npub fn pedersen_commitment_with_separator<let N: u32>(\n input: [Field; N],\n separator: u32,\n) -> EmbeddedCurvePoint {\n let mut points = [EmbeddedCurveScalar { lo: 0, hi: 0 }; N];\n for i in 0..N {\n // we use the unsafe version because the multi_scalar_mul will constrain the scalars.\n points[i] = from_field_unsafe(input[i]);\n }\n let generators = derive_generators("DEFAULT_DOMAIN_SEPARATOR".as_bytes(), separator);\n multi_scalar_mul(generators, points)\n}\n\n// docs:start:pedersen_hash\npub fn pedersen_hash<let N: u32>(input: [Field; N]) -> Field\n// docs:end:pedersen_hash\n{\n pedersen_hash_with_separator(input, 0)\n}\n\n#[no_predicates]\npub fn pedersen_hash_with_separator<let N: u32>(input: [Field; N], separator: u32) -> Field {\n let mut scalars: [EmbeddedCurveScalar; N + 1] = [EmbeddedCurveScalar { lo: 0, hi: 0 }; N + 1];\n let mut generators: [EmbeddedCurvePoint; N + 1] =\n [EmbeddedCurvePoint::point_at_infinity(); N + 1];\n let domain_generators: [EmbeddedCurvePoint; N] =\n derive_generators("DEFAULT_DOMAIN_SEPARATOR".as_bytes(), separator);\n\n for i in 0..N {\n scalars[i] = from_field_unsafe(input[i]);\n generators[i] = domain_generators[i];\n }\n scalars[N] = EmbeddedCurveScalar { lo: N as Field, hi: 0 as Field };\n\n let length_generator: [EmbeddedCurvePoint; 1] =\n derive_generators("pedersen_hash_length".as_bytes(), 0);\n generators[N] = length_generator[0];\n multi_scalar_mul_array_return(generators, scalars, true)[0].x\n}\n\n#[field(bn254)]\n#[inline_always]\npub fn derive_generators<let N: u32, let M: u32>(\n domain_separator_bytes: [u8; M],\n starting_index: u32,\n) -> [EmbeddedCurvePoint; N] {\n crate::assert_constant(domain_separator_bytes);\n // TODO(https://github.com/noir-lang/noir/issues/5672): Add back assert_constant on starting_index\n __derive_generators(domain_separator_bytes, starting_index)\n}\n\n#[builtin(derive_pedersen_generators)]\n#[field(bn254)]\nfn __derive_generators<let N: u32, let M: u32>(\n domain_separator_bytes: [u8; M],\n starting_index: u32,\n) -> [EmbeddedCurvePoint; N] {}\n\n#[field(bn254)]\n// Same as from_field but:\n// does not assert the limbs are 128 bits\n// does not assert the decomposition does not overflow the EmbeddedCurveScalar\nfn from_field_unsafe(scalar: Field) -> EmbeddedCurveScalar {\n // Safety: xlo and xhi decomposition is checked below\n let (xlo, xhi) = unsafe { crate::field::bn254::decompose_hint(scalar) };\n // Check that the decomposition is correct\n assert_eq(scalar, xlo + crate::field::bn254::TWO_POW_128 * xhi);\n EmbeddedCurveScalar { lo: xlo, hi: xhi }\n}\n\npub fn poseidon2_permutation<let N: u32>(input: [Field; N], state_len: u32) -> [Field; N] {\n assert_eq(input.len(), state_len);\n poseidon2_permutation_internal(input)\n}\n\n#[foreign(poseidon2_permutation)]\nfn poseidon2_permutation_internal<let N: u32>(input: [Field; N]) -> [Field; N] {}\n\n// Generic hashing support.\n// Partially ported and impacted by rust.\n\n// Hash trait shall be implemented per type.\n#[derive_via(derive_hash)]\npub trait Hash {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher;\n}\n\n// docs:start:derive_hash\ncomptime fn derive_hash(s: TypeDefinition) -> Quoted {\n let name = quote { $crate::hash::Hash };\n let signature = quote { fn hash<H>(_self: Self, _state: &mut H) where H: $crate::hash::Hasher };\n let for_each_field = |name| quote { _self.$name.hash(_state); };\n crate::meta::make_trait_impl(\n s,\n name,\n signature,\n for_each_field,\n quote {},\n |fields| fields,\n )\n}\n// docs:end:derive_hash\n\n// Hasher trait shall be implemented by algorithms to provide hash-agnostic means.\n// TODO: consider making the types generic here ([u8], [Field], etc.)\npub trait Hasher {\n fn finish(self) -> Field;\n\n fn write(&mut self, input: Field);\n}\n\n// BuildHasher is a factory trait, responsible for production of specific Hasher.\npub trait BuildHasher {\n type H: Hasher;\n\n fn build_hasher(self) -> H;\n}\n\npub struct BuildHasherDefault<H>;\n\nimpl<H> BuildHasher for BuildHasherDefault<H>\nwhere\n H: Hasher + Default,\n{\n type H = H;\n\n fn build_hasher(_self: Self) -> H {\n H::default()\n }\n}\n\nimpl<H> Default for BuildHasherDefault<H>\nwhere\n H: Hasher + Default,\n{\n fn default() -> Self {\n BuildHasherDefault {}\n }\n}\n\nimpl Hash for Field {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self);\n }\n}\n\nimpl Hash for u1 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for u8 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for u16 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for u32 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for u64 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for u128 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for i8 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as u8 as Field);\n }\n}\n\nimpl Hash for i16 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as u16 as Field);\n }\n}\n\nimpl Hash for i32 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as u32 as Field);\n }\n}\n\nimpl Hash for i64 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as u64 as Field);\n }\n}\n\nimpl Hash for bool {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for () {\n fn hash<H>(_self: Self, _state: &mut H)\n where\n H: Hasher,\n {}\n}\n\nimpl<T, let N: u32> Hash for [T; N]\nwhere\n T: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n for elem in self {\n elem.hash(state);\n }\n }\n}\n\nimpl<T> Hash for [T]\nwhere\n T: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n self.len().hash(state);\n for elem in self {\n elem.hash(state);\n }\n }\n}\n\nimpl<A, B> Hash for (A, B)\nwhere\n A: Hash,\n B: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n self.0.hash(state);\n self.1.hash(state);\n }\n}\n\nimpl<A, B, C> Hash for (A, B, C)\nwhere\n A: Hash,\n B: Hash,\n C: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n self.0.hash(state);\n self.1.hash(state);\n self.2.hash(state);\n }\n}\n\nimpl<A, B, C, D> Hash for (A, B, C, D)\nwhere\n A: Hash,\n B: Hash,\n C: Hash,\n D: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n self.0.hash(state);\n self.1.hash(state);\n self.2.hash(state);\n self.3.hash(state);\n }\n}\n\nimpl<A, B, C, D, E> Hash for (A, B, C, D, E)\nwhere\n A: Hash,\n B: Hash,\n C: Hash,\n D: Hash,\n E: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n self.0.hash(state);\n self.1.hash(state);\n self.2.hash(state);\n self.3.hash(state);\n self.4.hash(state);\n }\n}\n\n// Some test vectors for Pedersen hash and Pedersen Commitment.\n// They have been generated using the same functions so the tests are for now useless\n// but they will be useful when we switch to Noir implementation.\n#[test]\nfn assert_pedersen() {\n assert_eq(\n pedersen_hash_with_separator([1], 1),\n 0x1b3f4b1a83092a13d8d1a59f7acb62aba15e7002f4440f2275edb99ebbc2305f,\n );\n assert_eq(\n pedersen_commitment_with_separator([1], 1),\n EmbeddedCurvePoint {\n x: 0x054aa86a73cb8a34525e5bbed6e43ba1198e860f5f3950268f71df4591bde402,\n y: 0x209dcfbf2cfb57f9f6046f44d71ac6faf87254afc7407c04eb621a6287cac126,\n is_infinite: false,\n },\n );\n\n assert_eq(\n pedersen_hash_with_separator([1, 2], 2),\n 0x26691c129448e9ace0c66d11f0a16d9014a9e8498ee78f4d69f0083168188255,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2], 2),\n EmbeddedCurvePoint {\n x: 0x2e2b3b191e49541fe468ec6877721d445dcaffe41728df0a0eafeb15e87b0753,\n y: 0x2ff4482400ad3a6228be17a2af33e2bcdf41be04795f9782bd96efe7e24f8778,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3], 3),\n 0x0bc694b7a1f8d10d2d8987d07433f26bd616a2d351bc79a3c540d85b6206dbe4,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3], 3),\n EmbeddedCurvePoint {\n x: 0x1fee4e8cf8d2f527caa2684236b07c4b1bad7342c01b0f75e9a877a71827dc85,\n y: 0x2f9fedb9a090697ab69bf04c8bc15f7385b3e4b68c849c1536e5ae15ff138fd1,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4], 4),\n 0xdae10fb32a8408521803905981a2b300d6a35e40e798743e9322b223a5eddc,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4], 4),\n EmbeddedCurvePoint {\n x: 0x07ae3e202811e1fca39c2d81eabe6f79183978e6f12be0d3b8eda095b79bdbc9,\n y: 0x0afc6f892593db6fbba60f2da558517e279e0ae04f95758587760ba193145014,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5], 5),\n 0xfc375b062c4f4f0150f7100dfb8d9b72a6d28582dd9512390b0497cdad9c22,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5], 5),\n EmbeddedCurvePoint {\n x: 0x1754b12bd475a6984a1094b5109eeca9838f4f81ac89c5f0a41dbce53189bb29,\n y: 0x2da030e3cfcdc7ddad80eaf2599df6692cae0717d4e9f7bfbee8d073d5d278f7,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5, 6], 6),\n 0x1696ed13dc2730062a98ac9d8f9de0661bb98829c7582f699d0273b18c86a572,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5, 6], 6),\n EmbeddedCurvePoint {\n x: 0x190f6c0e97ad83e1e28da22a98aae156da083c5a4100e929b77e750d3106a697,\n y: 0x1f4b60f34ef91221a0b49756fa0705da93311a61af73d37a0c458877706616fb,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5, 6, 7], 7),\n 0x128c0ff144fc66b6cb60eeac8a38e23da52992fc427b92397a7dffd71c45ede3,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5, 6, 7], 7),\n EmbeddedCurvePoint {\n x: 0x015441e9d29491b06563fac16fc76abf7a9534c715421d0de85d20dbe2965939,\n y: 0x1d2575b0276f4e9087e6e07c2cb75aa1baafad127af4be5918ef8a2ef2fea8fc,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5, 6, 7, 8], 8),\n 0x2f960e117482044dfc99d12fece2ef6862fba9242be4846c7c9a3e854325a55c,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5, 6, 7, 8], 8),\n EmbeddedCurvePoint {\n x: 0x1657737676968887fceb6dd516382ea13b3a2c557f509811cd86d5d1199bc443,\n y: 0x1f39f0cb569040105fa1e2f156521e8b8e08261e635a2b210bdc94e8d6d65f77,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5, 6, 7, 8, 9], 9),\n 0x0c96db0790602dcb166cc4699e2d306c479a76926b81c2cb2aaa92d249ec7be7,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5, 6, 7, 8, 9], 9),\n EmbeddedCurvePoint {\n x: 0x0a3ceae42d14914a432aa60ec7fded4af7dad7dd4acdbf2908452675ec67e06d,\n y: 0xfc19761eaaf621ad4aec9a8b2e84a4eceffdba78f60f8b9391b0bd9345a2f2,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 10),\n 0x2cd37505871bc460a62ea1e63c7fe51149df5d0801302cf1cbc48beb8dff7e94,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 10),\n EmbeddedCurvePoint {\n x: 0x2fb3f8b3d41ddde007c8c3c62550f9a9380ee546fcc639ffbb3fd30c8d8de30c,\n y: 0x300783be23c446b11a4c0fabf6c91af148937cea15fcf5fb054abf7f752ee245,\n is_infinite: false,\n },\n );\n}\n', path: "std/hash/mod.nr" }, "50": { source: `/// Validity Proof Circuit
3818
- ///
3819
- /// Proves: "This intent is authorized by the sender, without revealing
3820
- /// the sender's identity, private key, or signature."
3821
- ///
3822
- /// @see docs/specs/VALIDITY-PROOF.md
3823
-
3824
- use std::hash::pedersen_hash;
3825
- use std::hash::pedersen_commitment;
3826
- use std::ecdsa_secp256k1::verify_signature;
3827
-
3828
- // --- Main Circuit ---
3829
-
3830
- /// Main validity proof entry point
3831
- ///
3832
- /// Public inputs: intent_hash, sender_commitment (x,y), nullifier, timestamp, expiry
3833
- /// Private inputs: sender_address (Field), sender_blinding, sender_secret,
3834
- /// pub_key_x, pub_key_y, signature, message_hash, nonce
3835
- ///
3836
- /// Constraints:
3837
- /// 1. sender_commitment = Pedersen(sender_address, sender_blinding)
3838
- /// 2. signature is valid for message_hash using pub_key
3839
- /// 3. nullifier = Pedersen_hash(sender_secret, intent_hash, nonce)
3840
- /// 4. timestamp < expiry
3841
- pub fn main(
3842
- // Public inputs
3843
- intent_hash: pub Field,
3844
- sender_commitment_x: pub Field,
3845
- sender_commitment_y: pub Field,
3846
- nullifier: pub Field,
3847
- timestamp: pub u64,
3848
- expiry: pub u64,
3849
-
3850
- // Private inputs
3851
- sender_address: Field,
3852
- sender_blinding: Field,
3853
- sender_secret: Field,
3854
- pub_key_x: [u8; 32],
3855
- pub_key_y: [u8; 32],
3856
- signature: [u8; 64],
3857
- message_hash: [u8; 32],
3858
- nonce: Field,
3859
- ) {
3860
- // Constraint 1: Verify Sender Commitment
3861
- // C = Pedersen(sender_address, sender_blinding)
3862
- let commitment = pedersen_commitment([sender_address, sender_blinding]);
3863
- assert(commitment.x == sender_commitment_x, "Sender commitment X mismatch");
3864
- assert(commitment.y == sender_commitment_y, "Sender commitment Y mismatch");
3865
-
3866
- // Constraint 2: Verify ECDSA Signature
3867
- // The signature must be valid for the message_hash using the provided public key
3868
- let valid_sig = verify_signature(pub_key_x, pub_key_y, signature, message_hash);
3869
- assert(valid_sig, "Invalid ECDSA signature");
3870
-
3871
- // Constraint 3: Verify Nullifier Derivation
3872
- // nullifier = Pedersen_hash(sender_secret, intent_hash, nonce)
3873
- let computed_nullifier = pedersen_hash([sender_secret, intent_hash, nonce]);
3874
- assert(computed_nullifier == nullifier, "Nullifier mismatch");
3875
-
3876
- // Constraint 4: Time Bounds Check
3877
- assert(timestamp < expiry, "Intent expired");
3878
- }
3879
-
3880
- // --- Tests ---
3881
-
3882
- // NOTE: Full ECDSA integration test requires TypeScript to generate valid signatures
3883
- // The NoirProofProvider in SDK will generate proper test vectors
3884
- // Here we test the commitment and nullifier logic which are pure Noir
3885
-
3886
- #[test]
3887
- fn test_commitment_and_nullifier() {
3888
- // Test just the commitment and nullifier computation (without ECDSA)
3889
- let sender_address: Field = 0x742d35Cc6634C0532925a3b844Bc9e7595f;
3890
- let sender_blinding: Field = 0xABCDEF123456;
3891
- let sender_secret: Field = 0x1234567890ABCDEF;
3892
- let intent_hash: Field = 0xDEADBEEF;
3893
- let nonce: Field = 0x99999;
3894
-
3895
- // Compute and verify commitment is consistent
3896
- let commitment1 = pedersen_commitment([sender_address, sender_blinding]);
3897
- let commitment2 = pedersen_commitment([sender_address, sender_blinding]);
3898
- assert(commitment1.x == commitment2.x, "Commitment X should be deterministic");
3899
- assert(commitment1.y == commitment2.y, "Commitment Y should be deterministic");
3900
-
3901
- // Compute and verify nullifier is consistent
3902
- let nullifier1 = pedersen_hash([sender_secret, intent_hash, nonce]);
3903
- let nullifier2 = pedersen_hash([sender_secret, intent_hash, nonce]);
3904
- assert(nullifier1 == nullifier2, "Nullifier should be deterministic");
3905
-
3906
- // Different nonce should give different nullifier
3907
- let different_nonce: Field = 0x88888;
3908
- let nullifier3 = pedersen_hash([sender_secret, intent_hash, different_nonce]);
3909
- assert(nullifier1 != nullifier3, "Different nonce should give different nullifier");
3910
- }
3911
-
3912
- #[test]
3913
- fn test_time_bounds() {
3914
- // Test timestamp < expiry constraint
3915
- let valid_timestamp: u64 = 1732600000;
3916
- let valid_expiry: u64 = 1732686400;
3917
- assert(valid_timestamp < valid_expiry, "Valid time bounds");
3918
- }
3919
-
3920
- // NOTE: Full integration tests with ECDSA require TypeScript SDK
3921
- // The NoirProofProvider will generate valid signature test vectors
3922
- `, path: "/Users/rz/local-dev/sip-protocol/packages/circuits/validity_proof/src/main.nr" } }, expression_width: { Bounded: { width: 4 } } };
3923
-
3924
- // src/proofs/circuits/fulfillment_proof.json
3925
- var fulfillment_proof_default = { noir_version: "1.0.0-beta.15+83245db91dcf63420ef4bcbbd85b98f397fee663", hash: "13146944445132352806", abi: { parameters: [{ name: "intent_hash", type: { kind: "field" }, visibility: "public" }, { name: "output_commitment_x", type: { kind: "field" }, visibility: "public" }, { name: "output_commitment_y", type: { kind: "field" }, visibility: "public" }, { name: "recipient_stealth", type: { kind: "field" }, visibility: "public" }, { name: "min_output_amount", type: { kind: "integer", sign: "unsigned", width: 64 }, visibility: "public" }, { name: "solver_id", type: { kind: "field" }, visibility: "public" }, { name: "fulfillment_time", type: { kind: "integer", sign: "unsigned", width: 64 }, visibility: "public" }, { name: "expiry", type: { kind: "integer", sign: "unsigned", width: 64 }, visibility: "public" }, { name: "output_amount", type: { kind: "integer", sign: "unsigned", width: 64 }, visibility: "private" }, { name: "output_blinding", type: { kind: "field" }, visibility: "private" }, { name: "solver_secret", type: { kind: "field" }, visibility: "private" }, { name: "attestation_recipient", type: { kind: "field" }, visibility: "private" }, { name: "attestation_amount", type: { kind: "integer", sign: "unsigned", width: 64 }, visibility: "private" }, { name: "attestation_tx_hash", type: { kind: "field" }, visibility: "private" }, { name: "attestation_block", type: { kind: "integer", sign: "unsigned", width: 64 }, visibility: "private" }, { name: "oracle_signature", type: { kind: "array", length: 64, type: { kind: "integer", sign: "unsigned", width: 8 } }, visibility: "private" }, { name: "oracle_message_hash", type: { kind: "array", length: 32, type: { kind: "integer", sign: "unsigned", width: 8 } }, visibility: "private" }, { name: "oracle_pub_key_x", type: { kind: "array", length: 32, type: { kind: "integer", sign: "unsigned", width: 8 } }, visibility: "private" }, { name: "oracle_pub_key_y", type: { kind: "array", length: 32, type: { kind: "integer", sign: "unsigned", width: 8 } }, visibility: "private" }], return_type: null, error_types: { "1811611355587044900": { error_kind: "string", string: "Unauthorized solver" }, "5682920188479059162": { error_kind: "string", string: "Amount mismatch in attestation" }, "9350488092177273812": { error_kind: "string", string: "Recipient mismatch in attestation" }, "10078784717933725989": { error_kind: "string", string: "Invalid oracle attestation signature" }, "10879340518732620616": { error_kind: "string", string: "Commitment X mismatch" }, "12297495446303487112": { error_kind: "string", string: "Output below minimum" }, "12394005467219657293": { error_kind: "string", string: "Commitment Y mismatch" }, "15764276373176857197": { error_kind: "string", string: "Stack too deep" }, "17406200060514520896": { error_kind: "string", string: "Fulfillment after expiry" } } }, bytecode: "H4sIAAAAAAAA/82aCXBV1QGGzwshhBqJEJYQBR7IFoFIgKAIQhRCIErYouwJIQkQNAlkgyBCwr4ohKXUglpcKgFBtpiyCrZjW7GM06kjHactOmO1M51au+gA6oz5yX/zDpefvPcSdTwz8OV999x7z7153Pz/Cx5TN0LJvMzc/HO1fIOvPbV/mpGYk+hyYcK1EC5cuAjhWgkXyf1td5twrYVrI1yUcG2Faydce+E6CBctXEfhYoS7Xbg7hOskXGfhugjnFa6rcN2Eu1O47sL1EK6ncL2E6y1crHB3CddHuL7C9RMuTri7hesvXLxwA4QbKNwg4RKEGyzcPcLdK9wQ4e4Tbqhww4S7X7jhwo0QLlG4B4R7ULiRwo0SLkm40cIlCzdGuLHCpQj3kHAPCzdOuFThxgs3QbiJwk0SbrJwacI9Ityjwk0Rbqpw04SbLtwM4WYKN0u4dOEyhJstXKZwc4TLEi5buBzh5go3T7j5wuUKt0C4x4R7XLg84fKFKxBuoXCLhCsUrki4YuFKhCsVbrFwS4QrE26pcE8It0y4J4VbLtwK4cqFqxBupXCrhFst3Brh1gq3Trj1wm0QbqNwm4R7Srinhdss3BbhKoXbKtw24bYLt0O4nwq3U7ifCfeMcD8Xbpdwu4V7VrjnhHteuF8It0e4F4R7UbiXhHtZuF8K94pwe4WrEm6fcPuFe1W4A8IdFO41ulC+DjE3Dsd5yf7ZqYUfxe+JPT4hqaaiYuqs3gP/MabsxMKtIz/6YvvnPJbXBDQ84f7nehra6DWB7Wtf1yHysDPDuRkQia4jhLpO9H1d/E2OW8njeg4FsYbDpnE31RPktdpr8netoQ2c2H1ef8cK4E1TP+xv/BHyqHtSsyYswN9NOnLzuTNdcz1HA1+D+S5vaEvTuBt6jKx2Twr2htoL8HdDj5nAb2h14Gu4dtPwjQ2znJcMH17W+s8JLUtjPw8rif+63flvyqp2f/bOkMoRuVP6ZhWkTLfnxqxIv3pwRfzMHvui/xfx+4sDR/zh1aUX345s+7eK02/1vrJ9lj03kOHMbZ5StaDonY2DJqXPeOP9j4e+0HHz2siMIRN6bll0KWnrmY9D7Lne59492/erKVe+DC0YdTHmt1cvF6Yd+l3istB/zomZs+78mz3tuf6G/UY7Qh4lj5HVrrX6GZ7Xa/+qqf3zK9eGYH/UeExw5wxwbpPWFGICX1ON+WHW1MwEvqZbzA+zpiCe4p4I07g1BfsT7bgJfE04dhjPUUAuJBeRhWQRWUyWkKXkYnIJWUYuJZ8gl5FPksvJFWQ5WUGuJFeRq8k15FpyHbme3EBuJDeRT5FPk5uNr7KAlcZXTcBtxldBwB3GVzXAncZXKcBnjK86gLuMryKAzxpfFQCfN77ID+4xvmgPvmh8ER582fiiOviK8UVysMr4oje43/giNnjA+KI0+BoZSd5GtibbkFFkW7Id2Z7sQEaTHckY8nbyDrIT2ZnsYnzPQrAr2Y28k+xO9iB7kr3I3mQseRfZh+xL9iPjyLvJ/mQ8OYAcSA4iE8jB5D3kveQQ8j5yKDmMvJ8cTo4gE8kHyAfJkeQoMokcTSaTY8ixZAr5EPkwOY5MJceTE8iJ5CRyMplGPkI+Sk4hp5LTyOnkDHImOYtMJzPI2WQmOYfMIrPJHHIuOY+cT+aSC8jHyMfJPDKfxHPzhLl+eEivCWh4TlhzA2lZ9jmact6fBD73uvB7kjzlnhRs+LUX4O/CT9587g3h91Tga7h2037M4bff5ROJf9/QKjVq8YeTi65+sqtTyfjchE/2ltfM3VEc/98LF+y5cRfW/3HavNOTj6/ZGndr+7WZaQdq9v/6T5fTe51f/u+jb1ausuf6G/Yb7SR5yrU2P8MTxNygjnu69q8zxve7a2cEG8Sam+DOGeDc7/QzpTAT+Bpb+J/raWij1wS2r31dZ8lzzgznMyWIRNcRgv1MqbEX7+8zpbNBrOGcadxN9QR5rfaa/F3rXn6BBxc+QcCDFO0FbeFWU/efK5DMkMqQyJDGkMSQwpDAkL6QvJC6kLiQtpC0kLKQsJCuunA9XU1dmkKSQopCgkJ6QnJCakJiQlpCUkJKQkJCOkIyQipCIkIaQhJCCkICQvpB8kHqQeJB2kHSQcpBwkG6QbJJNHWJBmkGSQYpBgkG6QXJBakFiQVpBUkFKQUJBekEyQSpBIkEaQRJBCkECQTpA8kDqQOJA09yJA2kDDypkS6QLGabukSBNIEkgRSBBIH0gOSA1IDEgLSApICUgISAdIBmhFaERoQ2hCaEFoQGhPaD5oPWg8aDtoOmg5aDhoN2g2ZTbuoaDdoMnt5oMWgwaC9oLmgtaCxoK2gqaCloKGgnaCZoJWgkaCNoImghaCBoH2geaB1oHGgbaBpoGWgYaBdoFntMXaNAm0CTQItAg0B7wHsQrQGNAW0BTQEtAQ3B+XDdGc7DEM8GPAPw4MW/7RbWHHv+PnL9oE87/H/pvv3WpvoPscdkbavYEvfVTnvbYXLcyg8zU6dfW079cD4DfS/q7NXZu39TYW9zPhf9oLr/xAtv/zXV3vY62WNslHdcy0ub7G1O8us+973L/+rWvaO97QyZ+O60qlPDt/zH8c7DsxWZnZNVkLewoCgnY35ufnFn2nDXbOfJ6jUBDU+4tV/w+5cnh7sPGNT+Jtn5dUtT1u/s04j96+PcKGt/91owIvjafoQ7++Dd2cr6OtLaByPJOp7HtW20OG8TrynJ2T+0cfuHtDE3nt85Fn6C4Bqj+bqZmGu/l5pbc9R9NcJ5xHHc98b+PnjJqHhzsculhLI+7QcXjC9dfSnt4PK2L8V+Ghn9Wcmw0it/KXBfS0gDa49oYA0R4nrs++P8m2jc/V+S7JzTWVdzc+P9so8f6prfiWxpnd9ep9c0PD5464v3q1MG5LV27Y/hXDOuM4ZfZ+cW5mQV55bmZNQ+mHLm5RRmLCopKM7NyS927kS4tZdzxGDekc7+tzRu/+tKm3GtxT5u/QnJULGf5yavQ1xsaK7b2y5CbHOO2Ya01+tcx7dZzirpuSsAAA==", debug_symbols: "pZbLjqswDIbfJWsWsXPvq4xGFW2ZERKiFdMe6ajqux+7QwJdJOoJG2Iu/oiN/eO7OHWH2/e+H7/OP2L3cReHqR+G/ns/nI/ttT+PdPUuJB/Aih02Atzv4sVO0RLETjcC6Qn9eDQiuu2vU9ex14pD9Es7deNV7MbbMDTiTzvcng/9XNrxuV7bie7KRnTjiVYCfvVDx9ajWbxl3tVLnJ092uQO7sUf8v5W69nfGlXj7yH6e1/lH4N3Mvv+QvzgpZoB4JVLBPN2BlFCDAGlUhUECEEmgsEcwRUINu0BrDFLHsILwRf34NMeMEsIeYIGMDNBg/E1BFQuEtCZOgJsJaB6g1DMpLfxW4RQQ6AiiE2FgJAjcLpzCGV0TISyUtZsAtClTViV3UShKrUJMQ5t9UpdbCUi5BDF9rQmxbHKxH80OKiQCE7XEKiSIkFBlcgom9pTyxqRQYNJpqzJ5gF1obKlTVpJOVk+hn57EzYRkJS7JgyvU1l6l00lutLX8CmXav3Te61sLDWHx9Sh3mQ7FLfLJW7XS9wumLhdMYvpDDJ1WIBQg1DU21HwqDjrEItmQnBbEZiX3WJ9L7NAWGn/+x2i5JIJuSpvJnzSWXvsp9dpFSxNqlSMYN28+nkNv6uT3PxsABk8xTqMV1S8onmCYsOw6LLB8y+wwRPwcxL23HJsBBYkHoplNIAlgQ3kfbNBZMUPe80/MTaIrPgVnsisyeBdNHw0AhsPTs/Ut4eh4wg5B7fxGAOm0+vfS7wTB/jLdD52p9vUcXJWUzwdP6jbMXw+OIH/AA==", file_map: { "14": { source: "// docs:start:ecdsa_secp256k1\n/// Verifies a ECDSA signature over the secp256k1 curve.\n/// - inputs:\n/// - x coordinate of public key as 32 bytes\n/// - y coordinate of public key as 32 bytes\n/// - the signature, as a 64 bytes array\n/// The signature internally will be represented as `(r, s)`,\n/// where `r` and `s` are fixed-sized big endian scalar values.\n/// As the `secp256k1` has a 256-bit modulus, we have a 64 byte signature\n/// while `r` and `s` will both be 32 bytes.\n/// We expect `s` to be normalized. This means given the curve's order,\n/// `s` should be less than or equal to `order / 2`.\n/// This is done to prevent malleability.\n/// For more context regarding malleability you can reference BIP 0062.\n/// - the hash of the message, as a vector of bytes\n/// - output: false for failure and true for success\npub fn verify_signature(\n public_key_x: [u8; 32],\n public_key_y: [u8; 32],\n signature: [u8; 64],\n message_hash: [u8; 32],\n) -> bool\n// docs:end:ecdsa_secp256k1\n{\n _verify_signature(public_key_x, public_key_y, signature, message_hash, true)\n}\n\n#[foreign(ecdsa_secp256k1)]\npub fn _verify_signature(\n public_key_x: [u8; 32],\n public_key_y: [u8; 32],\n signature: [u8; 64],\n message_hash: [u8; 32],\n predicate: bool,\n) -> bool {}\n", path: "std/ecdsa_secp256k1.nr" }, "16": { source: "use crate::cmp::Eq;\nuse crate::hash::Hash;\nuse crate::ops::arith::{Add, Neg, Sub};\n\n/// A point on the embedded elliptic curve\n/// By definition, the base field of the embedded curve is the scalar field of the proof system curve, i.e the Noir Field.\n/// x and y denotes the Weierstrass coordinates of the point, if is_infinite is false.\npub struct EmbeddedCurvePoint {\n pub x: Field,\n pub y: Field,\n pub is_infinite: bool,\n}\n\nimpl EmbeddedCurvePoint {\n /// Elliptic curve point doubling operation\n /// returns the doubled point of a point P, i.e P+P\n pub fn double(self) -> EmbeddedCurvePoint {\n embedded_curve_add(self, self)\n }\n\n /// Returns the null element of the curve; 'the point at infinity'\n pub fn point_at_infinity() -> EmbeddedCurvePoint {\n EmbeddedCurvePoint { x: 0, y: 0, is_infinite: true }\n }\n\n /// Returns the curve's generator point.\n pub fn generator() -> EmbeddedCurvePoint {\n // Generator point for the grumpkin curve (y^2 = x^3 - 17)\n EmbeddedCurvePoint {\n x: 1,\n y: 17631683881184975370165255887551781615748388533673675138860, // sqrt(-16)\n is_infinite: false,\n }\n }\n}\n\nimpl Add for EmbeddedCurvePoint {\n /// Adds two points P+Q, using the curve addition formula, and also handles point at infinity\n fn add(self, other: EmbeddedCurvePoint) -> EmbeddedCurvePoint {\n embedded_curve_add(self, other)\n }\n}\n\nimpl Sub for EmbeddedCurvePoint {\n /// Points subtraction operation, using addition and negation\n fn sub(self, other: EmbeddedCurvePoint) -> EmbeddedCurvePoint {\n self + other.neg()\n }\n}\n\nimpl Neg for EmbeddedCurvePoint {\n /// Negates a point P, i.e returns -P, by negating the y coordinate.\n /// If the point is at infinity, then the result is also at infinity.\n fn neg(self) -> EmbeddedCurvePoint {\n EmbeddedCurvePoint { x: self.x, y: -self.y, is_infinite: self.is_infinite }\n }\n}\n\nimpl Eq for EmbeddedCurvePoint {\n /// Checks whether two points are equal\n fn eq(self: Self, b: EmbeddedCurvePoint) -> bool {\n (self.is_infinite & b.is_infinite)\n | ((self.is_infinite == b.is_infinite) & (self.x == b.x) & (self.y == b.y))\n }\n}\n\nimpl Hash for EmbeddedCurvePoint {\n fn hash<H>(self, state: &mut H)\n where\n H: crate::hash::Hasher,\n {\n if self.is_infinite {\n self.is_infinite.hash(state);\n } else {\n self.x.hash(state);\n self.y.hash(state);\n }\n }\n}\n\n/// Scalar for the embedded curve represented as low and high limbs\n/// By definition, the scalar field of the embedded curve is base field of the proving system curve.\n/// It may not fit into a Field element, so it is represented with two Field elements; its low and high limbs.\npub struct EmbeddedCurveScalar {\n pub lo: Field,\n pub hi: Field,\n}\n\nimpl EmbeddedCurveScalar {\n pub fn new(lo: Field, hi: Field) -> Self {\n EmbeddedCurveScalar { lo, hi }\n }\n\n #[field(bn254)]\n pub fn from_field(scalar: Field) -> EmbeddedCurveScalar {\n let (a, b) = crate::field::bn254::decompose(scalar);\n EmbeddedCurveScalar { lo: a, hi: b }\n }\n\n //Bytes to scalar: take the first (after the specified offset) 16 bytes of the input as the lo value, and the next 16 bytes as the hi value\n #[field(bn254)]\n pub(crate) fn from_bytes(bytes: [u8; 64], offset: u32) -> EmbeddedCurveScalar {\n let mut v = 1;\n let mut lo = 0 as Field;\n let mut hi = 0 as Field;\n for i in 0..16 {\n lo = lo + (bytes[offset + 31 - i] as Field) * v;\n hi = hi + (bytes[offset + 15 - i] as Field) * v;\n v = v * 256;\n }\n let sig_s = crate::embedded_curve_ops::EmbeddedCurveScalar { lo, hi };\n sig_s\n }\n}\n\nimpl Eq for EmbeddedCurveScalar {\n fn eq(self, other: Self) -> bool {\n (other.hi == self.hi) & (other.lo == self.lo)\n }\n}\n\nimpl Hash for EmbeddedCurveScalar {\n fn hash<H>(self, state: &mut H)\n where\n H: crate::hash::Hasher,\n {\n self.hi.hash(state);\n self.lo.hash(state);\n }\n}\n\n// Computes a multi scalar multiplication over the embedded curve.\n// For bn254, We have Grumpkin and Baby JubJub.\n// For bls12-381, we have JubJub and Bandersnatch.\n//\n// The embedded curve being used is decided by the\n// underlying proof system.\n// docs:start:multi_scalar_mul\npub fn multi_scalar_mul<let N: u32>(\n points: [EmbeddedCurvePoint; N],\n scalars: [EmbeddedCurveScalar; N],\n) -> EmbeddedCurvePoint\n// docs:end:multi_scalar_mul\n{\n multi_scalar_mul_array_return(points, scalars, true)[0]\n}\n\n#[foreign(multi_scalar_mul)]\npub(crate) fn multi_scalar_mul_array_return<let N: u32>(\n points: [EmbeddedCurvePoint; N],\n scalars: [EmbeddedCurveScalar; N],\n predicate: bool,\n) -> [EmbeddedCurvePoint; 1] {}\n\n// docs:start:fixed_base_scalar_mul\npub fn fixed_base_scalar_mul(scalar: EmbeddedCurveScalar) -> EmbeddedCurvePoint\n// docs:end:fixed_base_scalar_mul\n{\n multi_scalar_mul([EmbeddedCurvePoint::generator()], [scalar])\n}\n\n/// This function only assumes that the points are on the curve\n/// It handles corner cases around the infinity point causing some overhead compared to embedded_curve_add_not_nul and embedded_curve_add_unsafe\n// docs:start:embedded_curve_add\npub fn embedded_curve_add(\n point1: EmbeddedCurvePoint,\n point2: EmbeddedCurvePoint,\n) -> EmbeddedCurvePoint {\n // docs:end:embedded_curve_add\n if crate::runtime::is_unconstrained() {\n // `embedded_curve_add_unsafe` requires the inputs not to be the infinity point, so we check it here.\n // This is because `embedded_curve_add_unsafe` uses the `embedded_curve_add` opcode.\n // For efficiency, the backend does not check the inputs for the infinity point, but it assumes that they are not the infinity point\n // so that it can apply the ec addition formula directly.\n if point1.is_infinite {\n point2\n } else if point2.is_infinite {\n point1\n } else {\n embedded_curve_add_unsafe(point1, point2)\n }\n } else {\n // In a constrained context, we also need to check the inputs are not the infinity point because we also use `embedded_curve_add_unsafe`\n // However we also need to identify the case where the two inputs are the same, because then\n // the addition formula does not work and we need to use the doubling formula instead.\n // In unconstrained context, we can check directly if the input values are the same when solving the opcode, so it is not an issue.\n\n // x_coordinates_match is true if both abscissae are the same\n let x_coordinates_match = point1.x == point2.x;\n // y_coordinates_match is true if both ordinates are the same\n let y_coordinates_match = point1.y == point2.y;\n // double_predicate is true if both abscissae and ordinates are the same\n let double_predicate = (x_coordinates_match & y_coordinates_match);\n // If the abscissae are the same, but not the ordinates, then one point is the opposite of the other\n let infinity_predicate = (x_coordinates_match & !y_coordinates_match);\n\n // `embedded_curve_add_unsafe` would not perform doubling, even if the inputs point1 and point2 are the same, because it cannot know this without adding some logic (and some constraints)\n // However we did this logic when we computed `double_predicate`, so we set the result to 2*point1 if point1 and point2 are the same\n let mut result = if double_predicate {\n // `embedded_curve_add_unsafe` is doing a doubling if the input is the same variable, because in this case it is guaranteed (at 'compile time') that the input is the same.\n embedded_curve_add_unsafe(point1, point1)\n } else {\n let point1_1 = EmbeddedCurvePoint {\n x: point1.x + (x_coordinates_match as Field),\n y: point1.y,\n is_infinite: false,\n };\n let point2_1 = EmbeddedCurvePoint { x: point2.x, y: point2.y, is_infinite: false };\n // point1_1 is guaranteed to have a different abscissa than point2:\n // - if x_coordinates_match is 0, that means point1.x != point2.x, and point1_1.x = point1.x + 0\n // - if x_coordinates_match is 1, that means point1.x = point2.x, but point1_1.x = point1.x + 1 in this case\n // Because the abscissa is different, the addition formula is guaranteed to succeed, so we can safely use `embedded_curve_add_unsafe`\n // Note that this computation may be garbage: if x_coordinates_match is 1, or if one of the input is the point at infinity.\n // therefore we only want to do this if we need the result, otherwise it needs to be eliminated as a dead instruction, lest we want the circuit to fail.\n embedded_curve_add_unsafe(point1_1, point2_1)\n };\n\n // Same logic as above for unconstrained context, we set the proper result when one of the inputs is the infinity point\n if point1.is_infinite {\n result = point2;\n }\n if point2.is_infinite {\n result = point1;\n }\n\n // Finally, we set the is_infinity flag of the result:\n // Opposite points should sum into the infinity point, however, if one of them is point at infinity, their coordinates are not meaningful\n // so we should not use the fact that the inputs are opposite in this case:\n let mut result_is_infinity =\n infinity_predicate & (!point1.is_infinite & !point2.is_infinite);\n // However, if both of them are at infinity, then the result is also at infinity\n result.is_infinite = result_is_infinity | (point1.is_infinite & point2.is_infinite);\n result\n }\n}\n\n#[foreign(embedded_curve_add)]\nfn embedded_curve_add_array_return(\n _point1: EmbeddedCurvePoint,\n _point2: EmbeddedCurvePoint,\n _predicate: bool,\n) -> [EmbeddedCurvePoint; 1] {}\n\n/// This function assumes that:\n/// The points are on the curve, and\n/// The points don't share an x-coordinate, and\n/// Neither point is the infinity point.\n/// If it is used with correct input, the function ensures the correct non-zero result is returned.\n/// Except for points on the curve, the other assumptions are checked by the function. It will cause assertion failure if they are not respected.\npub fn embedded_curve_add_not_nul(\n point1: EmbeddedCurvePoint,\n point2: EmbeddedCurvePoint,\n) -> EmbeddedCurvePoint {\n assert(point1.x != point2.x);\n assert(!point1.is_infinite);\n assert(!point2.is_infinite);\n // Ensure is_infinite is comptime\n let point1_1 = EmbeddedCurvePoint { x: point1.x, y: point1.y, is_infinite: false };\n let point2_1 = EmbeddedCurvePoint { x: point2.x, y: point2.y, is_infinite: false };\n embedded_curve_add_unsafe(point1_1, point2_1)\n}\n\n/// Unsafe ec addition\n/// If the inputs are the same, it will perform a doubling, but only if point1 and point2 are the same variable.\n/// If they have the same value but are different variables, the result will be incorrect because in this case\n/// it assumes (but does not check) that the points' x-coordinates are not equal.\n/// It also assumes neither point is the infinity point.\npub fn embedded_curve_add_unsafe(\n point1: EmbeddedCurvePoint,\n point2: EmbeddedCurvePoint,\n) -> EmbeddedCurvePoint {\n embedded_curve_add_array_return(point1, point2, true)[0]\n}\n", path: "std/embedded_curve_ops.nr" }, "17": { source: `use crate::field::field_less_than;
3926
- use crate::runtime::is_unconstrained;
3927
-
3928
- // The low and high decomposition of the field modulus
3929
- global PLO: Field = 53438638232309528389504892708671455233;
3930
- global PHI: Field = 64323764613183177041862057485226039389;
3931
-
3932
- pub(crate) global TWO_POW_128: Field = 0x100000000000000000000000000000000;
3933
-
3934
- // Decomposes a single field into two 16 byte fields.
3935
- fn compute_decomposition(x: Field) -> (Field, Field) {
3936
- // Here's we're taking advantage of truncating 128 bit limbs from the input field
3937
- // and then subtracting them from the input such the field division is equivalent to integer division.
3938
- let low = (x as u128) as Field;
3939
- let high = (x - low) / TWO_POW_128;
3940
-
3941
- (low, high)
3942
- }
3943
-
3944
- pub(crate) unconstrained fn decompose_hint(x: Field) -> (Field, Field) {
3945
- compute_decomposition(x)
3946
- }
3947
-
3948
- unconstrained fn lte_hint(x: Field, y: Field) -> bool {
3949
- if x == y {
3950
- true
3951
- } else {
3952
- field_less_than(x, y)
3953
- }
3954
- }
3955
-
3956
- // Assert that (alo > blo && ahi >= bhi) || (alo <= blo && ahi > bhi)
3957
- fn assert_gt_limbs(a: (Field, Field), b: (Field, Field)) {
3958
- let (alo, ahi) = a;
3959
- let (blo, bhi) = b;
3960
- // Safety: borrow is enforced to be boolean due to its type.
3961
- // if borrow is 0, it asserts that (alo > blo && ahi >= bhi)
3962
- // if borrow is 1, it asserts that (alo <= blo && ahi > bhi)
3963
- unsafe {
3964
- let borrow = lte_hint(alo, blo);
3965
-
3966
- let rlo = alo - blo - 1 + (borrow as Field) * TWO_POW_128;
3967
- let rhi = ahi - bhi - (borrow as Field);
3968
-
3969
- rlo.assert_max_bit_size::<128>();
3970
- rhi.assert_max_bit_size::<128>();
3971
- }
3972
- }
3973
-
3974
- /// Decompose a single field into two 16 byte fields.
3975
- pub fn decompose(x: Field) -> (Field, Field) {
3976
- if is_unconstrained() {
3977
- compute_decomposition(x)
3978
- } else {
3979
- // Safety: decomposition is properly checked below
3980
- unsafe {
3981
- // Take hints of the decomposition
3982
- let (xlo, xhi) = decompose_hint(x);
3983
-
3984
- // Range check the limbs
3985
- xlo.assert_max_bit_size::<128>();
3986
- xhi.assert_max_bit_size::<128>();
3987
-
3988
- // Check that the decomposition is correct
3989
- assert_eq(x, xlo + TWO_POW_128 * xhi);
3990
-
3991
- // Assert that the decomposition of P is greater than the decomposition of x
3992
- assert_gt_limbs((PLO, PHI), (xlo, xhi));
3993
- (xlo, xhi)
3994
- }
3995
- }
3996
- }
3997
-
3998
- pub fn assert_gt(a: Field, b: Field) {
3999
- if is_unconstrained() {
4000
- assert(
4001
- // Safety: already unconstrained
4002
- unsafe { field_less_than(b, a) },
4003
- );
4004
- } else {
4005
- // Decompose a and b
4006
- let a_limbs = decompose(a);
4007
- let b_limbs = decompose(b);
4008
-
4009
- // Assert that a_limbs is greater than b_limbs
4010
- assert_gt_limbs(a_limbs, b_limbs)
4011
- }
4012
- }
4013
-
4014
- pub fn assert_lt(a: Field, b: Field) {
4015
- assert_gt(b, a);
4016
- }
4017
-
4018
- pub fn gt(a: Field, b: Field) -> bool {
4019
- if is_unconstrained() {
4020
- // Safety: unsafe in unconstrained
4021
- unsafe {
4022
- field_less_than(b, a)
4023
- }
4024
- } else if a == b {
4025
- false
4026
- } else {
4027
- // Safety: Take a hint of the comparison and verify it
4028
- unsafe {
4029
- if field_less_than(a, b) {
4030
- assert_gt(b, a);
4031
- false
4032
- } else {
4033
- assert_gt(a, b);
4034
- true
4035
- }
4036
- }
4037
- }
4038
- }
4039
-
4040
- pub fn lt(a: Field, b: Field) -> bool {
4041
- gt(b, a)
4042
- }
4043
-
4044
- mod tests {
4045
- // TODO: Allow imports from "super"
4046
- use crate::field::bn254::{assert_gt, decompose, gt, lt, lte_hint, PHI, PLO, TWO_POW_128};
4047
-
4048
- #[test]
4049
- fn check_decompose() {
4050
- assert_eq(decompose(TWO_POW_128), (0, 1));
4051
- assert_eq(decompose(TWO_POW_128 + 0x1234567890), (0x1234567890, 1));
4052
- assert_eq(decompose(0x1234567890), (0x1234567890, 0));
4053
- }
4054
-
4055
- #[test]
4056
- unconstrained fn check_lte_hint() {
4057
- assert(lte_hint(0, 1));
4058
- assert(lte_hint(0, 0x100));
4059
- assert(lte_hint(0x100, TWO_POW_128 - 1));
4060
- assert(!lte_hint(0 - 1, 0));
4061
-
4062
- assert(lte_hint(0, 0));
4063
- assert(lte_hint(0x100, 0x100));
4064
- assert(lte_hint(0 - 1, 0 - 1));
4065
- }
4066
-
4067
- #[test]
4068
- fn check_gt() {
4069
- assert(gt(1, 0));
4070
- assert(gt(0x100, 0));
4071
- assert(gt((0 - 1), (0 - 2)));
4072
- assert(gt(TWO_POW_128, 0));
4073
- assert(!gt(0, 0));
4074
- assert(!gt(0, 0x100));
4075
- assert(gt(0 - 1, 0 - 2));
4076
- assert(!gt(0 - 2, 0 - 1));
4077
- assert_gt(0 - 1, 0);
4078
- }
4079
-
4080
- #[test]
4081
- fn check_plo_phi() {
4082
- assert_eq(PLO + PHI * TWO_POW_128, 0);
4083
- let p_bytes = crate::field::modulus_le_bytes();
4084
- let mut p_low: Field = 0;
4085
- let mut p_high: Field = 0;
4086
-
4087
- let mut offset = 1;
4088
- for i in 0..16 {
4089
- p_low += (p_bytes[i] as Field) * offset;
4090
- p_high += (p_bytes[i + 16] as Field) * offset;
4091
- offset *= 256;
4092
- }
4093
- assert_eq(p_low, PLO);
4094
- assert_eq(p_high, PHI);
4095
- }
4096
-
4097
- #[test]
4098
- fn check_decompose_edge_cases() {
4099
- assert_eq(decompose(0), (0, 0));
4100
- assert_eq(decompose(TWO_POW_128 - 1), (TWO_POW_128 - 1, 0));
4101
- assert_eq(decompose(TWO_POW_128 + 1), (1, 1));
4102
- assert_eq(decompose(TWO_POW_128 * 2), (0, 2));
4103
- assert_eq(decompose(TWO_POW_128 * 2 + 0x1234567890), (0x1234567890, 2));
4104
- }
4105
-
4106
- #[test]
4107
- fn check_decompose_large_values() {
4108
- let large_field = 0xffffffffffffffff;
4109
- let (lo, hi) = decompose(large_field);
4110
- assert_eq(large_field, lo + TWO_POW_128 * hi);
4111
-
4112
- let large_value = large_field - TWO_POW_128;
4113
- let (lo2, hi2) = decompose(large_value);
4114
- assert_eq(large_value, lo2 + TWO_POW_128 * hi2);
4115
- }
4116
-
4117
- #[test]
4118
- fn check_lt_comprehensive() {
4119
- assert(lt(0, 1));
4120
- assert(!lt(1, 0));
4121
- assert(!lt(0, 0));
4122
- assert(!lt(42, 42));
4123
-
4124
- assert(lt(TWO_POW_128 - 1, TWO_POW_128));
4125
- assert(!lt(TWO_POW_128, TWO_POW_128 - 1));
4126
- }
4127
- }
4128
- `, path: "std/field/bn254.nr" }, "19": { source: '// Exposed only for usage in `std::meta`\npub(crate) mod poseidon2;\n\nuse crate::default::Default;\nuse crate::embedded_curve_ops::{\n EmbeddedCurvePoint, EmbeddedCurveScalar, multi_scalar_mul, multi_scalar_mul_array_return,\n};\nuse crate::meta::derive_via;\n\n#[foreign(sha256_compression)]\n// docs:start:sha256_compression\npub fn sha256_compression(input: [u32; 16], state: [u32; 8]) -> [u32; 8] {}\n// docs:end:sha256_compression\n\n#[foreign(keccakf1600)]\n// docs:start:keccakf1600\npub fn keccakf1600(input: [u64; 25]) -> [u64; 25] {}\n// docs:end:keccakf1600\n\npub mod keccak {\n #[deprecated("This function has been moved to std::hash::keccakf1600")]\n pub fn keccakf1600(input: [u64; 25]) -> [u64; 25] {\n super::keccakf1600(input)\n }\n}\n\n#[foreign(blake2s)]\n// docs:start:blake2s\npub fn blake2s<let N: u32>(input: [u8; N]) -> [u8; 32]\n// docs:end:blake2s\n{}\n\n// docs:start:blake3\npub fn blake3<let N: u32>(input: [u8; N]) -> [u8; 32]\n// docs:end:blake3\n{\n if crate::runtime::is_unconstrained() {\n // Temporary measure while Barretenberg is main proving system.\n // Please open an issue if you\'re working on another proving system and running into problems due to this.\n crate::static_assert(\n N <= 1024,\n "Barretenberg cannot prove blake3 hashes with inputs larger than 1024 bytes",\n );\n }\n __blake3(input)\n}\n\n#[foreign(blake3)]\nfn __blake3<let N: u32>(input: [u8; N]) -> [u8; 32] {}\n\n// docs:start:pedersen_commitment\npub fn pedersen_commitment<let N: u32>(input: [Field; N]) -> EmbeddedCurvePoint {\n // docs:end:pedersen_commitment\n pedersen_commitment_with_separator(input, 0)\n}\n\n#[inline_always]\npub fn pedersen_commitment_with_separator<let N: u32>(\n input: [Field; N],\n separator: u32,\n) -> EmbeddedCurvePoint {\n let mut points = [EmbeddedCurveScalar { lo: 0, hi: 0 }; N];\n for i in 0..N {\n // we use the unsafe version because the multi_scalar_mul will constrain the scalars.\n points[i] = from_field_unsafe(input[i]);\n }\n let generators = derive_generators("DEFAULT_DOMAIN_SEPARATOR".as_bytes(), separator);\n multi_scalar_mul(generators, points)\n}\n\n// docs:start:pedersen_hash\npub fn pedersen_hash<let N: u32>(input: [Field; N]) -> Field\n// docs:end:pedersen_hash\n{\n pedersen_hash_with_separator(input, 0)\n}\n\n#[no_predicates]\npub fn pedersen_hash_with_separator<let N: u32>(input: [Field; N], separator: u32) -> Field {\n let mut scalars: [EmbeddedCurveScalar; N + 1] = [EmbeddedCurveScalar { lo: 0, hi: 0 }; N + 1];\n let mut generators: [EmbeddedCurvePoint; N + 1] =\n [EmbeddedCurvePoint::point_at_infinity(); N + 1];\n let domain_generators: [EmbeddedCurvePoint; N] =\n derive_generators("DEFAULT_DOMAIN_SEPARATOR".as_bytes(), separator);\n\n for i in 0..N {\n scalars[i] = from_field_unsafe(input[i]);\n generators[i] = domain_generators[i];\n }\n scalars[N] = EmbeddedCurveScalar { lo: N as Field, hi: 0 as Field };\n\n let length_generator: [EmbeddedCurvePoint; 1] =\n derive_generators("pedersen_hash_length".as_bytes(), 0);\n generators[N] = length_generator[0];\n multi_scalar_mul_array_return(generators, scalars, true)[0].x\n}\n\n#[field(bn254)]\n#[inline_always]\npub fn derive_generators<let N: u32, let M: u32>(\n domain_separator_bytes: [u8; M],\n starting_index: u32,\n) -> [EmbeddedCurvePoint; N] {\n crate::assert_constant(domain_separator_bytes);\n // TODO(https://github.com/noir-lang/noir/issues/5672): Add back assert_constant on starting_index\n __derive_generators(domain_separator_bytes, starting_index)\n}\n\n#[builtin(derive_pedersen_generators)]\n#[field(bn254)]\nfn __derive_generators<let N: u32, let M: u32>(\n domain_separator_bytes: [u8; M],\n starting_index: u32,\n) -> [EmbeddedCurvePoint; N] {}\n\n#[field(bn254)]\n// Same as from_field but:\n// does not assert the limbs are 128 bits\n// does not assert the decomposition does not overflow the EmbeddedCurveScalar\nfn from_field_unsafe(scalar: Field) -> EmbeddedCurveScalar {\n // Safety: xlo and xhi decomposition is checked below\n let (xlo, xhi) = unsafe { crate::field::bn254::decompose_hint(scalar) };\n // Check that the decomposition is correct\n assert_eq(scalar, xlo + crate::field::bn254::TWO_POW_128 * xhi);\n EmbeddedCurveScalar { lo: xlo, hi: xhi }\n}\n\npub fn poseidon2_permutation<let N: u32>(input: [Field; N], state_len: u32) -> [Field; N] {\n assert_eq(input.len(), state_len);\n poseidon2_permutation_internal(input)\n}\n\n#[foreign(poseidon2_permutation)]\nfn poseidon2_permutation_internal<let N: u32>(input: [Field; N]) -> [Field; N] {}\n\n// Generic hashing support.\n// Partially ported and impacted by rust.\n\n// Hash trait shall be implemented per type.\n#[derive_via(derive_hash)]\npub trait Hash {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher;\n}\n\n// docs:start:derive_hash\ncomptime fn derive_hash(s: TypeDefinition) -> Quoted {\n let name = quote { $crate::hash::Hash };\n let signature = quote { fn hash<H>(_self: Self, _state: &mut H) where H: $crate::hash::Hasher };\n let for_each_field = |name| quote { _self.$name.hash(_state); };\n crate::meta::make_trait_impl(\n s,\n name,\n signature,\n for_each_field,\n quote {},\n |fields| fields,\n )\n}\n// docs:end:derive_hash\n\n// Hasher trait shall be implemented by algorithms to provide hash-agnostic means.\n// TODO: consider making the types generic here ([u8], [Field], etc.)\npub trait Hasher {\n fn finish(self) -> Field;\n\n fn write(&mut self, input: Field);\n}\n\n// BuildHasher is a factory trait, responsible for production of specific Hasher.\npub trait BuildHasher {\n type H: Hasher;\n\n fn build_hasher(self) -> H;\n}\n\npub struct BuildHasherDefault<H>;\n\nimpl<H> BuildHasher for BuildHasherDefault<H>\nwhere\n H: Hasher + Default,\n{\n type H = H;\n\n fn build_hasher(_self: Self) -> H {\n H::default()\n }\n}\n\nimpl<H> Default for BuildHasherDefault<H>\nwhere\n H: Hasher + Default,\n{\n fn default() -> Self {\n BuildHasherDefault {}\n }\n}\n\nimpl Hash for Field {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self);\n }\n}\n\nimpl Hash for u1 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for u8 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for u16 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for u32 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for u64 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for u128 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for i8 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as u8 as Field);\n }\n}\n\nimpl Hash for i16 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as u16 as Field);\n }\n}\n\nimpl Hash for i32 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as u32 as Field);\n }\n}\n\nimpl Hash for i64 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as u64 as Field);\n }\n}\n\nimpl Hash for bool {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for () {\n fn hash<H>(_self: Self, _state: &mut H)\n where\n H: Hasher,\n {}\n}\n\nimpl<T, let N: u32> Hash for [T; N]\nwhere\n T: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n for elem in self {\n elem.hash(state);\n }\n }\n}\n\nimpl<T> Hash for [T]\nwhere\n T: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n self.len().hash(state);\n for elem in self {\n elem.hash(state);\n }\n }\n}\n\nimpl<A, B> Hash for (A, B)\nwhere\n A: Hash,\n B: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n self.0.hash(state);\n self.1.hash(state);\n }\n}\n\nimpl<A, B, C> Hash for (A, B, C)\nwhere\n A: Hash,\n B: Hash,\n C: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n self.0.hash(state);\n self.1.hash(state);\n self.2.hash(state);\n }\n}\n\nimpl<A, B, C, D> Hash for (A, B, C, D)\nwhere\n A: Hash,\n B: Hash,\n C: Hash,\n D: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n self.0.hash(state);\n self.1.hash(state);\n self.2.hash(state);\n self.3.hash(state);\n }\n}\n\nimpl<A, B, C, D, E> Hash for (A, B, C, D, E)\nwhere\n A: Hash,\n B: Hash,\n C: Hash,\n D: Hash,\n E: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n self.0.hash(state);\n self.1.hash(state);\n self.2.hash(state);\n self.3.hash(state);\n self.4.hash(state);\n }\n}\n\n// Some test vectors for Pedersen hash and Pedersen Commitment.\n// They have been generated using the same functions so the tests are for now useless\n// but they will be useful when we switch to Noir implementation.\n#[test]\nfn assert_pedersen() {\n assert_eq(\n pedersen_hash_with_separator([1], 1),\n 0x1b3f4b1a83092a13d8d1a59f7acb62aba15e7002f4440f2275edb99ebbc2305f,\n );\n assert_eq(\n pedersen_commitment_with_separator([1], 1),\n EmbeddedCurvePoint {\n x: 0x054aa86a73cb8a34525e5bbed6e43ba1198e860f5f3950268f71df4591bde402,\n y: 0x209dcfbf2cfb57f9f6046f44d71ac6faf87254afc7407c04eb621a6287cac126,\n is_infinite: false,\n },\n );\n\n assert_eq(\n pedersen_hash_with_separator([1, 2], 2),\n 0x26691c129448e9ace0c66d11f0a16d9014a9e8498ee78f4d69f0083168188255,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2], 2),\n EmbeddedCurvePoint {\n x: 0x2e2b3b191e49541fe468ec6877721d445dcaffe41728df0a0eafeb15e87b0753,\n y: 0x2ff4482400ad3a6228be17a2af33e2bcdf41be04795f9782bd96efe7e24f8778,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3], 3),\n 0x0bc694b7a1f8d10d2d8987d07433f26bd616a2d351bc79a3c540d85b6206dbe4,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3], 3),\n EmbeddedCurvePoint {\n x: 0x1fee4e8cf8d2f527caa2684236b07c4b1bad7342c01b0f75e9a877a71827dc85,\n y: 0x2f9fedb9a090697ab69bf04c8bc15f7385b3e4b68c849c1536e5ae15ff138fd1,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4], 4),\n 0xdae10fb32a8408521803905981a2b300d6a35e40e798743e9322b223a5eddc,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4], 4),\n EmbeddedCurvePoint {\n x: 0x07ae3e202811e1fca39c2d81eabe6f79183978e6f12be0d3b8eda095b79bdbc9,\n y: 0x0afc6f892593db6fbba60f2da558517e279e0ae04f95758587760ba193145014,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5], 5),\n 0xfc375b062c4f4f0150f7100dfb8d9b72a6d28582dd9512390b0497cdad9c22,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5], 5),\n EmbeddedCurvePoint {\n x: 0x1754b12bd475a6984a1094b5109eeca9838f4f81ac89c5f0a41dbce53189bb29,\n y: 0x2da030e3cfcdc7ddad80eaf2599df6692cae0717d4e9f7bfbee8d073d5d278f7,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5, 6], 6),\n 0x1696ed13dc2730062a98ac9d8f9de0661bb98829c7582f699d0273b18c86a572,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5, 6], 6),\n EmbeddedCurvePoint {\n x: 0x190f6c0e97ad83e1e28da22a98aae156da083c5a4100e929b77e750d3106a697,\n y: 0x1f4b60f34ef91221a0b49756fa0705da93311a61af73d37a0c458877706616fb,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5, 6, 7], 7),\n 0x128c0ff144fc66b6cb60eeac8a38e23da52992fc427b92397a7dffd71c45ede3,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5, 6, 7], 7),\n EmbeddedCurvePoint {\n x: 0x015441e9d29491b06563fac16fc76abf7a9534c715421d0de85d20dbe2965939,\n y: 0x1d2575b0276f4e9087e6e07c2cb75aa1baafad127af4be5918ef8a2ef2fea8fc,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5, 6, 7, 8], 8),\n 0x2f960e117482044dfc99d12fece2ef6862fba9242be4846c7c9a3e854325a55c,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5, 6, 7, 8], 8),\n EmbeddedCurvePoint {\n x: 0x1657737676968887fceb6dd516382ea13b3a2c557f509811cd86d5d1199bc443,\n y: 0x1f39f0cb569040105fa1e2f156521e8b8e08261e635a2b210bdc94e8d6d65f77,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5, 6, 7, 8, 9], 9),\n 0x0c96db0790602dcb166cc4699e2d306c479a76926b81c2cb2aaa92d249ec7be7,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5, 6, 7, 8, 9], 9),\n EmbeddedCurvePoint {\n x: 0x0a3ceae42d14914a432aa60ec7fded4af7dad7dd4acdbf2908452675ec67e06d,\n y: 0xfc19761eaaf621ad4aec9a8b2e84a4eceffdba78f60f8b9391b0bd9345a2f2,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 10),\n 0x2cd37505871bc460a62ea1e63c7fe51149df5d0801302cf1cbc48beb8dff7e94,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 10),\n EmbeddedCurvePoint {\n x: 0x2fb3f8b3d41ddde007c8c3c62550f9a9380ee546fcc639ffbb3fd30c8d8de30c,\n y: 0x300783be23c446b11a4c0fabf6c91af148937cea15fcf5fb054abf7f752ee245,\n is_infinite: false,\n },\n );\n}\n', path: "std/hash/mod.nr" }, "50": { source: `/// Fulfillment Proof Circuit
4129
- ///
4130
- /// Proves: "The solver correctly executed the intent and delivered
4131
- /// the required output to the recipient, without revealing execution
4132
- /// path, liquidity sources, or intermediate transactions."
4133
- ///
4134
- /// @see docs/specs/FULFILLMENT-PROOF.md
4135
-
4136
- use std::hash::pedersen_hash;
4137
- use std::hash::pedersen_commitment;
4138
- use std::ecdsa_secp256k1::verify_signature;
4139
-
4140
- // --- Main Circuit ---
4141
-
4142
- /// Main fulfillment proof entry point
4143
- ///
4144
- /// Public inputs: intent_hash, output_commitment, recipient_stealth,
4145
- /// min_output_amount, solver_id, fulfillment_time, expiry
4146
- /// Private inputs: output_amount, output_blinding, attestation data, solver_secret
4147
- ///
4148
- /// Constraints:
4149
- /// 1. output_amount >= min_output_amount (range proof via u64)
4150
- /// 2. output_commitment = Pedersen(output_amount, output_blinding)
4151
- /// 3. Oracle attestation is valid and matches claimed values
4152
- /// 4. Solver is authorized (solver_id derived from solver_secret)
4153
- /// 5. fulfillment_time <= expiry
4154
- pub fn main(
4155
- // Public inputs
4156
- intent_hash: pub Field,
4157
- output_commitment_x: pub Field,
4158
- output_commitment_y: pub Field,
4159
- recipient_stealth: pub Field,
4160
- min_output_amount: pub u64,
4161
- solver_id: pub Field,
4162
- fulfillment_time: pub u64,
4163
- expiry: pub u64,
4164
-
4165
- // Private inputs
4166
- output_amount: u64,
4167
- output_blinding: Field,
4168
- solver_secret: Field,
4169
-
4170
- // Oracle attestation (private)
4171
- attestation_recipient: Field,
4172
- attestation_amount: u64,
4173
- attestation_tx_hash: Field,
4174
- attestation_block: u64,
4175
- oracle_signature: [u8; 64],
4176
- oracle_message_hash: [u8; 32],
4177
- oracle_pub_key_x: [u8; 32],
4178
- oracle_pub_key_y: [u8; 32],
4179
- ) {
4180
- // Constraint 1: Output meets minimum requirement
4181
- // Range proof is implicit via u64 type comparison
4182
- assert(output_amount >= min_output_amount, "Output below minimum");
4183
-
4184
- // Constraint 2: Output commitment is valid
4185
- // C = Pedersen(output_amount, output_blinding)
4186
- let commitment = pedersen_commitment([output_amount as Field, output_blinding]);
4187
- assert(commitment.x == output_commitment_x, "Commitment X mismatch");
4188
- assert(commitment.y == output_commitment_y, "Commitment Y mismatch");
4189
-
4190
- // Constraint 3a: Attestation matches claimed values
4191
- assert(attestation_recipient == recipient_stealth, "Recipient mismatch in attestation");
4192
- assert(attestation_amount == output_amount, "Amount mismatch in attestation");
4193
-
4194
- // Constraint 3b: Oracle signature is valid
4195
- let valid_attestation = verify_signature(
4196
- oracle_pub_key_x,
4197
- oracle_pub_key_y,
4198
- oracle_signature,
4199
- oracle_message_hash
4200
- );
4201
- assert(valid_attestation, "Invalid oracle attestation signature");
4202
-
4203
- // Constraint 4: Solver authorization
4204
- // solver_id = pedersen_hash(solver_secret)
4205
- let computed_solver_id = pedersen_hash([solver_secret]);
4206
- assert(computed_solver_id == solver_id, "Unauthorized solver");
4207
-
4208
- // Constraint 5: Time constraint
4209
- assert(fulfillment_time <= expiry, "Fulfillment after expiry");
4210
-
4211
- // Intent hash binding (ensures this proof is for this specific intent)
4212
- // The intent_hash is a public input, binding this proof to the intent
4213
- // No additional constraint needed - it's enforced by the verifier checking public inputs
4214
- let _ = intent_hash;
4215
-
4216
- // Attestation metadata (tx_hash and block) are included for auditability
4217
- // but not strictly constrained in circuit (oracle signature covers them)
4218
- let _ = attestation_tx_hash;
4219
- let _ = attestation_block;
4220
- }
4221
-
4222
- // --- Tests ---
4223
-
4224
- #[test]
4225
- fn test_output_commitment() {
4226
- // Test that commitment is correctly computed
4227
- let output_amount: u64 = 1000000;
4228
- let output_blinding: Field = 0x123456789;
4229
-
4230
- let commitment1 = pedersen_commitment([output_amount as Field, output_blinding]);
4231
- let commitment2 = pedersen_commitment([output_amount as Field, output_blinding]);
4232
-
4233
- // Commitment should be deterministic
4234
- assert(commitment1.x == commitment2.x, "Commitment X should be deterministic");
4235
- assert(commitment1.y == commitment2.y, "Commitment Y should be deterministic");
4236
- }
4237
-
4238
- #[test]
4239
- fn test_solver_authorization() {
4240
- // Test solver_id derivation
4241
- let solver_secret: Field = 0x1234567890ABCDEF;
4242
-
4243
- let solver_id1 = pedersen_hash([solver_secret]);
4244
- let solver_id2 = pedersen_hash([solver_secret]);
4245
-
4246
- // Solver ID should be deterministic
4247
- assert(solver_id1 == solver_id2, "Solver ID should be deterministic");
4248
-
4249
- // Different secret should give different solver_id
4250
- let different_secret: Field = 0xFEDCBA0987654321;
4251
- let different_id = pedersen_hash([different_secret]);
4252
- assert(solver_id1 != different_id, "Different secrets should give different solver IDs");
4253
- }
4254
-
4255
- #[test]
4256
- fn test_range_proof_passes() {
4257
- // Test that output >= min passes
4258
- let output_amount: u64 = 1050000;
4259
- let min_output_amount: u64 = 1000000;
4260
-
4261
- assert(output_amount >= min_output_amount, "Output should be >= minimum");
4262
- }
4263
-
4264
- #[test]
4265
- fn test_time_constraint_valid() {
4266
- // Test valid time constraint
4267
- let fulfillment_time: u64 = 1732650000;
4268
- let expiry: u64 = 1732686400;
4269
-
4270
- assert(fulfillment_time <= expiry, "Fulfillment time should be <= expiry");
4271
- }
4272
-
4273
- #[test]
4274
- fn test_time_constraint_edge_case() {
4275
- // Edge case: exactly at expiry should be valid
4276
- let fulfillment_time: u64 = 1732686400;
4277
- let expiry: u64 = 1732686400;
4278
-
4279
- assert(fulfillment_time <= expiry, "Fulfillment at exactly expiry should be valid");
4280
- }
4281
-
4282
- // NOTE: Full integration tests with ECDSA oracle signatures require TypeScript SDK
4283
- // The NoirProofProvider will generate valid oracle signature test vectors
4284
- `, path: "/Users/rz/local-dev/sip-protocol/packages/circuits/fulfillment_proof/src/main.nr" } }, expression_width: { Bounded: { width: 4 } } };
4285
-
4286
- // src/proofs/noir.ts
4287
- var NoirProofProvider = class {
4288
- framework = "noir";
4289
- _isReady = false;
4290
- config;
4291
- // Circuit instances
4292
- fundingNoir = null;
4293
- fundingBackend = null;
4294
- validityNoir = null;
4295
- validityBackend = null;
4296
- fulfillmentNoir = null;
4297
- fulfillmentBackend = null;
4298
- constructor(config = {}) {
4299
- this.config = {
4300
- backend: "barretenberg",
4301
- verbose: false,
4302
- ...config
4303
- };
4304
- }
4305
- get isReady() {
4306
- return this._isReady;
4307
- }
4308
- /**
4309
- * Derive secp256k1 public key coordinates from a private key
4310
- *
4311
- * Utility method that can be used to generate public key coordinates
4312
- * for use in ValidityProofParams.senderPublicKey or NoirProviderConfig.oraclePublicKey
4313
- *
4314
- * @param privateKey - 32-byte private key
4315
- * @returns X and Y coordinates as 32-byte arrays
4316
- *
4317
- * @example
4318
- * ```typescript
4319
- * const privateKey = new Uint8Array(32).fill(1) // Your secret key
4320
- * const publicKey = NoirProofProvider.derivePublicKey(privateKey)
4321
- *
4322
- * // Use for oracle configuration
4323
- * const provider = new NoirProofProvider({
4324
- * oraclePublicKey: publicKey
4325
- * })
4326
- *
4327
- * // Or use for validity proof params
4328
- * const validityParams = {
4329
- * // ... other params
4330
- * senderPublicKey: {
4331
- * x: new Uint8Array(publicKey.x),
4332
- * y: new Uint8Array(publicKey.y)
4333
- * }
4334
- * }
4335
- * ```
4336
- */
4337
- static derivePublicKey(privateKey) {
4338
- const uncompressedPubKey = import_secp256k13.secp256k1.getPublicKey(privateKey, false);
4339
- const x = Array.from(uncompressedPubKey.slice(1, 33));
4340
- const y = Array.from(uncompressedPubKey.slice(33, 65));
4341
- return { x, y };
4342
- }
4343
- /**
4344
- * Initialize the Noir provider
4345
- *
4346
- * Loads circuit artifacts and initializes the proving backend.
4347
- */
4348
- async initialize() {
4349
- if (this._isReady) {
4350
- return;
4351
- }
4352
- try {
4353
- if (this.config.verbose) {
4354
- console.log("[NoirProofProvider] Initializing...");
4355
- }
4356
- const fundingCircuit = funding_proof_default;
4357
- this.fundingBackend = new import_bb.UltraHonkBackend(fundingCircuit.bytecode);
4358
- this.fundingNoir = new import_noir_js.Noir(fundingCircuit);
4359
- if (this.config.verbose) {
4360
- console.log("[NoirProofProvider] Funding circuit loaded");
4361
- const artifactVersion = funding_proof_default.noir_version;
4362
- console.log(`[NoirProofProvider] Noir version: ${artifactVersion ?? "unknown"}`);
4363
- }
4364
- const validityCircuit = validity_proof_default;
4365
- this.validityBackend = new import_bb.UltraHonkBackend(validityCircuit.bytecode);
4366
- this.validityNoir = new import_noir_js.Noir(validityCircuit);
4367
- if (this.config.verbose) {
4368
- console.log("[NoirProofProvider] Validity circuit loaded");
4369
- }
4370
- const fulfillmentCircuit = fulfillment_proof_default;
4371
- this.fulfillmentBackend = new import_bb.UltraHonkBackend(fulfillmentCircuit.bytecode);
4372
- this.fulfillmentNoir = new import_noir_js.Noir(fulfillmentCircuit);
4373
- if (this.config.verbose) {
4374
- console.log("[NoirProofProvider] Fulfillment circuit loaded");
4375
- }
4376
- this._isReady = true;
4377
- if (this.config.verbose) {
4378
- console.log("[NoirProofProvider] Initialization complete");
4379
- }
4380
- } catch (error) {
4381
- throw new ProofError(
4382
- `Failed to initialize NoirProofProvider: ${error instanceof Error ? error.message : String(error)}`,
4383
- "SIP_4003" /* PROOF_NOT_IMPLEMENTED */,
4384
- { context: { error } }
4385
- );
4386
- }
4387
- }
4388
- /**
4389
- * Generate a Funding Proof using Noir circuits
4390
- *
4391
- * Proves: balance >= minimumRequired without revealing balance
4392
- *
4393
- * @see docs/specs/FUNDING-PROOF.md
4394
- */
4395
- async generateFundingProof(params) {
4396
- this.ensureReady();
4397
- if (!this.fundingNoir || !this.fundingBackend) {
4398
- throw new ProofGenerationError(
4399
- "funding",
4400
- "Funding circuit not initialized"
4401
- );
4402
- }
4403
- try {
4404
- if (this.config.verbose) {
4405
- console.log("[NoirProofProvider] Generating funding proof...");
4406
- }
4407
- const { commitmentHash, blindingField } = await this.computeCommitmentHash(
4408
- params.balance,
4409
- params.blindingFactor,
4410
- params.assetId
4411
- );
4412
- const witnessInputs = {
4413
- // Public inputs
4414
- commitment_hash: commitmentHash,
4415
- minimum_required: params.minimumRequired.toString(),
4416
- asset_id: this.assetIdToField(params.assetId),
4417
- // Private inputs
4418
- balance: params.balance.toString(),
4419
- blinding: blindingField
4420
- };
4421
- if (this.config.verbose) {
4422
- console.log("[NoirProofProvider] Witness inputs:", {
4423
- commitment_hash: commitmentHash,
4424
- minimum_required: params.minimumRequired.toString(),
4425
- asset_id: this.assetIdToField(params.assetId),
4426
- balance: "[PRIVATE]",
4427
- blinding: "[PRIVATE]"
4428
- });
4429
- }
4430
- const { witness } = await this.fundingNoir.execute(witnessInputs);
4431
- if (this.config.verbose) {
4432
- console.log("[NoirProofProvider] Witness generated, creating proof...");
4433
- }
4434
- const proofData = await this.fundingBackend.generateProof(witness);
4435
- if (this.config.verbose) {
4436
- console.log("[NoirProofProvider] Proof generated successfully");
4437
- }
4438
- const publicInputs = [
4439
- `0x${commitmentHash}`,
4440
- `0x${params.minimumRequired.toString(16).padStart(16, "0")}`,
4441
- `0x${this.assetIdToField(params.assetId)}`
4442
- ];
4443
- const proof = {
4444
- type: "funding",
4445
- proof: `0x${Buffer.from(proofData.proof).toString("hex")}`,
4446
- publicInputs
4447
- };
4448
- return {
4449
- proof,
4450
- publicInputs
4451
- };
4452
- } catch (error) {
4453
- const message = error instanceof Error ? error.message : String(error);
4454
- if (message.includes("Insufficient balance")) {
4455
- throw new ProofGenerationError(
4456
- "funding",
4457
- "Insufficient balance to generate proof",
4458
- error instanceof Error ? error : void 0
4459
- );
4460
- }
4461
- if (message.includes("Commitment hash mismatch")) {
4462
- throw new ProofGenerationError(
4463
- "funding",
4464
- "Commitment hash verification failed",
4465
- error instanceof Error ? error : void 0
4466
- );
4467
- }
4468
- throw new ProofGenerationError(
4469
- "funding",
4470
- `Failed to generate funding proof: ${message}`,
4471
- error instanceof Error ? error : void 0
4472
- );
4473
- }
4474
- }
4475
- /**
4476
- * Generate a Validity Proof using Noir circuits
4477
- *
4478
- * Proves: Intent is authorized by sender without revealing identity
4479
- *
4480
- * @see docs/specs/VALIDITY-PROOF.md
4481
- */
4482
- async generateValidityProof(params) {
4483
- this.ensureReady();
4484
- if (!this.validityNoir || !this.validityBackend) {
4485
- throw new ProofGenerationError(
4486
- "validity",
4487
- "Validity circuit not initialized"
4488
- );
4489
- }
4490
- try {
4491
- if (this.config.verbose) {
4492
- console.log("[NoirProofProvider] Generating validity proof...");
4493
- }
4494
- const intentHashField = this.hexToField(params.intentHash);
4495
- const senderAddressField = this.hexToField(params.senderAddress);
4496
- const senderBlindingField = this.bytesToField(params.senderBlinding);
4497
- const senderSecretField = this.bytesToField(params.senderSecret);
4498
- const nonceField = this.bytesToField(params.nonce);
4499
- const { commitmentX, commitmentY } = await this.computeSenderCommitment(
4500
- senderAddressField,
4501
- senderBlindingField
4502
- );
4503
- const nullifier = await this.computeNullifier(
4504
- senderSecretField,
4505
- intentHashField,
4506
- nonceField
4507
- );
4508
- const signature = Array.from(params.authorizationSignature);
4509
- const messageHash = this.fieldToBytes32(intentHashField);
4510
- let pubKeyX;
4511
- let pubKeyY;
4512
- if (params.senderPublicKey) {
4513
- pubKeyX = Array.from(params.senderPublicKey.x);
4514
- pubKeyY = Array.from(params.senderPublicKey.y);
4515
- } else {
4516
- const coords = this.getPublicKeyCoordinates(params.senderSecret);
4517
- pubKeyX = coords.x;
4518
- pubKeyY = coords.y;
4519
- }
4520
- const witnessInputs = {
4521
- // Public inputs
4522
- intent_hash: intentHashField,
4523
- sender_commitment_x: commitmentX,
4524
- sender_commitment_y: commitmentY,
4525
- nullifier,
4526
- timestamp: params.timestamp.toString(),
4527
- expiry: params.expiry.toString(),
4528
- // Private inputs
4529
- sender_address: senderAddressField,
4530
- sender_blinding: senderBlindingField,
4531
- sender_secret: senderSecretField,
4532
- pub_key_x: pubKeyX,
4533
- pub_key_y: pubKeyY,
4534
- signature,
4535
- message_hash: messageHash,
4536
- nonce: nonceField
4537
- };
4538
- if (this.config.verbose) {
4539
- console.log("[NoirProofProvider] Validity witness inputs:", {
4540
- intent_hash: intentHashField,
4541
- sender_commitment_x: commitmentX,
4542
- sender_commitment_y: commitmentY,
4543
- nullifier,
4544
- timestamp: params.timestamp,
4545
- expiry: params.expiry,
4546
- sender_address: "[PRIVATE]",
4547
- sender_blinding: "[PRIVATE]",
4548
- sender_secret: "[PRIVATE]",
4549
- signature: "[PRIVATE]"
4550
- });
4551
- }
4552
- const { witness } = await this.validityNoir.execute(witnessInputs);
4553
- if (this.config.verbose) {
4554
- console.log("[NoirProofProvider] Validity witness generated, creating proof...");
4555
- }
4556
- const proofData = await this.validityBackend.generateProof(witness);
4557
- if (this.config.verbose) {
4558
- console.log("[NoirProofProvider] Validity proof generated successfully");
4559
- }
4560
- const publicInputs = [
4561
- `0x${intentHashField}`,
4562
- `0x${commitmentX}`,
4563
- `0x${commitmentY}`,
4564
- `0x${nullifier}`,
4565
- `0x${params.timestamp.toString(16).padStart(16, "0")}`,
4566
- `0x${params.expiry.toString(16).padStart(16, "0")}`
4567
- ];
4568
- const proof = {
4569
- type: "validity",
4570
- proof: `0x${Buffer.from(proofData.proof).toString("hex")}`,
4571
- publicInputs
4572
- };
4573
- return {
4574
- proof,
4575
- publicInputs
4576
- };
4577
- } catch (error) {
4578
- const message = error instanceof Error ? error.message : String(error);
4579
- if (message.includes("Sender commitment")) {
4580
- throw new ProofGenerationError(
4581
- "validity",
4582
- "Sender commitment verification failed",
4583
- error instanceof Error ? error : void 0
4584
- );
4585
- }
4586
- if (message.includes("Invalid ECDSA")) {
4587
- throw new ProofGenerationError(
4588
- "validity",
4589
- "Authorization signature verification failed",
4590
- error instanceof Error ? error : void 0
4591
- );
4592
- }
4593
- if (message.includes("Nullifier mismatch")) {
4594
- throw new ProofGenerationError(
4595
- "validity",
4596
- "Nullifier derivation failed",
4597
- error instanceof Error ? error : void 0
4598
- );
4599
- }
4600
- if (message.includes("Intent expired")) {
4601
- throw new ProofGenerationError(
4602
- "validity",
4603
- "Intent has expired (timestamp >= expiry)",
4604
- error instanceof Error ? error : void 0
4605
- );
4606
- }
4607
- throw new ProofGenerationError(
4608
- "validity",
4609
- `Failed to generate validity proof: ${message}`,
4610
- error instanceof Error ? error : void 0
4611
- );
4612
- }
4613
- }
4614
- /**
4615
- * Generate a Fulfillment Proof using Noir circuits
4616
- *
4617
- * Proves: Solver correctly executed the intent and delivered the required
4618
- * output to the recipient, without revealing execution path or liquidity sources.
4619
- *
4620
- * @see docs/specs/FULFILLMENT-PROOF.md
4621
- */
4622
- async generateFulfillmentProof(params) {
4623
- this.ensureReady();
4624
- if (!this.fulfillmentNoir || !this.fulfillmentBackend) {
4625
- throw new ProofGenerationError(
4626
- "fulfillment",
4627
- "Fulfillment circuit not initialized"
4628
- );
4629
- }
4630
- try {
4631
- if (this.config.verbose) {
4632
- console.log("[NoirProofProvider] Generating fulfillment proof...");
4633
- }
4634
- const intentHashField = this.hexToField(params.intentHash);
4635
- const recipientStealthField = this.hexToField(params.recipientStealth);
4636
- const { commitmentX, commitmentY } = await this.computeOutputCommitment(
4637
- params.outputAmount,
4638
- params.outputBlinding
4639
- );
4640
- const solverSecretField = this.bytesToField(params.solverSecret);
4641
- const solverId = await this.computeSolverId(solverSecretField);
4642
- const outputBlindingField = this.bytesToField(params.outputBlinding);
4643
- const attestation = params.oracleAttestation;
4644
- const attestationRecipientField = this.hexToField(attestation.recipient);
4645
- const attestationTxHashField = this.hexToField(attestation.txHash);
4646
- const oracleSignature = Array.from(attestation.signature);
4647
- const oracleMessageHash = await this.computeOracleMessageHash(
4648
- attestation.recipient,
4649
- attestation.amount,
4650
- attestation.txHash,
4651
- attestation.blockNumber
4652
- );
4653
- const oraclePubKeyX = this.config.oraclePublicKey?.x ?? new Array(32).fill(0);
4654
- const oraclePubKeyY = this.config.oraclePublicKey?.y ?? new Array(32).fill(0);
4655
- if (!this.config.oraclePublicKey && this.config.verbose) {
4656
- console.warn("[NoirProofProvider] Warning: No oracle public key configured. Using placeholder keys.");
4657
- }
4658
- const witnessInputs = {
4659
- // Public inputs
4660
- intent_hash: intentHashField,
4661
- output_commitment_x: commitmentX,
4662
- output_commitment_y: commitmentY,
4663
- recipient_stealth: recipientStealthField,
4664
- min_output_amount: params.minOutputAmount.toString(),
4665
- solver_id: solverId,
4666
- fulfillment_time: params.fulfillmentTime.toString(),
4667
- expiry: params.expiry.toString(),
4668
- // Private inputs
4669
- output_amount: params.outputAmount.toString(),
4670
- output_blinding: outputBlindingField,
4671
- solver_secret: solverSecretField,
4672
- attestation_recipient: attestationRecipientField,
4673
- attestation_amount: attestation.amount.toString(),
4674
- attestation_tx_hash: attestationTxHashField,
4675
- attestation_block: attestation.blockNumber.toString(),
4676
- oracle_signature: oracleSignature,
4677
- oracle_message_hash: oracleMessageHash,
4678
- oracle_pub_key_x: oraclePubKeyX,
4679
- oracle_pub_key_y: oraclePubKeyY
4680
- };
4681
- if (this.config.verbose) {
4682
- console.log("[NoirProofProvider] Fulfillment witness inputs:", {
4683
- intent_hash: intentHashField,
4684
- output_commitment_x: commitmentX,
4685
- output_commitment_y: commitmentY,
4686
- recipient_stealth: recipientStealthField,
4687
- min_output_amount: params.minOutputAmount.toString(),
4688
- solver_id: solverId,
4689
- fulfillment_time: params.fulfillmentTime,
4690
- expiry: params.expiry,
4691
- output_amount: "[PRIVATE]",
4692
- output_blinding: "[PRIVATE]",
4693
- solver_secret: "[PRIVATE]",
4694
- oracle_attestation: "[PRIVATE]"
4695
- });
4696
- }
4697
- const { witness } = await this.fulfillmentNoir.execute(witnessInputs);
4698
- if (this.config.verbose) {
4699
- console.log("[NoirProofProvider] Fulfillment witness generated, creating proof...");
4700
- }
4701
- const proofData = await this.fulfillmentBackend.generateProof(witness);
4702
- if (this.config.verbose) {
4703
- console.log("[NoirProofProvider] Fulfillment proof generated successfully");
4704
- }
4705
- const publicInputs = [
4706
- `0x${intentHashField}`,
4707
- `0x${commitmentX}`,
4708
- `0x${commitmentY}`,
4709
- `0x${recipientStealthField}`,
4710
- `0x${params.minOutputAmount.toString(16).padStart(16, "0")}`,
4711
- `0x${solverId}`,
4712
- `0x${params.fulfillmentTime.toString(16).padStart(16, "0")}`,
4713
- `0x${params.expiry.toString(16).padStart(16, "0")}`
4714
- ];
4715
- const proof = {
4716
- type: "fulfillment",
4717
- proof: `0x${Buffer.from(proofData.proof).toString("hex")}`,
4718
- publicInputs
4719
- };
4720
- return {
4721
- proof,
4722
- publicInputs
4723
- };
4724
- } catch (error) {
4725
- const message = error instanceof Error ? error.message : String(error);
4726
- if (message.includes("Output below minimum")) {
4727
- throw new ProofGenerationError(
4728
- "fulfillment",
4729
- "Output amount is below minimum required",
4730
- error instanceof Error ? error : void 0
4731
- );
4732
- }
4733
- if (message.includes("Commitment") && message.includes("mismatch")) {
4734
- throw new ProofGenerationError(
4735
- "fulfillment",
4736
- "Output commitment verification failed",
4737
- error instanceof Error ? error : void 0
4738
- );
4739
- }
4740
- if (message.includes("Recipient mismatch")) {
4741
- throw new ProofGenerationError(
4742
- "fulfillment",
4743
- "Attestation recipient does not match",
4744
- error instanceof Error ? error : void 0
4745
- );
4746
- }
4747
- if (message.includes("Invalid oracle")) {
4748
- throw new ProofGenerationError(
4749
- "fulfillment",
4750
- "Oracle attestation signature is invalid",
4751
- error instanceof Error ? error : void 0
4752
- );
4753
- }
4754
- if (message.includes("Unauthorized solver")) {
4755
- throw new ProofGenerationError(
4756
- "fulfillment",
4757
- "Solver not authorized for this intent",
4758
- error instanceof Error ? error : void 0
4759
- );
4760
- }
4761
- if (message.includes("Fulfillment after expiry")) {
4762
- throw new ProofGenerationError(
4763
- "fulfillment",
4764
- "Fulfillment occurred after intent expiry",
4765
- error instanceof Error ? error : void 0
4766
- );
4767
- }
4768
- throw new ProofGenerationError(
4769
- "fulfillment",
4770
- `Failed to generate fulfillment proof: ${message}`,
4771
- error instanceof Error ? error : void 0
4772
- );
4773
- }
4774
- }
4775
- /**
4776
- * Verify a Noir proof
4777
- */
4778
- async verifyProof(proof) {
4779
- this.ensureReady();
4780
- let backend = null;
4781
- switch (proof.type) {
4782
- case "funding":
4783
- backend = this.fundingBackend;
4784
- break;
4785
- case "validity":
4786
- backend = this.validityBackend;
4787
- break;
4788
- case "fulfillment":
4789
- backend = this.fulfillmentBackend;
4790
- break;
4791
- default:
4792
- throw new ProofError(
4793
- `Unknown proof type: ${proof.type}`,
4794
- "SIP_4003" /* PROOF_NOT_IMPLEMENTED */
4795
- );
4796
- }
4797
- if (!backend) {
4798
- throw new ProofError(
4799
- `${proof.type} backend not initialized`,
4800
- "SIP_4004" /* PROOF_PROVIDER_NOT_READY */
4801
- );
4802
- }
4803
- try {
4804
- const proofHex = proof.proof.startsWith("0x") ? proof.proof.slice(2) : proof.proof;
4805
- const proofBytes = new Uint8Array(Buffer.from(proofHex, "hex"));
4806
- const isValid = await backend.verifyProof({
4807
- proof: proofBytes,
4808
- publicInputs: proof.publicInputs.map(
4809
- (input) => input.startsWith("0x") ? input.slice(2) : input
4810
- )
4811
- });
4812
- return isValid;
4813
- } catch (error) {
4814
- if (this.config.verbose) {
4815
- console.error("[NoirProofProvider] Verification error:", error);
4816
- }
4817
- return false;
4818
- }
4819
- }
4820
- /**
4821
- * Destroy the provider and free resources
4822
- */
4823
- async destroy() {
4824
- if (this.fundingBackend) {
4825
- await this.fundingBackend.destroy();
4826
- this.fundingBackend = null;
4827
- }
4828
- if (this.validityBackend) {
4829
- await this.validityBackend.destroy();
4830
- this.validityBackend = null;
4831
- }
4832
- if (this.fulfillmentBackend) {
4833
- await this.fulfillmentBackend.destroy();
4834
- this.fulfillmentBackend = null;
4835
- }
4836
- this.fundingNoir = null;
4837
- this.validityNoir = null;
4838
- this.fulfillmentNoir = null;
4839
- this._isReady = false;
4840
- }
4841
- // ─── Private Methods ───────────────────────────────────────────────────────
4842
- ensureReady() {
4843
- if (!this._isReady) {
4844
- throw new ProofError(
4845
- "NoirProofProvider not initialized. Call initialize() first.",
4846
- "SIP_4004" /* PROOF_PROVIDER_NOT_READY */
4847
- );
4848
- }
4849
- }
4850
- /**
4851
- * Compute the commitment hash that the circuit expects
4852
- *
4853
- * The circuit computes:
4854
- * 1. commitment = pedersen_commitment([balance, blinding])
4855
- * 2. commitment_hash = pedersen_hash([commitment.x, commitment.y, asset_id])
4856
- *
4857
- * We need to compute this outside to pass as a public input.
4858
- *
4859
- * **IMPORTANT**: This SDK uses SHA256 as a deterministic stand-in for Pedersen hash.
4860
- * Both the SDK and circuit MUST use the same hash function. The bundled circuit
4861
- * artifacts are configured to use SHA256 for compatibility. If you use custom
4862
- * circuits with actual Pedersen hashing, you must update this implementation.
4863
- *
4864
- * @see docs/specs/HASH-COMPATIBILITY.md for hash function requirements
4865
- */
4866
- async computeCommitmentHash(balance, blindingFactor, assetId) {
4867
- const blindingField = this.bytesToField(blindingFactor);
4868
- const { sha256: sha25611 } = await import("@noble/hashes/sha256");
4869
- const { bytesToHex: bytesToHex15 } = await import("@noble/hashes/utils");
4870
- const preimage = new Uint8Array([
4871
- ...this.bigintToBytes(balance, 8),
4872
- ...blindingFactor.slice(0, 32),
4873
- ...this.hexToBytes(this.assetIdToField(assetId))
4874
- ]);
4875
- const hash2 = sha25611(preimage);
4876
- const commitmentHash = bytesToHex15(hash2);
4877
- return { commitmentHash, blindingField };
4878
- }
4879
- /**
4880
- * Convert asset ID to field element
4881
- */
4882
- assetIdToField(assetId) {
4883
- if (assetId.startsWith("0x")) {
4884
- return assetId.slice(2).padStart(64, "0");
4885
- }
4886
- const encoder = new TextEncoder();
4887
- const bytes = encoder.encode(assetId);
4888
- let result = 0n;
4889
- for (let i = 0; i < bytes.length && i < 31; i++) {
4890
- result = result * 256n + BigInt(bytes[i]);
4891
- }
4892
- return result.toString(16).padStart(64, "0");
4893
- }
4894
- /**
4895
- * Convert bytes to field element string
4896
- */
4897
- bytesToField(bytes) {
4898
- let result = 0n;
4899
- const len = Math.min(bytes.length, 31);
4900
- for (let i = 0; i < len; i++) {
4901
- result = result * 256n + BigInt(bytes[i]);
4902
- }
4903
- return result.toString();
4904
- }
4905
- /**
4906
- * Convert bigint to bytes
4907
- */
4908
- bigintToBytes(value, length) {
4909
- const bytes = new Uint8Array(length);
4910
- let v = value;
4911
- for (let i = length - 1; i >= 0; i--) {
4912
- bytes[i] = Number(v & 0xffn);
4913
- v = v >> 8n;
4914
- }
4915
- return bytes;
4916
- }
4917
- /**
4918
- * Convert hex string to bytes
4919
- */
4920
- hexToBytes(hex) {
4921
- const h = hex.startsWith("0x") ? hex.slice(2) : hex;
4922
- const bytes = new Uint8Array(h.length / 2);
4923
- for (let i = 0; i < bytes.length; i++) {
4924
- bytes[i] = parseInt(h.slice(i * 2, i * 2 + 2), 16);
4925
- }
4926
- return bytes;
4927
- }
4928
- /**
4929
- * Convert hex string to field element string
4930
- */
4931
- hexToField(hex) {
4932
- const h = hex.startsWith("0x") ? hex.slice(2) : hex;
4933
- return h.padStart(64, "0");
4934
- }
4935
- /**
4936
- * Convert field string to 32-byte array
4937
- */
4938
- fieldToBytes32(field) {
4939
- const hex = field.padStart(64, "0");
4940
- const bytes = [];
4941
- for (let i = 0; i < 32; i++) {
4942
- bytes.push(parseInt(hex.slice(i * 2, i * 2 + 2), 16));
4943
- }
4944
- return bytes;
4945
- }
4946
- /**
4947
- * Compute sender commitment for validity proof
4948
- *
4949
- * Uses SHA256 for SDK-side computation. The bundled circuit artifacts
4950
- * are compiled to use SHA256 for compatibility with this SDK.
4951
- *
4952
- * @see computeCommitmentHash for hash function compatibility notes
4953
- */
4954
- async computeSenderCommitment(senderAddressField, senderBlindingField) {
4955
- const { sha256: sha25611 } = await import("@noble/hashes/sha256");
4956
- const { bytesToHex: bytesToHex15 } = await import("@noble/hashes/utils");
4957
- const addressBytes = this.hexToBytes(senderAddressField);
4958
- const blindingBytes = this.hexToBytes(senderBlindingField.padStart(64, "0"));
4959
- const preimage = new Uint8Array([...addressBytes, ...blindingBytes]);
4960
- const hash2 = sha25611(preimage);
4961
- const commitmentX = bytesToHex15(hash2.slice(0, 16)).padStart(64, "0");
4962
- const commitmentY = bytesToHex15(hash2.slice(16, 32)).padStart(64, "0");
4963
- return { commitmentX, commitmentY };
4964
- }
4965
- /**
4966
- * Compute nullifier for validity proof
4967
- *
4968
- * Uses SHA256 for SDK-side computation. The bundled circuit artifacts
4969
- * are compiled to use SHA256 for compatibility with this SDK.
4970
- *
4971
- * @see computeCommitmentHash for hash function compatibility notes
4972
- */
4973
- async computeNullifier(senderSecretField, intentHashField, nonceField) {
4974
- const { sha256: sha25611 } = await import("@noble/hashes/sha256");
4975
- const { bytesToHex: bytesToHex15 } = await import("@noble/hashes/utils");
4976
- const secretBytes = this.hexToBytes(senderSecretField.padStart(64, "0"));
4977
- const intentBytes = this.hexToBytes(intentHashField);
4978
- const nonceBytes = this.hexToBytes(nonceField.padStart(64, "0"));
4979
- const preimage = new Uint8Array([...secretBytes, ...intentBytes, ...nonceBytes]);
4980
- const hash2 = sha25611(preimage);
4981
- return bytesToHex15(hash2);
4982
- }
4983
- /**
4984
- * Compute output commitment for fulfillment proof
4985
- *
4986
- * Uses SHA256 for SDK-side computation. The bundled circuit artifacts
4987
- * are compiled to use SHA256 for compatibility with this SDK.
4988
- *
4989
- * @see computeCommitmentHash for hash function compatibility notes
4990
- */
4991
- async computeOutputCommitment(outputAmount, outputBlinding) {
4992
- const { sha256: sha25611 } = await import("@noble/hashes/sha256");
4993
- const { bytesToHex: bytesToHex15 } = await import("@noble/hashes/utils");
4994
- const amountBytes = this.bigintToBytes(outputAmount, 8);
4995
- const blindingBytes = outputBlinding.slice(0, 32);
4996
- const preimage = new Uint8Array([...amountBytes, ...blindingBytes]);
4997
- const hash2 = sha25611(preimage);
4998
- const commitmentX = bytesToHex15(hash2.slice(0, 16)).padStart(64, "0");
4999
- const commitmentY = bytesToHex15(hash2.slice(16, 32)).padStart(64, "0");
5000
- return { commitmentX, commitmentY };
5001
- }
5002
- /**
5003
- * Compute solver ID from solver secret
5004
- *
5005
- * Uses SHA256 for SDK-side computation. The bundled circuit artifacts
5006
- * are compiled to use SHA256 for compatibility with this SDK.
5007
- *
5008
- * @see computeCommitmentHash for hash function compatibility notes
5009
- */
5010
- async computeSolverId(solverSecretField) {
5011
- const { sha256: sha25611 } = await import("@noble/hashes/sha256");
5012
- const { bytesToHex: bytesToHex15 } = await import("@noble/hashes/utils");
5013
- const secretBytes = this.hexToBytes(solverSecretField.padStart(64, "0"));
5014
- const hash2 = sha25611(secretBytes);
5015
- return bytesToHex15(hash2);
5016
- }
5017
- /**
5018
- * Compute oracle message hash for fulfillment proof
5019
- *
5020
- * Hash of attestation data that oracle signs
5021
- */
5022
- async computeOracleMessageHash(recipient, amount, txHash, blockNumber) {
5023
- const { sha256: sha25611 } = await import("@noble/hashes/sha256");
5024
- const recipientBytes = this.hexToBytes(this.hexToField(recipient));
5025
- const amountBytes = this.bigintToBytes(amount, 8);
5026
- const txHashBytes = this.hexToBytes(this.hexToField(txHash));
5027
- const blockBytes = this.bigintToBytes(blockNumber, 8);
5028
- const preimage = new Uint8Array([
5029
- ...recipientBytes,
5030
- ...amountBytes,
5031
- ...txHashBytes,
5032
- ...blockBytes
5033
- ]);
5034
- const hash2 = sha25611(preimage);
5035
- return Array.from(hash2);
5036
- }
5037
- /**
5038
- * Derive secp256k1 public key coordinates from a private key
5039
- *
5040
- * @param privateKey - 32-byte private key as Uint8Array
5041
- * @returns X and Y coordinates as 32-byte arrays
5042
- */
5043
- getPublicKeyCoordinates(privateKey) {
5044
- const uncompressedPubKey = import_secp256k13.secp256k1.getPublicKey(privateKey, false);
5045
- const x = Array.from(uncompressedPubKey.slice(1, 33));
5046
- const y = Array.from(uncompressedPubKey.slice(33, 65));
5047
- return { x, y };
5048
- }
5049
- /**
5050
- * Derive public key coordinates from a field string (private key)
5051
- *
5052
- * @param privateKeyField - Private key as hex field string
5053
- * @returns X and Y coordinates as 32-byte arrays
5054
- */
5055
- getPublicKeyFromField(privateKeyField) {
5056
- const privateKeyBytes = this.hexToBytes(privateKeyField.padStart(64, "0"));
5057
- return this.getPublicKeyCoordinates(privateKeyBytes);
5058
- }
5059
- };
5060
-
5061
3312
  // src/proofs/browser-utils.ts
5062
3313
  function hexToBytes5(hex) {
5063
3314
  const h = hex.startsWith("0x") ? hex.slice(2) : hex;
@@ -7049,7 +5300,7 @@ function getPaymentSummary(payment) {
7049
5300
 
7050
5301
  // src/treasury/treasury.ts
7051
5302
  var import_types12 = require("@sip-protocol/types");
7052
- var import_secp256k14 = require("@noble/curves/secp256k1");
5303
+ var import_secp256k13 = require("@noble/curves/secp256k1");
7053
5304
  var import_sha25610 = require("@noble/hashes/sha256");
7054
5305
  var import_utils12 = require("@noble/hashes/utils");
7055
5306
  var DEFAULT_PROPOSAL_TTL = 7 * 24 * 60 * 60;
@@ -7565,7 +5816,7 @@ function signMessage(messageHash, privateKey) {
7565
5816
  const keyHex = privateKey.startsWith("0x") ? privateKey.slice(2) : privateKey;
7566
5817
  const keyBytes = (0, import_utils12.hexToBytes)(keyHex);
7567
5818
  try {
7568
- const signature = import_secp256k14.secp256k1.sign(messageHash, keyBytes);
5819
+ const signature = import_secp256k13.secp256k1.sign(messageHash, keyBytes);
7569
5820
  return `0x${signature.toCompactHex()}`;
7570
5821
  } finally {
7571
5822
  secureWipe(keyBytes);
@@ -7577,7 +5828,7 @@ function verifySignature(messageHash, signature, publicKey) {
7577
5828
  try {
7578
5829
  const sigBytes = (0, import_utils12.hexToBytes)(sigHex);
7579
5830
  const pubKeyBytes = (0, import_utils12.hexToBytes)(pubKeyHex);
7580
- return import_secp256k14.secp256k1.verify(sigBytes, messageHash, pubKeyBytes);
5831
+ return import_secp256k13.secp256k1.verify(sigBytes, messageHash, pubKeyBytes);
7581
5832
  } catch {
7582
5833
  return false;
7583
5834
  }
@@ -12132,7 +10383,6 @@ var import_types32 = require("@sip-protocol/types");
12132
10383
  NATIVE_TOKENS,
12133
10384
  NEARIntentsAdapter,
12134
10385
  NetworkError,
12135
- NoirProofProvider,
12136
10386
  ORACLE_DOMAIN,
12137
10387
  OneClickClient,
12138
10388
  OneClickDepositMode,