@solarity/zkit 0.3.3 → 0.3.5
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/README.md +3 -2
- package/dist/core/CircuitZKit.js +17 -7
- package/dist/core/CircuitZKit.js.map +1 -1
- package/dist/core/protocols/Groth16Implementer.d.ts +2 -2
- package/dist/core/protocols/Groth16Implementer.d.ts.map +1 -1
- package/dist/core/protocols/Groth16Implementer.js +26 -9
- package/dist/core/protocols/Groth16Implementer.js.map +1 -1
- package/dist/core/protocols/PlonkImplementer.d.ts +2 -2
- package/dist/core/protocols/PlonkImplementer.d.ts.map +1 -1
- package/dist/core/protocols/PlonkImplementer.js +22 -8
- package/dist/core/protocols/PlonkImplementer.js.map +1 -1
- package/dist/core/templates/verifier_groth16.sol.ejs +4 -1
- package/dist/core/templates/verifier_groth16.vy.ejs +3 -1
- package/dist/core/templates/verifier_plonk.sol.ejs +82 -82
- package/dist/core/templates/verifier_plonk.vy.ejs +79 -79
- package/dist/types/protocols/groth16.d.ts +9 -15
- package/dist/types/protocols/groth16.d.ts.map +1 -1
- package/dist/types/protocols/index.d.ts +5 -5
- package/dist/types/protocols/index.d.ts.map +1 -1
- package/dist/types/protocols/plonk.d.ts +4 -0
- package/dist/types/protocols/plonk.d.ts.map +1 -1
- package/dist/utils.js +17 -7
- package/dist/utils.js.map +1 -1
- package/package.json +3 -2
- package/src/core/protocols/Groth16Implementer.ts +14 -5
- package/src/core/protocols/PlonkImplementer.ts +9 -4
- package/src/core/templates/verifier_groth16.sol.ejs +4 -1
- package/src/core/templates/verifier_groth16.vy.ejs +3 -1
- package/src/core/templates/verifier_plonk.sol.ejs +82 -82
- package/src/core/templates/verifier_plonk.vy.ejs +79 -79
- package/src/types/protocols/groth16.ts +10 -6
- package/src/types/protocols/index.ts +5 -5
- package/src/types/protocols/plonk.ts +5 -0
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
# Omega
|
|
6
6
|
W1: constant(uint256) = <%=w%>
|
|
7
7
|
# Scalar field size
|
|
8
|
-
|
|
8
|
+
SCALAR_FIELD_SIZE: constant(uint256) = 21888242871839275222246405745257275088548364400416034343698204186575808495617
|
|
9
9
|
# Base field size
|
|
10
|
-
|
|
10
|
+
BASE_FIELD_SIZE: constant(uint256) = 21888242871839275222246405745257275088696311157297823662689037894645226208583
|
|
11
11
|
|
|
12
12
|
# [1]_1
|
|
13
13
|
G1_X: constant(uint256) = 1
|
|
@@ -227,13 +227,13 @@ def _inverseArray(pVals: uint256[<%=nPublic + 1%>]) -> uint256[<%=nPublic + 1%>]
|
|
|
227
227
|
|
|
228
228
|
for i: uint256 in range(1, <%=nPublic + 1%>):
|
|
229
229
|
pAux[i] = acc
|
|
230
|
-
acc = uint256_mulmod(acc, pVals[i],
|
|
230
|
+
acc = uint256_mulmod(acc, pVals[i], SCALAR_FIELD_SIZE)
|
|
231
231
|
|
|
232
|
-
inv_total: uint256 = self._inverse(acc,
|
|
232
|
+
inv_total: uint256 = self._inverse(acc, SCALAR_FIELD_SIZE)
|
|
233
233
|
|
|
234
234
|
for i: uint256 in range(<%=nPublic%>):
|
|
235
|
-
inverses[<%=nPublic%> - i] = uint256_mulmod(inv_total, pAux[<%=nPublic%> - i],
|
|
236
|
-
inv_total = uint256_mulmod(inv_total, pVals[<%=nPublic%> - i],
|
|
235
|
+
inverses[<%=nPublic%> - i] = uint256_mulmod(inv_total, pAux[<%=nPublic%> - i], SCALAR_FIELD_SIZE)
|
|
236
|
+
inv_total = uint256_mulmod(inv_total, pVals[<%=nPublic%> - i], SCALAR_FIELD_SIZE)
|
|
237
237
|
|
|
238
238
|
inverses[0] = inv_total
|
|
239
239
|
|
|
@@ -243,22 +243,22 @@ def _inverseArray(pVals: uint256[<%=nPublic + 1%>]) -> uint256[<%=nPublic + 1%>]
|
|
|
243
243
|
@pure
|
|
244
244
|
@internal
|
|
245
245
|
def _checkInput(proof: uint256[24]) -> bool:
|
|
246
|
-
if proof[P_EVAL_A] >=
|
|
246
|
+
if proof[P_EVAL_A] >= SCALAR_FIELD_SIZE:
|
|
247
247
|
return False
|
|
248
248
|
|
|
249
|
-
if proof[P_EVAL_B] >=
|
|
249
|
+
if proof[P_EVAL_B] >= SCALAR_FIELD_SIZE:
|
|
250
250
|
return False
|
|
251
251
|
|
|
252
|
-
if proof[P_EVAL_C] >=
|
|
252
|
+
if proof[P_EVAL_C] >= SCALAR_FIELD_SIZE:
|
|
253
253
|
return False
|
|
254
254
|
|
|
255
|
-
if proof[P_EVAL_S1] >=
|
|
255
|
+
if proof[P_EVAL_S1] >= SCALAR_FIELD_SIZE:
|
|
256
256
|
return False
|
|
257
257
|
|
|
258
|
-
if proof[P_EVAL_S2] >=
|
|
258
|
+
if proof[P_EVAL_S2] >= SCALAR_FIELD_SIZE:
|
|
259
259
|
return False
|
|
260
260
|
|
|
261
|
-
if proof[P_EVAL_ZW] >=
|
|
261
|
+
if proof[P_EVAL_ZW] >= SCALAR_FIELD_SIZE:
|
|
262
262
|
return False
|
|
263
263
|
|
|
264
264
|
return True
|
|
@@ -273,54 +273,54 @@ def _calculateChallenges(proof: uint256[24], pubSignals: uint256[<%=nPublic%>])
|
|
|
273
273
|
proof[P_A], proof[P_A + 1], proof[P_B], proof[P_B + 1], proof[P_C], proof[P_C + 1],
|
|
274
274
|
]
|
|
275
275
|
|
|
276
|
-
beta: uint256 = convert(keccak256(abi_encode(mIn<%=22+nPublic%>)), uint256) %
|
|
276
|
+
beta: uint256 = convert(keccak256(abi_encode(mIn<%=22+nPublic%>)), uint256) % SCALAR_FIELD_SIZE
|
|
277
277
|
|
|
278
278
|
p: uint256[P_TOTAL_SIZE] = empty(uint256[P_TOTAL_SIZE])
|
|
279
279
|
p[P_BETA] = beta
|
|
280
280
|
|
|
281
281
|
# challenges.gamma
|
|
282
|
-
p[P_GAMMA] = convert(keccak256(abi_encode(p[P_BETA])), uint256) %
|
|
282
|
+
p[P_GAMMA] = convert(keccak256(abi_encode(p[P_BETA])), uint256) % SCALAR_FIELD_SIZE
|
|
283
283
|
|
|
284
284
|
# challenges.alpha
|
|
285
285
|
mIn4: uint256[4] = [beta, p[P_GAMMA], proof[P_Z], proof[P_Z + 1]]
|
|
286
|
-
aux: uint256 = convert(keccak256(abi_encode(mIn4)), uint256) %
|
|
286
|
+
aux: uint256 = convert(keccak256(abi_encode(mIn4)), uint256) % SCALAR_FIELD_SIZE
|
|
287
287
|
p[P_ALPHA] = aux
|
|
288
|
-
p[P_ALPHA2] = uint256_mulmod(aux, aux,
|
|
288
|
+
p[P_ALPHA2] = uint256_mulmod(aux, aux, SCALAR_FIELD_SIZE)
|
|
289
289
|
|
|
290
290
|
# challenges.xi
|
|
291
291
|
mIn7: uint256[7] = [aux, proof[P_T1], proof[P_T1 + 1], proof[P_T2], proof[P_T2 + 1], proof[P_T3], proof[P_T3 + 1]]
|
|
292
|
-
aux = convert(keccak256(abi_encode(mIn7)), uint256) %
|
|
292
|
+
aux = convert(keccak256(abi_encode(mIn7)), uint256) % SCALAR_FIELD_SIZE
|
|
293
293
|
p[P_XI] = aux
|
|
294
294
|
|
|
295
295
|
# challenges.v
|
|
296
296
|
mIn7 = [
|
|
297
297
|
aux, proof[P_EVAL_A], proof[P_EVAL_B], proof[P_EVAL_C], proof[P_EVAL_S1], proof[P_EVAL_S2], proof[P_EVAL_ZW]
|
|
298
298
|
]
|
|
299
|
-
v1: uint256 = convert(keccak256(abi_encode(mIn7)), uint256) %
|
|
299
|
+
v1: uint256 = convert(keccak256(abi_encode(mIn7)), uint256) % SCALAR_FIELD_SIZE
|
|
300
300
|
p[P_V1] = v1
|
|
301
301
|
|
|
302
302
|
# challenges.v^2, challenges.v^3, challenges.v^4, challenges.v^5
|
|
303
|
-
p[P_V2] = uint256_mulmod(v1, v1,
|
|
304
|
-
p[P_V3] = uint256_mulmod(p[P_V2], v1,
|
|
305
|
-
p[P_V4] = uint256_mulmod(p[P_V3], v1,
|
|
306
|
-
p[P_V5] = uint256_mulmod(p[P_V4], v1,
|
|
303
|
+
p[P_V2] = uint256_mulmod(v1, v1, SCALAR_FIELD_SIZE)
|
|
304
|
+
p[P_V3] = uint256_mulmod(p[P_V2], v1, SCALAR_FIELD_SIZE)
|
|
305
|
+
p[P_V4] = uint256_mulmod(p[P_V3], v1, SCALAR_FIELD_SIZE)
|
|
306
|
+
p[P_V5] = uint256_mulmod(p[P_V4], v1, SCALAR_FIELD_SIZE)
|
|
307
307
|
|
|
308
308
|
# challenges.beta * challenges.xi
|
|
309
|
-
p[P_BETA_XI] = uint256_mulmod(beta, aux,
|
|
309
|
+
p[P_BETA_XI] = uint256_mulmod(beta, aux, SCALAR_FIELD_SIZE)
|
|
310
310
|
|
|
311
311
|
# challenges.xi^n
|
|
312
312
|
<%for (let i = 0; i < power; i++) {%>
|
|
313
|
-
aux = uint256_mulmod(aux, aux,
|
|
313
|
+
aux = uint256_mulmod(aux, aux, SCALAR_FIELD_SIZE)<% } %>
|
|
314
314
|
p[P_XIN] = aux
|
|
315
315
|
|
|
316
316
|
# Zh
|
|
317
|
-
aux = uint256_addmod(aux,
|
|
317
|
+
aux = uint256_addmod(aux, SCALAR_FIELD_SIZE - 1, SCALAR_FIELD_SIZE)
|
|
318
318
|
p[P_ZH] = aux
|
|
319
319
|
p[P_ZH_INV] = aux
|
|
320
320
|
|
|
321
321
|
# challenges.u
|
|
322
322
|
mIn4 = [proof[P_WX_I], proof[P_WX_I + 1], proof[P_WX_IW], proof[P_WX_IW + 1]]
|
|
323
|
-
p[P_U] = convert(keccak256(abi_encode(mIn4)), uint256) %
|
|
323
|
+
p[P_U] = convert(keccak256(abi_encode(mIn4)), uint256) % SCALAR_FIELD_SIZE
|
|
324
324
|
|
|
325
325
|
return p
|
|
326
326
|
|
|
@@ -328,7 +328,7 @@ def _calculateChallenges(proof: uint256[24], pubSignals: uint256[<%=nPublic%>])
|
|
|
328
328
|
@pure
|
|
329
329
|
@internal
|
|
330
330
|
def _evaluateLagrange(w: uint256, xi: uint256) -> uint256:
|
|
331
|
-
return uint256_mulmod(N, uint256_addmod(xi,
|
|
331
|
+
return uint256_mulmod(N, uint256_addmod(xi, SCALAR_FIELD_SIZE - w, SCALAR_FIELD_SIZE), SCALAR_FIELD_SIZE)
|
|
332
332
|
|
|
333
333
|
|
|
334
334
|
@pure
|
|
@@ -338,7 +338,7 @@ def _calculateLagrange(p: uint256[P_TOTAL_SIZE]) -> uint256[P_TOTAL_SIZE]:
|
|
|
338
338
|
|
|
339
339
|
for i: uint256 in range(1, <%=nPublic + 1%>):
|
|
340
340
|
p[P_EVAL_L1 + (i - 1)] = self._evaluateLagrange(w, p[P_XI])
|
|
341
|
-
w = uint256_mulmod(w, W1,
|
|
341
|
+
w = uint256_mulmod(w, W1, SCALAR_FIELD_SIZE)
|
|
342
342
|
|
|
343
343
|
pointsToInverse: uint256[<%=nPublic + 1%>] = empty(uint256[<%=nPublic + 1%>])
|
|
344
344
|
for i: uint256 in range(<%=nPublic + 1%>):
|
|
@@ -354,11 +354,11 @@ def _calculateLagrange(p: uint256[P_TOTAL_SIZE]) -> uint256[P_TOTAL_SIZE]:
|
|
|
354
354
|
|
|
355
355
|
for i: uint256 in range(1, <%=nPublic + 1%>):
|
|
356
356
|
p[P_EVAL_L1 + (i - 1)] = uint256_mulmod(
|
|
357
|
-
uint256_mulmod(p[P_EVAL_L1 + (i - 1)], zh,
|
|
357
|
+
uint256_mulmod(p[P_EVAL_L1 + (i - 1)], zh, SCALAR_FIELD_SIZE),
|
|
358
358
|
w,
|
|
359
|
-
|
|
359
|
+
SCALAR_FIELD_SIZE
|
|
360
360
|
)
|
|
361
|
-
w = uint256_mulmod(w, W1,
|
|
361
|
+
w = uint256_mulmod(w, W1, SCALAR_FIELD_SIZE)
|
|
362
362
|
|
|
363
363
|
return p
|
|
364
364
|
|
|
@@ -371,8 +371,8 @@ def _calculatePI(p: uint256[P_TOTAL_SIZE], pPub: uint256[<%=nPublic%>]) -> uint2
|
|
|
371
371
|
for i: uint256 in range(<%=nPublic%>):
|
|
372
372
|
pl = uint256_addmod(
|
|
373
373
|
pl,
|
|
374
|
-
|
|
375
|
-
|
|
374
|
+
SCALAR_FIELD_SIZE - uint256_mulmod(p[P_EVAL_L1 + i], pPub[i], SCALAR_FIELD_SIZE),
|
|
375
|
+
SCALAR_FIELD_SIZE
|
|
376
376
|
)
|
|
377
377
|
|
|
378
378
|
return pl
|
|
@@ -383,30 +383,30 @@ def _calculatePI(p: uint256[P_TOTAL_SIZE], pPub: uint256[<%=nPublic%>]) -> uint2
|
|
|
383
383
|
def _calculateR0(p: uint256[P_TOTAL_SIZE], proof: uint256[24]) -> uint256:
|
|
384
384
|
e1: uint256 = p[P_PI]
|
|
385
385
|
|
|
386
|
-
e2: uint256 = uint256_mulmod(p[P_EVAL_L1], p[P_ALPHA2],
|
|
386
|
+
e2: uint256 = uint256_mulmod(p[P_EVAL_L1], p[P_ALPHA2], SCALAR_FIELD_SIZE)
|
|
387
387
|
|
|
388
388
|
e3a: uint256 = uint256_addmod(
|
|
389
389
|
proof[P_EVAL_A],
|
|
390
|
-
uint256_mulmod(p[P_BETA], proof[P_EVAL_S1],
|
|
391
|
-
|
|
390
|
+
uint256_mulmod(p[P_BETA], proof[P_EVAL_S1], SCALAR_FIELD_SIZE),
|
|
391
|
+
SCALAR_FIELD_SIZE
|
|
392
392
|
)
|
|
393
|
-
e3a = uint256_addmod(e3a, p[P_GAMMA],
|
|
393
|
+
e3a = uint256_addmod(e3a, p[P_GAMMA], SCALAR_FIELD_SIZE)
|
|
394
394
|
|
|
395
395
|
e3b: uint256 = uint256_addmod(
|
|
396
396
|
proof[P_EVAL_B],
|
|
397
|
-
uint256_mulmod(p[P_BETA], proof[P_EVAL_S2],
|
|
398
|
-
|
|
397
|
+
uint256_mulmod(p[P_BETA], proof[P_EVAL_S2], SCALAR_FIELD_SIZE),
|
|
398
|
+
SCALAR_FIELD_SIZE
|
|
399
399
|
)
|
|
400
|
-
e3b = uint256_addmod(e3b, p[P_GAMMA],
|
|
400
|
+
e3b = uint256_addmod(e3b, p[P_GAMMA], SCALAR_FIELD_SIZE)
|
|
401
401
|
|
|
402
|
-
e3c: uint256 = uint256_addmod(proof[P_EVAL_C], p[P_GAMMA],
|
|
402
|
+
e3c: uint256 = uint256_addmod(proof[P_EVAL_C], p[P_GAMMA], SCALAR_FIELD_SIZE)
|
|
403
403
|
|
|
404
|
-
e3: uint256 = uint256_mulmod(uint256_mulmod(e3a, e3b,
|
|
405
|
-
e3 = uint256_mulmod(e3, proof[P_EVAL_ZW],
|
|
406
|
-
e3 = uint256_mulmod(e3, p[P_ALPHA],
|
|
404
|
+
e3: uint256 = uint256_mulmod(uint256_mulmod(e3a, e3b, SCALAR_FIELD_SIZE), e3c, SCALAR_FIELD_SIZE)
|
|
405
|
+
e3 = uint256_mulmod(e3, proof[P_EVAL_ZW], SCALAR_FIELD_SIZE)
|
|
406
|
+
e3 = uint256_mulmod(e3, p[P_ALPHA], SCALAR_FIELD_SIZE)
|
|
407
407
|
|
|
408
|
-
r0: uint256 = uint256_addmod(e1,
|
|
409
|
-
return uint256_addmod(r0,
|
|
408
|
+
r0: uint256 = uint256_addmod(e1, SCALAR_FIELD_SIZE - e2, SCALAR_FIELD_SIZE)
|
|
409
|
+
return uint256_addmod(r0, SCALAR_FIELD_SIZE - e3, SCALAR_FIELD_SIZE)
|
|
410
410
|
|
|
411
411
|
|
|
412
412
|
@pure
|
|
@@ -426,7 +426,7 @@ def _calculateD(p: uint256[P_TOTAL_SIZE], proof: uint256[24]) -> (bool, uint256[
|
|
|
426
426
|
success: bool = True
|
|
427
427
|
pd: uint256[2] = [QC_X, QC_Y]
|
|
428
428
|
|
|
429
|
-
success, pd = self._g1_mulAccC(pd, [QM_X, QM_Y], uint256_mulmod(proof[P_EVAL_A], proof[P_EVAL_B],
|
|
429
|
+
success, pd = self._g1_mulAccC(pd, [QM_X, QM_Y], uint256_mulmod(proof[P_EVAL_A], proof[P_EVAL_B], SCALAR_FIELD_SIZE))
|
|
430
430
|
if not success:
|
|
431
431
|
return (False, [0, 0])
|
|
432
432
|
|
|
@@ -443,61 +443,61 @@ def _calculateD(p: uint256[P_TOTAL_SIZE], proof: uint256[24]) -> (bool, uint256[
|
|
|
443
443
|
return (False, [0, 0])
|
|
444
444
|
|
|
445
445
|
val1: uint256 = uint256_addmod(
|
|
446
|
-
uint256_addmod(proof[P_EVAL_A], p[P_BETA_XI],
|
|
446
|
+
uint256_addmod(proof[P_EVAL_A], p[P_BETA_XI], SCALAR_FIELD_SIZE),
|
|
447
447
|
p[P_GAMMA],
|
|
448
|
-
|
|
448
|
+
SCALAR_FIELD_SIZE
|
|
449
449
|
)
|
|
450
450
|
|
|
451
451
|
val2: uint256 = uint256_addmod(
|
|
452
|
-
uint256_addmod(proof[P_EVAL_B], uint256_mulmod(p[P_BETA_XI], K1,
|
|
452
|
+
uint256_addmod(proof[P_EVAL_B], uint256_mulmod(p[P_BETA_XI], K1, SCALAR_FIELD_SIZE), SCALAR_FIELD_SIZE),
|
|
453
453
|
p[P_GAMMA],
|
|
454
|
-
|
|
454
|
+
SCALAR_FIELD_SIZE
|
|
455
455
|
)
|
|
456
456
|
|
|
457
457
|
val3: uint256 = uint256_addmod(
|
|
458
|
-
uint256_addmod(proof[P_EVAL_C], uint256_mulmod(p[P_BETA_XI], K2,
|
|
458
|
+
uint256_addmod(proof[P_EVAL_C], uint256_mulmod(p[P_BETA_XI], K2, SCALAR_FIELD_SIZE), SCALAR_FIELD_SIZE),
|
|
459
459
|
p[P_GAMMA],
|
|
460
|
-
|
|
460
|
+
SCALAR_FIELD_SIZE
|
|
461
461
|
)
|
|
462
462
|
|
|
463
463
|
d2a: uint256 = uint256_mulmod(
|
|
464
|
-
uint256_mulmod(uint256_mulmod(val1, val2,
|
|
464
|
+
uint256_mulmod(uint256_mulmod(val1, val2, SCALAR_FIELD_SIZE), val3, SCALAR_FIELD_SIZE),
|
|
465
465
|
p[P_ALPHA],
|
|
466
|
-
|
|
466
|
+
SCALAR_FIELD_SIZE
|
|
467
467
|
)
|
|
468
468
|
|
|
469
|
-
d2b: uint256 = uint256_mulmod(p[P_EVAL_L1], p[P_ALPHA2],
|
|
469
|
+
d2b: uint256 = uint256_mulmod(p[P_EVAL_L1], p[P_ALPHA2], SCALAR_FIELD_SIZE)
|
|
470
470
|
|
|
471
471
|
mP: uint256[2] = [0, 0]
|
|
472
472
|
|
|
473
473
|
success, mP = self._ecmul(
|
|
474
474
|
[proof[P_Z], proof[P_Z + 1]],
|
|
475
|
-
uint256_addmod(uint256_addmod(d2a, d2b,
|
|
475
|
+
uint256_addmod(uint256_addmod(d2a, d2b, SCALAR_FIELD_SIZE), p[P_U], SCALAR_FIELD_SIZE)
|
|
476
476
|
)
|
|
477
477
|
if not success:
|
|
478
478
|
return (False, [0, 0])
|
|
479
479
|
|
|
480
480
|
val1 = uint256_addmod(
|
|
481
|
-
uint256_addmod(proof[P_EVAL_A], uint256_mulmod(p[P_BETA], proof[P_EVAL_S1],
|
|
481
|
+
uint256_addmod(proof[P_EVAL_A], uint256_mulmod(p[P_BETA], proof[P_EVAL_S1], SCALAR_FIELD_SIZE), SCALAR_FIELD_SIZE),
|
|
482
482
|
p[P_GAMMA],
|
|
483
|
-
|
|
483
|
+
SCALAR_FIELD_SIZE
|
|
484
484
|
)
|
|
485
485
|
|
|
486
486
|
val2 = uint256_addmod(
|
|
487
|
-
uint256_addmod(proof[P_EVAL_B], uint256_mulmod(p[P_BETA], proof[P_EVAL_S2],
|
|
487
|
+
uint256_addmod(proof[P_EVAL_B], uint256_mulmod(p[P_BETA], proof[P_EVAL_S2], SCALAR_FIELD_SIZE), SCALAR_FIELD_SIZE),
|
|
488
488
|
p[P_GAMMA],
|
|
489
|
-
|
|
489
|
+
SCALAR_FIELD_SIZE
|
|
490
490
|
)
|
|
491
491
|
|
|
492
492
|
val3 = uint256_mulmod(
|
|
493
|
-
uint256_mulmod(p[P_ALPHA], p[P_BETA],
|
|
493
|
+
uint256_mulmod(p[P_ALPHA], p[P_BETA], SCALAR_FIELD_SIZE),
|
|
494
494
|
proof[P_EVAL_ZW],
|
|
495
|
-
|
|
495
|
+
SCALAR_FIELD_SIZE
|
|
496
496
|
)
|
|
497
497
|
|
|
498
498
|
success, mP = self._ecmul(
|
|
499
499
|
[proof[P_Z], proof[P_Z + 1]],
|
|
500
|
-
uint256_addmod(uint256_addmod(d2a, d2b,
|
|
500
|
+
uint256_addmod(uint256_addmod(d2a, d2b, SCALAR_FIELD_SIZE), p[P_U], SCALAR_FIELD_SIZE)
|
|
501
501
|
)
|
|
502
502
|
if not success:
|
|
503
503
|
return (False, [0, 0])
|
|
@@ -508,9 +508,9 @@ def _calculateD(p: uint256[P_TOTAL_SIZE], proof: uint256[24]) -> (bool, uint256[
|
|
|
508
508
|
|
|
509
509
|
success, mP = self._ecmul(
|
|
510
510
|
[S3_X, S3_Y],
|
|
511
|
-
uint256_mulmod(uint256_mulmod(val1, val2,
|
|
511
|
+
uint256_mulmod(uint256_mulmod(val1, val2, SCALAR_FIELD_SIZE), val3, SCALAR_FIELD_SIZE)
|
|
512
512
|
)
|
|
513
|
-
mP[1] = (
|
|
513
|
+
mP[1] = (BASE_FIELD_SIZE - mP[1]) % BASE_FIELD_SIZE
|
|
514
514
|
|
|
515
515
|
success, pd = self._ecadd(pd, mP)
|
|
516
516
|
if not success:
|
|
@@ -521,13 +521,13 @@ def _calculateD(p: uint256[P_TOTAL_SIZE], proof: uint256[24]) -> (bool, uint256[
|
|
|
521
521
|
if not success:
|
|
522
522
|
return (False, [0, 0])
|
|
523
523
|
|
|
524
|
-
xin2: uint256 = uint256_mulmod(p[P_XIN], p[P_XIN],
|
|
524
|
+
xin2: uint256 = uint256_mulmod(p[P_XIN], p[P_XIN], SCALAR_FIELD_SIZE)
|
|
525
525
|
success, pd2 = self._g1_mulAccC(pd2, [proof[P_T3], proof[P_T3 + 1]], xin2)
|
|
526
526
|
if not success:
|
|
527
527
|
return (False, [0, 0])
|
|
528
528
|
|
|
529
529
|
success, mP = self._ecmul(pd2, p[P_ZH])
|
|
530
|
-
mP[1] = (
|
|
530
|
+
mP[1] = (BASE_FIELD_SIZE - mP[1]) % BASE_FIELD_SIZE
|
|
531
531
|
|
|
532
532
|
return self._ecadd(pd, mP)
|
|
533
533
|
|
|
@@ -560,14 +560,14 @@ def _calculateF(p: uint256[P_TOTAL_SIZE], proof: uint256[24]) -> (bool, uint256[
|
|
|
560
560
|
@pure
|
|
561
561
|
@internal
|
|
562
562
|
def _calculateE(p: uint256[P_TOTAL_SIZE], proof: uint256[24]) -> (bool, uint256[2]):
|
|
563
|
-
s: uint256 = (
|
|
563
|
+
s: uint256 = (SCALAR_FIELD_SIZE - p[P_EVAL_R0]) % SCALAR_FIELD_SIZE
|
|
564
564
|
|
|
565
|
-
s = uint256_addmod(s, uint256_mulmod(proof[P_EVAL_A], p[P_V1],
|
|
566
|
-
s = uint256_addmod(s, uint256_mulmod(proof[P_EVAL_B], p[P_V2],
|
|
567
|
-
s = uint256_addmod(s, uint256_mulmod(proof[P_EVAL_C], p[P_V3],
|
|
568
|
-
s = uint256_addmod(s, uint256_mulmod(proof[P_EVAL_S1], p[P_V4],
|
|
569
|
-
s = uint256_addmod(s, uint256_mulmod(proof[P_EVAL_S2], p[P_V5],
|
|
570
|
-
s = uint256_addmod(s, uint256_mulmod(proof[P_EVAL_ZW], p[P_U],
|
|
565
|
+
s = uint256_addmod(s, uint256_mulmod(proof[P_EVAL_A], p[P_V1], SCALAR_FIELD_SIZE), SCALAR_FIELD_SIZE)
|
|
566
|
+
s = uint256_addmod(s, uint256_mulmod(proof[P_EVAL_B], p[P_V2], SCALAR_FIELD_SIZE), SCALAR_FIELD_SIZE)
|
|
567
|
+
s = uint256_addmod(s, uint256_mulmod(proof[P_EVAL_C], p[P_V3], SCALAR_FIELD_SIZE), SCALAR_FIELD_SIZE)
|
|
568
|
+
s = uint256_addmod(s, uint256_mulmod(proof[P_EVAL_S1], p[P_V4], SCALAR_FIELD_SIZE), SCALAR_FIELD_SIZE)
|
|
569
|
+
s = uint256_addmod(s, uint256_mulmod(proof[P_EVAL_S2], p[P_V5], SCALAR_FIELD_SIZE), SCALAR_FIELD_SIZE)
|
|
570
|
+
s = uint256_addmod(s, uint256_mulmod(proof[P_EVAL_ZW], p[P_U], SCALAR_FIELD_SIZE), SCALAR_FIELD_SIZE)
|
|
571
571
|
|
|
572
572
|
return self._ecmul([G1_X, G1_Y], s)
|
|
573
573
|
|
|
@@ -591,7 +591,7 @@ def _checkPairing(p: uint256[P_TOTAL_SIZE], proof: uint256[24]) -> bool:
|
|
|
591
591
|
return False
|
|
592
592
|
|
|
593
593
|
mIn[0] = aP[0]
|
|
594
|
-
mIn[1] = (
|
|
594
|
+
mIn[1] = (BASE_FIELD_SIZE - aP[1]) % BASE_FIELD_SIZE
|
|
595
595
|
|
|
596
596
|
# [X]_2
|
|
597
597
|
mIn[2] = X2_X2
|
|
@@ -607,8 +607,8 @@ def _checkPairing(p: uint256[P_TOTAL_SIZE], proof: uint256[24]) -> bool:
|
|
|
607
607
|
mIn[6] = mP[0]
|
|
608
608
|
mIn[7] = mP[1]
|
|
609
609
|
|
|
610
|
-
s: uint256 = uint256_mulmod(p[P_U], p[P_XI],
|
|
611
|
-
s = uint256_mulmod(s, W1,
|
|
610
|
+
s: uint256 = uint256_mulmod(p[P_U], p[P_XI], SCALAR_FIELD_SIZE)
|
|
611
|
+
s = uint256_mulmod(s, W1, SCALAR_FIELD_SIZE)
|
|
612
612
|
|
|
613
613
|
success, mP = self._ecmul([proof[P_WX_IW], proof[P_WX_IW + 1]], s)
|
|
614
614
|
if not success:
|
|
@@ -622,7 +622,7 @@ def _checkPairing(p: uint256[P_TOTAL_SIZE], proof: uint256[24]) -> bool:
|
|
|
622
622
|
if not success:
|
|
623
623
|
return False
|
|
624
624
|
|
|
625
|
-
p[P_E + 1] = (
|
|
625
|
+
p[P_E + 1] = (BASE_FIELD_SIZE - p[P_E + 1]) % BASE_FIELD_SIZE
|
|
626
626
|
|
|
627
627
|
success, aP = self._ecadd(aP, [p[P_E], p[P_E + 1]])
|
|
628
628
|
if not success:
|
|
@@ -13,9 +13,13 @@ export interface Groth16ProofStruct {
|
|
|
13
13
|
publicSignals: PublicSignals;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
export interface Groth16CalldataStruct {
|
|
17
|
+
proofPoints: Groth16ProofPoints;
|
|
18
|
+
publicSignals: PublicSignals;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface Groth16ProofPoints {
|
|
22
|
+
a: [NumericString, NumericString];
|
|
23
|
+
b: [[NumericString, NumericString], [NumericString, NumericString]];
|
|
24
|
+
c: [NumericString, NumericString];
|
|
25
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Groth16ProofStruct,
|
|
2
|
-
import { PlonkProofStruct,
|
|
1
|
+
import { Groth16ProofStruct, Groth16CalldataStruct } from "./groth16";
|
|
2
|
+
import { PlonkProofStruct, PlonkCalldataStruct } from "./plonk";
|
|
3
3
|
|
|
4
4
|
import { Signals } from "../proof-utils";
|
|
5
5
|
import { VerifierLanguageType } from "../circuit-zkit";
|
|
@@ -34,15 +34,15 @@ export interface IProtocolImplementer<T extends ProvingSystemType> {
|
|
|
34
34
|
export interface ProvingSystemStructMap {
|
|
35
35
|
groth16: {
|
|
36
36
|
proofStruct: Groth16ProofStruct;
|
|
37
|
-
|
|
37
|
+
calldataStruct: Groth16CalldataStruct;
|
|
38
38
|
};
|
|
39
39
|
plonk: {
|
|
40
40
|
proofStruct: PlonkProofStruct;
|
|
41
|
-
|
|
41
|
+
calldataStruct: PlonkCalldataStruct;
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
export type ProvingSystemType = keyof ProvingSystemStructMap;
|
|
46
46
|
|
|
47
47
|
export type ProofStructByProtocol<T extends ProvingSystemType> = ProvingSystemStructMap[T]["proofStruct"];
|
|
48
|
-
export type CalldataByProtocol<T extends ProvingSystemType> = ProvingSystemStructMap[T]["
|
|
48
|
+
export type CalldataByProtocol<T extends ProvingSystemType> = ProvingSystemStructMap[T]["calldataStruct"];
|