zkjson 0.1.30 → 0.1.32

Sign up to get free protection for your applications and to get access to all the features.
package/circomlibjs.js CHANGED
@@ -26,31 +26,31 @@ class BabyJub {
26
26
  constructor(F) {
27
27
  this.F = F
28
28
  this.p = ffjavascript.Scalar.fromString(
29
- "21888242871839275222246405745257275088548364400416034343698204186575808495617"
29
+ "21888242871839275222246405745257275088548364400416034343698204186575808495617",
30
30
  )
31
31
  this.pm1d2 = ffjavascript.Scalar.div(
32
32
  ffjavascript.Scalar.sub(this.p, ffjavascript.Scalar.e(1)),
33
- ffjavascript.Scalar.e(2)
33
+ ffjavascript.Scalar.e(2),
34
34
  )
35
35
 
36
36
  this.Generator = [
37
37
  F.e(
38
- "995203441582195749578291179787384436505546430278305826713579947235728471134"
38
+ "995203441582195749578291179787384436505546430278305826713579947235728471134",
39
39
  ),
40
40
  F.e(
41
- "5472060717959818805561601436314318772137091100104008585924551046643952123905"
41
+ "5472060717959818805561601436314318772137091100104008585924551046643952123905",
42
42
  ),
43
43
  ]
44
44
  this.Base8 = [
45
45
  F.e(
46
- "5299619240641551281634865583518297030282874472190772894086521144482721001553"
46
+ "5299619240641551281634865583518297030282874472190772894086521144482721001553",
47
47
  ),
48
48
  F.e(
49
- "16950150798460657717958625567821834550301663161624707787222815936182638968203"
49
+ "16950150798460657717958625567821834550301663161624707787222815936182638968203",
50
50
  ),
51
51
  ]
52
52
  this.order = ffjavascript.Scalar.fromString(
53
- "21888242871839275222246405745257275088614511777268538073601725287587578984328"
53
+ "21888242871839275222246405745257275088614511777268538073601725287587578984328",
54
54
  )
55
55
  this.subOrder = ffjavascript.Scalar.shiftRight(this.order, 3)
56
56
  this.A = F.e("168700")
@@ -77,7 +77,7 @@ class BabyJub {
77
77
 
78
78
  res[1] = F.div(
79
79
  F.add(delta, F.sub(F.mul(this.A, beta), gamma)),
80
- F.sub(F.one, dtau)
80
+ F.sub(F.one, dtau),
81
81
  )
82
82
 
83
83
  return res
@@ -115,7 +115,7 @@ class BabyJub {
115
115
  if (
116
116
  !F.eq(
117
117
  F.add(F.mul(this.A, x2), y2),
118
- F.add(F.one, F.mul(F.mul(x2, y2), this.D))
118
+ F.add(F.one, F.mul(F.mul(x2, y2), this.D)),
119
119
  )
120
120
  )
121
121
  return false
@@ -184,7 +184,7 @@ class PedersenHash {
184
184
  return createBlakeHash__default["default"]("blake256").update(S).digest()
185
185
  } else if (type == "blake2b") {
186
186
  return Buffer.from(
187
- blake2b__default["default"](32).update(Buffer.from(S)).digest()
187
+ blake2b__default["default"](32).update(Buffer.from(S)).digest(),
188
188
  )
189
189
  }
190
190
  }
@@ -206,7 +206,7 @@ class PedersenHash {
206
206
  if (s == nSegments - 1) {
207
207
  nWindows =
208
208
  Math.floor(
209
- (bits.length - (nSegments - 1) * bitsPerSegment - 1) / windowSize
209
+ (bits.length - (nSegments - 1) * bitsPerSegment - 1) / windowSize,
210
210
  ) + 1
211
211
  } else {
212
212
  nWindows = nWindowsPerSegment
@@ -220,7 +220,7 @@ class PedersenHash {
220
220
  if (bits[o]) {
221
221
  acc = ffjavascript.Scalar.add(
222
222
  acc,
223
- ffjavascript.Scalar.shl(ffjavascript.Scalar.e(1), b)
223
+ ffjavascript.Scalar.shl(ffjavascript.Scalar.e(1), b),
224
224
  )
225
225
  }
226
226
  o++
@@ -233,7 +233,7 @@ class PedersenHash {
233
233
  }
234
234
  escalar = ffjavascript.Scalar.add(
235
235
  escalar,
236
- ffjavascript.Scalar.mul(acc, exp)
236
+ ffjavascript.Scalar.mul(acc, exp),
237
237
  )
238
238
  exp = ffjavascript.Scalar.shl(exp, windowSize + 1)
239
239
  }
@@ -244,7 +244,10 @@ class PedersenHash {
244
244
 
245
245
  accP = babyJub.addPoint(
246
246
  accP,
247
- babyJub.mulPointEscalar(this.getBasePoint(options.baseHash, s), escalar)
247
+ babyJub.mulPointEscalar(
248
+ this.getBasePoint(options.baseHash, s),
249
+ escalar,
250
+ ),
248
251
  )
249
252
  }
250
253
 
@@ -324,7 +327,7 @@ class Mimc7 {
324
327
  const F = this.F
325
328
  if (typeof seed === "undefined") seed = SEED$1
326
329
  const c = ethers.ethers.utils.keccak256(
327
- ethers.ethers.utils.toUtf8Bytes(seed + "_iv")
330
+ ethers.ethers.utils.toUtf8Bytes(seed + "_iv"),
328
331
  )
329
332
  const cn = ffjavascript.Scalar.e(c)
330
333
  const iv = ffjavascript.Scalar.mod(cn, F.p)
@@ -336,7 +339,7 @@ class Mimc7 {
336
339
  if (typeof nRounds === "undefined") nRounds = NROUNDS$1
337
340
  const cts = new Array(nRounds)
338
341
  let c = ethers.ethers.utils.keccak256(
339
- ethers.ethers.utils.toUtf8Bytes(SEED$1)
342
+ ethers.ethers.utils.toUtf8Bytes(SEED$1),
340
343
  )
341
344
  for (let i = 1; i < nRounds; i++) {
342
345
  c = ethers.ethers.utils.keccak256(c)
@@ -25188,7 +25191,7 @@ async function buildPoseidon$2() {
25188
25191
  const bn128 = await ffjavascript.getCurveFromName(
25189
25192
  "bn128",
25190
25193
  true,
25191
- buildPoseidonWasm
25194
+ buildPoseidonWasm,
25192
25195
  )
25193
25196
 
25194
25197
  const F = bn128.Fr
@@ -25240,8 +25243,8 @@ async function buildPoseidon$2() {
25240
25243
  function buildPoseidonWasm(module) {
25241
25244
  const F = new ffjavascript.F1Field(
25242
25245
  ffjavascript.Scalar.e(
25243
- "21888242871839275222246405745257275088548364400416034343698204186575808495617"
25244
- )
25246
+ "21888242871839275222246405745257275088548364400416034343698204186575808495617",
25247
+ ),
25245
25248
  )
25246
25249
  const N_ROUNDS_P = [
25247
25250
  56, 57, 56, 60, 60, 63, 64, 63, 60, 66, 60, 65, 70, 60, 64, 68,
@@ -25304,18 +25307,18 @@ function buildPoseidonWasm(module) {
25304
25307
  "frm_add",
25305
25308
  c.getLocal("pC"),
25306
25309
  c.getLocal("pState"),
25307
- c.getLocal("pState")
25310
+ c.getLocal("pState"),
25308
25311
  ),
25309
25312
  c.setLocal("pC", c.i32_add(c.getLocal("pC"), c.i32_const(32))),
25310
25313
  c.setLocal(
25311
25314
  "pState",
25312
- c.i32_add(c.getLocal("pState"), c.i32_const(32))
25315
+ c.i32_add(c.getLocal("pState"), c.i32_const(32)),
25313
25316
  ),
25314
25317
  c.setLocal("i", c.i32_add(c.getLocal("i"), c.i32_const(1))),
25315
- c.br(0)
25316
- )
25318
+ c.br(0),
25319
+ ),
25317
25320
  ),
25318
- c.ret(c.getLocal("pC"))
25321
+ c.ret(c.getLocal("pC")),
25319
25322
  )
25320
25323
  }
25321
25324
 
@@ -25330,7 +25333,7 @@ function buildPoseidonWasm(module) {
25330
25333
  f.addCode(
25331
25334
  c.call("frm_square", c.getLocal("p"), AUX),
25332
25335
  c.call("frm_square", AUX, AUX),
25333
- c.call("frm_mul", c.getLocal("p"), AUX, c.getLocal("p"))
25336
+ c.call("frm_mul", c.getLocal("p"), AUX, c.getLocal("p")),
25334
25337
  )
25335
25338
  }
25336
25339
 
@@ -25351,12 +25354,12 @@ function buildPoseidonWasm(module) {
25351
25354
  c.call("poseidon_power5", c.getLocal("pState")),
25352
25355
  c.setLocal(
25353
25356
  "pState",
25354
- c.i32_add(c.getLocal("pState"), c.i32_const(32))
25357
+ c.i32_add(c.getLocal("pState"), c.i32_const(32)),
25355
25358
  ),
25356
25359
  c.setLocal("i", c.i32_add(c.getLocal("i"), c.i32_const(1))),
25357
- c.br(0)
25358
- )
25359
- )
25360
+ c.br(0),
25361
+ ),
25362
+ ),
25360
25363
  )
25361
25364
  }
25362
25365
 
@@ -25391,30 +25394,30 @@ function buildPoseidonWasm(module) {
25391
25394
  "frm_mul",
25392
25395
  c.getLocal("pState"),
25393
25396
  c.getLocal("pM"),
25394
- c.i32_const(pAux)
25397
+ c.i32_const(pAux),
25395
25398
  ),
25396
25399
  c.call(
25397
25400
  "frm_add",
25398
25401
  c.i32_const(pAux),
25399
25402
  c.getLocal("pStateAux"),
25400
- c.getLocal("pStateAux")
25403
+ c.getLocal("pStateAux"),
25401
25404
  ),
25402
25405
  c.setLocal("pM", c.i32_add(c.getLocal("pM"), c.i32_const(32))),
25403
25406
  c.setLocal(
25404
25407
  "pState",
25405
- c.i32_add(c.getLocal("pState"), c.i32_const(32))
25408
+ c.i32_add(c.getLocal("pState"), c.i32_const(32)),
25406
25409
  ),
25407
25410
  c.setLocal("j", c.i32_add(c.getLocal("j"), c.i32_const(1))),
25408
- c.br(0)
25409
- )
25411
+ c.br(0),
25412
+ ),
25410
25413
  ),
25411
25414
  c.setLocal(
25412
25415
  "pStateAux",
25413
- c.i32_add(c.getLocal("pStateAux"), c.i32_const(32))
25416
+ c.i32_add(c.getLocal("pStateAux"), c.i32_const(32)),
25414
25417
  ),
25415
25418
  c.setLocal("i", c.i32_add(c.getLocal("i"), c.i32_const(1))),
25416
- c.br(0)
25417
- )
25419
+ c.br(0),
25420
+ ),
25418
25421
  ),
25419
25422
  c.setLocal("pStateAux", c.i32_const(pStateAux)),
25420
25423
  c.setLocal("pState", c.i32_const(pState)),
@@ -25425,16 +25428,16 @@ function buildPoseidonWasm(module) {
25425
25428
  c.call("frm_copy", c.getLocal("pStateAux"), c.getLocal("pState")),
25426
25429
  c.setLocal(
25427
25430
  "pState",
25428
- c.i32_add(c.getLocal("pState"), c.i32_const(32))
25431
+ c.i32_add(c.getLocal("pState"), c.i32_const(32)),
25429
25432
  ),
25430
25433
  c.setLocal(
25431
25434
  "pStateAux",
25432
- c.i32_add(c.getLocal("pStateAux"), c.i32_const(32))
25435
+ c.i32_add(c.getLocal("pStateAux"), c.i32_const(32)),
25433
25436
  ),
25434
25437
  c.setLocal("i", c.i32_add(c.getLocal("i"), c.i32_const(1))),
25435
- c.br(0)
25436
- )
25437
- )
25438
+ c.br(0),
25439
+ ),
25440
+ ),
25438
25441
  )
25439
25442
  }
25440
25443
 
@@ -25462,22 +25465,22 @@ function buildPoseidonWasm(module) {
25462
25465
  "frm_mul",
25463
25466
  c.getLocal("pState"),
25464
25467
  c.getLocal("pS"),
25465
- c.i32_const(pAux)
25468
+ c.i32_const(pAux),
25466
25469
  ),
25467
25470
  c.call(
25468
25471
  "frm_add",
25469
25472
  c.i32_const(pS0),
25470
25473
  c.i32_const(pAux),
25471
- c.i32_const(pS0)
25474
+ c.i32_const(pS0),
25472
25475
  ),
25473
25476
  c.setLocal("pS", c.i32_add(c.getLocal("pS"), c.i32_const(32))),
25474
25477
  c.setLocal(
25475
25478
  "pState",
25476
- c.i32_add(c.getLocal("pState"), c.i32_const(32))
25479
+ c.i32_add(c.getLocal("pState"), c.i32_const(32)),
25477
25480
  ),
25478
25481
  c.setLocal("i", c.i32_add(c.getLocal("i"), c.i32_const(1))),
25479
- c.br(0)
25480
- )
25482
+ c.br(0),
25483
+ ),
25481
25484
  ),
25482
25485
 
25483
25486
  c.setLocal("pState", c.i32_const(pState + 32)),
@@ -25489,25 +25492,25 @@ function buildPoseidonWasm(module) {
25489
25492
  "frm_mul",
25490
25493
  c.i32_const(pState),
25491
25494
  c.getLocal("pS"),
25492
- c.i32_const(pAux)
25495
+ c.i32_const(pAux),
25493
25496
  ),
25494
25497
  c.call(
25495
25498
  "frm_add",
25496
25499
  c.getLocal("pState"),
25497
25500
  c.i32_const(pAux),
25498
- c.getLocal("pState")
25501
+ c.getLocal("pState"),
25499
25502
  ),
25500
25503
  c.setLocal("pS", c.i32_add(c.getLocal("pS"), c.i32_const(32))),
25501
25504
  c.setLocal(
25502
25505
  "pState",
25503
- c.i32_add(c.getLocal("pState"), c.i32_const(32))
25506
+ c.i32_add(c.getLocal("pState"), c.i32_const(32)),
25504
25507
  ),
25505
25508
  c.setLocal("i", c.i32_add(c.getLocal("i"), c.i32_const(1))),
25506
- c.br(0)
25507
- )
25509
+ c.br(0),
25510
+ ),
25508
25511
  ),
25509
25512
  c.call("frm_copy", c.i32_const(pS0), c.i32_const(pState)),
25510
- c.ret(c.getLocal("pS"))
25513
+ c.ret(c.getLocal("pS")),
25511
25514
  )
25512
25515
  }
25513
25516
 
@@ -25535,25 +25538,28 @@ function buildPoseidonWasm(module) {
25535
25538
  "pAux",
25536
25539
  c.i32_add(
25537
25540
  c.i32_const(pConstants),
25538
- c.i32_mul(c.i32_sub(c.getLocal("n"), c.i32_const(1)), c.i32_const(20))
25539
- )
25541
+ c.i32_mul(
25542
+ c.i32_sub(c.getLocal("n"), c.i32_const(1)),
25543
+ c.i32_const(20),
25544
+ ),
25545
+ ),
25540
25546
  ),
25541
25547
  c.setLocal("nRoundsP", c.i32_load(c.getLocal("pAux"))),
25542
25548
  c.setLocal(
25543
25549
  "pC",
25544
- c.i32_load(c.i32_add(c.getLocal("pAux"), c.i32_const(4)))
25550
+ c.i32_load(c.i32_add(c.getLocal("pAux"), c.i32_const(4))),
25545
25551
  ),
25546
25552
  c.setLocal(
25547
25553
  "pS",
25548
- c.i32_load(c.i32_add(c.getLocal("pAux"), c.i32_const(8)))
25554
+ c.i32_load(c.i32_add(c.getLocal("pAux"), c.i32_const(8))),
25549
25555
  ),
25550
25556
  c.setLocal(
25551
25557
  "pM",
25552
- c.i32_load(c.i32_add(c.getLocal("pAux"), c.i32_const(12)))
25558
+ c.i32_load(c.i32_add(c.getLocal("pAux"), c.i32_const(12))),
25553
25559
  ),
25554
25560
  c.setLocal(
25555
25561
  "pP",
25556
- c.i32_load(c.i32_add(c.getLocal("pAux"), c.i32_const(16)))
25562
+ c.i32_load(c.i32_add(c.getLocal("pAux"), c.i32_const(16))),
25557
25563
  ),
25558
25564
 
25559
25565
  // Initialize state
@@ -25568,24 +25574,24 @@ function buildPoseidonWasm(module) {
25568
25574
  c.getLocal("pIn"),
25569
25575
  c.i32_mul(
25570
25576
  c.i32_sub(c.getLocal("i"), c.i32_const(1)),
25571
- c.i32_const(32)
25572
- )
25577
+ c.i32_const(32),
25578
+ ),
25573
25579
  ),
25574
25580
  c.i32_add(
25575
25581
  c.i32_const(pState),
25576
- c.i32_mul(c.getLocal("i"), c.i32_const(32))
25577
- )
25582
+ c.i32_mul(c.getLocal("i"), c.i32_const(32)),
25583
+ ),
25578
25584
  ),
25579
25585
  c.br_if(1, c.i32_eq(c.getLocal("i"), c.getLocal("n"))),
25580
25586
  c.setLocal("i", c.i32_add(c.getLocal("i"), c.i32_const(1))),
25581
- c.br(0)
25582
- )
25587
+ c.br(0),
25588
+ ),
25583
25589
  ),
25584
25590
 
25585
25591
  // Initialize state
25586
25592
  c.setLocal(
25587
25593
  "pC",
25588
- c.call("poseidon_addConstant", c.getLocal("t"), c.getLocal("pC"))
25594
+ c.call("poseidon_addConstant", c.getLocal("t"), c.getLocal("pC")),
25589
25595
  ),
25590
25596
  // First full rounds
25591
25597
  c.setLocal("i", c.i32_const(0)),
@@ -25595,18 +25601,18 @@ function buildPoseidonWasm(module) {
25595
25601
  c.call("poseidon_power5all", c.getLocal("t")),
25596
25602
  c.setLocal(
25597
25603
  "pC",
25598
- c.call("poseidon_addConstant", c.getLocal("t"), c.getLocal("pC"))
25604
+ c.call("poseidon_addConstant", c.getLocal("t"), c.getLocal("pC")),
25599
25605
  ),
25600
25606
  c.call("poseidon_applyMatrix", c.getLocal("t"), c.getLocal("pM")),
25601
25607
  c.setLocal("i", c.i32_add(c.getLocal("i"), c.i32_const(1))),
25602
- c.br(0)
25603
- )
25608
+ c.br(0),
25609
+ ),
25604
25610
  ),
25605
25611
 
25606
25612
  c.call("poseidon_power5all", c.getLocal("t")),
25607
25613
  c.setLocal(
25608
25614
  "pC",
25609
- c.call("poseidon_addConstant", c.getLocal("t"), c.getLocal("pC"))
25615
+ c.call("poseidon_addConstant", c.getLocal("t"), c.getLocal("pC")),
25610
25616
  ),
25611
25617
  c.call("poseidon_applyMatrix", c.getLocal("t"), c.getLocal("pP")),
25612
25618
 
@@ -25619,16 +25625,16 @@ function buildPoseidonWasm(module) {
25619
25625
  "frm_add",
25620
25626
  c.i32_const(pState),
25621
25627
  c.getLocal("pC"),
25622
- c.i32_const(pState)
25628
+ c.i32_const(pState),
25623
25629
  ),
25624
25630
  c.setLocal("pC", c.i32_add(c.getLocal("pC"), c.i32_const(32))),
25625
25631
  c.setLocal(
25626
25632
  "pS",
25627
- c.call("poseidon_applySMatrix", c.getLocal("t"), c.getLocal("pS"))
25633
+ c.call("poseidon_applySMatrix", c.getLocal("t"), c.getLocal("pS")),
25628
25634
  ),
25629
25635
  c.setLocal("i", c.i32_add(c.getLocal("i"), c.i32_const(1))),
25630
- c.br(0)
25631
- )
25636
+ c.br(0),
25637
+ ),
25632
25638
  ),
25633
25639
 
25634
25640
  c.setLocal("i", c.i32_const(0)),
@@ -25638,12 +25644,12 @@ function buildPoseidonWasm(module) {
25638
25644
  c.call("poseidon_power5all", c.getLocal("t")),
25639
25645
  c.setLocal(
25640
25646
  "pC",
25641
- c.call("poseidon_addConstant", c.getLocal("t"), c.getLocal("pC"))
25647
+ c.call("poseidon_addConstant", c.getLocal("t"), c.getLocal("pC")),
25642
25648
  ),
25643
25649
  c.call("poseidon_applyMatrix", c.getLocal("t"), c.getLocal("pM")),
25644
25650
  c.setLocal("i", c.i32_add(c.getLocal("i"), c.i32_const(1))),
25645
- c.br(0)
25646
- )
25651
+ c.br(0),
25652
+ ),
25647
25653
  ),
25648
25654
  c.call("poseidon_power5all", c.getLocal("t")),
25649
25655
  c.call("poseidon_applyMatrix", c.getLocal("t"), c.getLocal("pM")),
@@ -25656,17 +25662,17 @@ function buildPoseidonWasm(module) {
25656
25662
  "frm_copy",
25657
25663
  c.i32_add(
25658
25664
  c.i32_const(pState),
25659
- c.i32_mul(c.getLocal("i"), c.i32_const(32))
25665
+ c.i32_mul(c.getLocal("i"), c.i32_const(32)),
25660
25666
  ),
25661
25667
  c.i32_add(
25662
25668
  c.getLocal("pOut"),
25663
- c.i32_mul(c.getLocal("i"), c.i32_const(32))
25664
- )
25669
+ c.i32_mul(c.getLocal("i"), c.i32_const(32)),
25670
+ ),
25665
25671
  ),
25666
25672
  c.setLocal("i", c.i32_add(c.getLocal("i"), c.i32_const(1))),
25667
- c.br(0)
25668
- )
25669
- )
25673
+ c.br(0),
25674
+ ),
25675
+ ),
25670
25676
  )
25671
25677
  }
25672
25678
 
@@ -25698,7 +25704,7 @@ class MimcSponge {
25698
25704
  const F = this.F
25699
25705
  if (typeof seed === "undefined") seed = SEED
25700
25706
  const c = ethers.ethers.utils.keccak256(
25701
- ethers.ethers.utils.toUtf8Bytes(seed + "_iv")
25707
+ ethers.ethers.utils.toUtf8Bytes(seed + "_iv"),
25702
25708
  )
25703
25709
  const cn = ffjavascript.Scalar.e(c)
25704
25710
  const iv = cn.mod(F.p)
@@ -25809,12 +25815,12 @@ class Eddsa {
25809
25815
  const sBuff = this.pruneBuffer(
25810
25816
  createBlakeHash__default["default"]("blake512")
25811
25817
  .update(Buffer.from(prv))
25812
- .digest()
25818
+ .digest(),
25813
25819
  )
25814
25820
  let s = ffjavascript.Scalar.fromRprLE(sBuff, 0, 32)
25815
25821
  const A = this.babyJub.mulPointEscalar(
25816
25822
  this.babyJub.Base8,
25817
- ffjavascript.Scalar.shr(s, 3)
25823
+ ffjavascript.Scalar.shr(s, 3),
25818
25824
  )
25819
25825
  return A
25820
25826
  }
@@ -25824,12 +25830,12 @@ class Eddsa {
25824
25830
  const sBuff = this.pruneBuffer(
25825
25831
  createBlakeHash__default["default"]("blake512")
25826
25832
  .update(Buffer.from(prv))
25827
- .digest()
25833
+ .digest(),
25828
25834
  )
25829
25835
  const s = ffjavascript.Scalar.fromRprLE(sBuff, 0, 32)
25830
25836
  const A = this.babyJub.mulPointEscalar(
25831
25837
  this.babyJub.Base8,
25832
- ffjavascript.Scalar.shr(s, 3)
25838
+ ffjavascript.Scalar.shr(s, 3),
25833
25839
  )
25834
25840
 
25835
25841
  const composeBuff = new Uint8Array(32 + msg.length)
@@ -25840,7 +25846,7 @@ class Eddsa {
25840
25846
  .digest()
25841
25847
  let r = ffjavascript.Scalar.mod(
25842
25848
  ffjavascript.Scalar.fromRprLE(rBuff, 0, 64),
25843
- this.babyJub.subOrder
25849
+ this.babyJub.subOrder,
25844
25850
  )
25845
25851
  const R8 = this.babyJub.mulPointEscalar(this.babyJub.Base8, r)
25846
25852
  const R8p = this.babyJub.packPoint(R8)
@@ -25856,7 +25862,7 @@ class Eddsa {
25856
25862
 
25857
25863
  const S = ffjavascript.Scalar.mod(
25858
25864
  ffjavascript.Scalar.add(r, ffjavascript.Scalar.mul(hm, s)),
25859
- this.babyJub.subOrder
25865
+ this.babyJub.subOrder,
25860
25866
  )
25861
25867
  return {
25862
25868
  R8: R8,
@@ -25869,12 +25875,12 @@ class Eddsa {
25869
25875
  const sBuff = this.pruneBuffer(
25870
25876
  createBlakeHash__default["default"]("blake512")
25871
25877
  .update(Buffer.from(prv))
25872
- .digest()
25878
+ .digest(),
25873
25879
  )
25874
25880
  const s = ffjavascript.Scalar.fromRprLE(sBuff, 0, 32)
25875
25881
  const A = this.babyJub.mulPointEscalar(
25876
25882
  this.babyJub.Base8,
25877
- ffjavascript.Scalar.shr(s, 3)
25883
+ ffjavascript.Scalar.shr(s, 3),
25878
25884
  )
25879
25885
 
25880
25886
  const composeBuff = new Uint8Array(32 + msg.length)
@@ -25885,7 +25891,7 @@ class Eddsa {
25885
25891
  .digest()
25886
25892
  let r = ffjavascript.Scalar.mod(
25887
25893
  ffjavascript.Scalar.fromRprLE(rBuff, 0, 64),
25888
- this.babyJub.subOrder
25894
+ this.babyJub.subOrder,
25889
25895
  )
25890
25896
  const R8 = this.babyJub.mulPointEscalar(this.babyJub.Base8, r)
25891
25897
 
@@ -25893,7 +25899,7 @@ class Eddsa {
25893
25899
  const hms = ffjavascript.Scalar.e(this.babyJub.F.toObject(hm))
25894
25900
  const S = ffjavascript.Scalar.mod(
25895
25901
  ffjavascript.Scalar.add(r, ffjavascript.Scalar.mul(hms, s)),
25896
- this.babyJub.subOrder
25902
+ this.babyJub.subOrder,
25897
25903
  )
25898
25904
  return {
25899
25905
  R8: R8,
@@ -25906,12 +25912,12 @@ class Eddsa {
25906
25912
  const sBuff = this.pruneBuffer(
25907
25913
  createBlakeHash__default["default"]("blake512")
25908
25914
  .update(Buffer.from(prv))
25909
- .digest()
25915
+ .digest(),
25910
25916
  )
25911
25917
  const s = ffjavascript.Scalar.fromRprLE(sBuff, 0, 32)
25912
25918
  const A = this.babyJub.mulPointEscalar(
25913
25919
  this.babyJub.Base8,
25914
- ffjavascript.Scalar.shr(s, 3)
25920
+ ffjavascript.Scalar.shr(s, 3),
25915
25921
  )
25916
25922
 
25917
25923
  const composeBuff = new Uint8Array(32 + msg.length)
@@ -25922,7 +25928,7 @@ class Eddsa {
25922
25928
  .digest()
25923
25929
  let r = ffjavascript.Scalar.mod(
25924
25930
  ffjavascript.Scalar.fromRprLE(rBuff, 0, 64),
25925
- this.babyJub.subOrder
25931
+ this.babyJub.subOrder,
25926
25932
  )
25927
25933
  const R8 = this.babyJub.mulPointEscalar(this.babyJub.Base8, r)
25928
25934
 
@@ -25930,7 +25936,7 @@ class Eddsa {
25930
25936
  const hms = ffjavascript.Scalar.e(this.babyJub.F.toObject(hm))
25931
25937
  const S = ffjavascript.Scalar.mod(
25932
25938
  ffjavascript.Scalar.add(r, ffjavascript.Scalar.mul(hms, s)),
25933
- this.babyJub.subOrder
25939
+ this.babyJub.subOrder,
25934
25940
  )
25935
25941
  return {
25936
25942
  R8: R8,
@@ -25943,12 +25949,12 @@ class Eddsa {
25943
25949
  const sBuff = this.pruneBuffer(
25944
25950
  createBlakeHash__default["default"]("blake512")
25945
25951
  .update(Buffer.from(prv))
25946
- .digest()
25952
+ .digest(),
25947
25953
  )
25948
25954
  const s = ffjavascript.Scalar.fromRprLE(sBuff, 0, 32)
25949
25955
  const A = this.babyJub.mulPointEscalar(
25950
25956
  this.babyJub.Base8,
25951
- ffjavascript.Scalar.shr(s, 3)
25957
+ ffjavascript.Scalar.shr(s, 3),
25952
25958
  )
25953
25959
 
25954
25960
  const composeBuff = new Uint8Array(32 + msg.length)
@@ -25959,7 +25965,7 @@ class Eddsa {
25959
25965
  .digest()
25960
25966
  let r = ffjavascript.Scalar.mod(
25961
25967
  ffjavascript.Scalar.fromRprLE(rBuff, 0, 64),
25962
- this.babyJub.subOrder
25968
+ this.babyJub.subOrder,
25963
25969
  )
25964
25970
  const R8 = this.babyJub.mulPointEscalar(this.babyJub.Base8, r)
25965
25971
 
@@ -25967,7 +25973,7 @@ class Eddsa {
25967
25973
  const hms = ffjavascript.Scalar.e(this.babyJub.F.toObject(hm))
25968
25974
  const S = ffjavascript.Scalar.mod(
25969
25975
  ffjavascript.Scalar.add(r, ffjavascript.Scalar.mul(hms, s)),
25970
- this.babyJub.subOrder
25976
+ this.babyJub.subOrder,
25971
25977
  )
25972
25978
  return {
25973
25979
  R8: R8,
@@ -26023,7 +26029,7 @@ class Eddsa {
26023
26029
  const Pleft = this.babyJub.mulPointEscalar(this.babyJub.Base8, sig.S)
26024
26030
  let Pright = this.babyJub.mulPointEscalar(
26025
26031
  A,
26026
- ffjavascript.Scalar.mul(hms, 8)
26032
+ ffjavascript.Scalar.mul(hms, 8),
26027
26033
  )
26028
26034
  Pright = this.babyJub.addPoint(sig.R8, Pright)
26029
26035
 
@@ -26049,7 +26055,7 @@ class Eddsa {
26049
26055
  const Pleft = this.babyJub.mulPointEscalar(this.babyJub.Base8, sig.S)
26050
26056
  let Pright = this.babyJub.mulPointEscalar(
26051
26057
  A,
26052
- ffjavascript.Scalar.mul(hms, 8)
26058
+ ffjavascript.Scalar.mul(hms, 8),
26053
26059
  )
26054
26060
  Pright = this.babyJub.addPoint(sig.R8, Pright)
26055
26061
 
@@ -26081,7 +26087,7 @@ class Eddsa {
26081
26087
  const Pleft = this.babyJub.mulPointEscalar(this.babyJub.Base8, sig.S)
26082
26088
  let Pright = this.babyJub.mulPointEscalar(
26083
26089
  A,
26084
- ffjavascript.Scalar.mul(hms, 8)
26090
+ ffjavascript.Scalar.mul(hms, 8),
26085
26091
  )
26086
26092
  Pright = this.babyJub.addPoint(sig.R8, Pright)
26087
26093
 
@@ -26371,7 +26377,7 @@ class Contract {
26371
26377
  if (ffjavascript.Scalar.isNegative(v)) {
26372
26378
  v = ffjavascript.Scalar.add(
26373
26379
  ffjavascript.Scalar.shl(ffjavascript.Scalar.e(1), 256),
26374
- v
26380
+ v,
26375
26381
  )
26376
26382
  }
26377
26383
  let S = ffjavascript.Scalar.toString(v, 16)
@@ -39795,18 +39801,18 @@ function createCode(nInputs) {
39795
39801
  C.push(
39796
39802
  ethers.ethers.utils
39797
39803
  .keccak256(
39798
- ethers.ethers.utils.toUtf8Bytes(`poseidon(uint256[${nInputs}])`)
39804
+ ethers.ethers.utils.toUtf8Bytes(`poseidon(uint256[${nInputs}])`),
39799
39805
  )
39800
- .slice(0, 10)
39806
+ .slice(0, 10),
39801
39807
  ) // poseidon(uint256[n])
39802
39808
  C.eq()
39803
39809
  C.swap(1)
39804
39810
  C.push(
39805
39811
  ethers.ethers.utils
39806
39812
  .keccak256(
39807
- ethers.ethers.utils.toUtf8Bytes(`poseidon(bytes32[${nInputs}])`)
39813
+ ethers.ethers.utils.toUtf8Bytes(`poseidon(bytes32[${nInputs}])`),
39808
39814
  )
39809
- .slice(0, 10)
39815
+ .slice(0, 10),
39810
39816
  ) // poseidon(bytes32[n])
39811
39817
  C.eq()
39812
39818
  C.or()
@@ -39978,8 +39984,8 @@ async function buildPoseidon$1() {
39978
39984
  state = state.map((_, i) =>
39979
39985
  state.reduce(
39980
39986
  (acc, a, j) => F.add(acc, F.mul(M[t - 2][i][j], a)),
39981
- F.zero
39982
- )
39987
+ F.zero,
39988
+ ),
39983
39989
  )
39984
39990
  }
39985
39991
  if (nOut == 1) {
@@ -40056,13 +40062,13 @@ async function buildPoseidon() {
40056
40062
  state = state.map(a => pow5(a))
40057
40063
  state = state.map((a, i) => F.add(a, C[(r + 1) * t + i]))
40058
40064
  state = state.map((_, i) =>
40059
- state.reduce((acc, a, j) => F.add(acc, F.mul(M[j][i], a)), F.zero)
40065
+ state.reduce((acc, a, j) => F.add(acc, F.mul(M[j][i], a)), F.zero),
40060
40066
  )
40061
40067
  }
40062
40068
  state = state.map(a => pow5(a))
40063
40069
  state = state.map((a, i) => F.add(a, C[(nRoundsF / 2 - 1 + 1) * t + i]))
40064
40070
  state = state.map((_, i) =>
40065
- state.reduce((acc, a, j) => F.add(acc, F.mul(P[j][i], a)), F.zero)
40071
+ state.reduce((acc, a, j) => F.add(acc, F.mul(P[j][i], a)), F.zero),
40066
40072
  )
40067
40073
  for (let r = 0; r < nRoundsP; r++) {
40068
40074
  state[0] = pow5(state[0])
@@ -40074,7 +40080,7 @@ async function buildPoseidon() {
40074
40080
  for (let k = 1; k < t; k++) {
40075
40081
  state[k] = F.add(
40076
40082
  state[k],
40077
- F.mul(state[0], S[(t * 2 - 1) * r + t + k - 1])
40083
+ F.mul(state[0], S[(t * 2 - 1) * r + t + k - 1]),
40078
40084
  )
40079
40085
  }
40080
40086
  state[0] = s0
@@ -40082,15 +40088,15 @@ async function buildPoseidon() {
40082
40088
  for (let r = 0; r < nRoundsF / 2 - 1; r++) {
40083
40089
  state = state.map(a => pow5(a))
40084
40090
  state = state.map((a, i) =>
40085
- F.add(a, C[(nRoundsF / 2 + 1) * t + nRoundsP + r * t + i])
40091
+ F.add(a, C[(nRoundsF / 2 + 1) * t + nRoundsP + r * t + i]),
40086
40092
  )
40087
40093
  state = state.map((_, i) =>
40088
- state.reduce((acc, a, j) => F.add(acc, F.mul(M[j][i], a)), F.zero)
40094
+ state.reduce((acc, a, j) => F.add(acc, F.mul(M[j][i], a)), F.zero),
40089
40095
  )
40090
40096
  }
40091
40097
  state = state.map(a => pow5(a))
40092
40098
  state = state.map((_, i) =>
40093
- state.reduce((acc, a, j) => F.add(acc, F.mul(M[j][i], a)), F.zero)
40099
+ state.reduce((acc, a, j) => F.add(acc, F.mul(M[j][i], a)), F.zero),
40094
40100
  )
40095
40101
 
40096
40102
  if (nOut == 1) {
@@ -40200,17 +40206,35 @@ class SMT {
40200
40206
  }
40201
40207
 
40202
40208
  async update(_key, _newValue) {
40203
- const poseidon = await buildPoseidon()
40209
+ this.poseidon ??= await buildPoseidon()
40210
+ this.zero ??= this.poseidon([
40211
+ "0",
40212
+ "0",
40213
+ "0",
40214
+ "0",
40215
+ "0",
40216
+ "0",
40217
+ "0",
40218
+ "0",
40219
+ "0",
40220
+ "0",
40221
+ "0",
40222
+ "0",
40223
+ "0",
40224
+ "0",
40225
+ "0",
40226
+ "0",
40227
+ ])
40204
40228
  let _hash_value = _newValue
40205
40229
  if (_newValue.length === 256) {
40206
40230
  _hash_value = []
40207
40231
  for (let v of splitEvery(16, _newValue)) {
40208
- const poseidon = await buildPoseidon()
40209
- const value = poseidon(v)
40232
+ const value =
40233
+ v.join("") === "0000000000000000" ? this.zero : this.poseidon(v)
40210
40234
  _hash_value.push(value)
40211
40235
  }
40212
40236
  }
40213
- const newValue = poseidon(_hash_value)
40237
+ const newValue = this.poseidon(_hash_value)
40214
40238
  const F = this.F
40215
40239
  const key = F.e(_key)
40216
40240
  const resFind = await this.find(key)
@@ -40279,7 +40303,7 @@ class SMT {
40279
40303
  let mixed
40280
40304
  if (resFind.siblings.length > 0) {
40281
40305
  const record = await this.db.get(
40282
- resFind.siblings[resFind.siblings.length - 1]
40306
+ resFind.siblings[resFind.siblings.length - 1],
40283
40307
  )
40284
40308
  if (record.length == 3 && F.eq(record[0], F.one)) {
40285
40309
  mixed = false
@@ -40346,18 +40370,36 @@ class SMT {
40346
40370
  }
40347
40371
 
40348
40372
  async insert(_key, _value) {
40349
- const poseidon = await buildPoseidon()
40373
+ this.poseidon ??= await buildPoseidon()
40374
+ this.zero ??= this.poseidon([
40375
+ "0",
40376
+ "0",
40377
+ "0",
40378
+ "0",
40379
+ "0",
40380
+ "0",
40381
+ "0",
40382
+ "0",
40383
+ "0",
40384
+ "0",
40385
+ "0",
40386
+ "0",
40387
+ "0",
40388
+ "0",
40389
+ "0",
40390
+ "0",
40391
+ ])
40350
40392
  let _hash_value = _value
40351
40393
  if (_value.length === 256) {
40352
40394
  _hash_value = []
40353
40395
  for (let v of splitEvery(16, _value)) {
40354
- const poseidon = await buildPoseidon()
40355
- const value = poseidon(v)
40396
+ const value =
40397
+ v.join("") === "0000000000000000" ? this.zero : this.poseidon(v)
40356
40398
  _hash_value.push(value)
40357
40399
  }
40358
40400
  }
40359
40401
 
40360
- const value = poseidon(_hash_value)
40402
+ const value = this.poseidon(_hash_value)
40361
40403
  const F = this.F
40362
40404
  const key = F.e(_key)
40363
40405
  let addedOne = false