@solarity/zkit 0.3.0-rc.0 → 0.3.0-rc.1
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/core/templates/verifier_groth16.vy.ejs +3 -3
- package/dist/core/templates/verifier_plonk.sol.ejs +534 -436
- package/dist/core/templates/verifier_plonk.vy.ejs +92 -92
- package/package.json +1 -1
- package/src/core/templates/verifier_groth16.vy.ejs +3 -3
- package/src/core/templates/verifier_plonk.sol.ejs +534 -436
- package/src/core/templates/verifier_plonk.vy.ejs +92 -92
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
# Omega
|
|
6
6
|
W1: constant(uint256) = <%=w%>
|
|
7
7
|
# Scalar field size
|
|
8
|
-
|
|
8
|
+
SCALAR_SIZE: constant(uint256) = 21888242871839275222246405745257275088548364400416034343698204186575808495617
|
|
9
9
|
# Base field size
|
|
10
|
-
|
|
10
|
+
BASE_SIZE: constant(uint256) = 21888242871839275222246405745257275088696311157297823662689037894645226208583
|
|
11
11
|
|
|
12
12
|
# [1]_1
|
|
13
13
|
G1_X: constant(uint256) = 1
|
|
@@ -94,7 +94,7 @@ P_ZH_INV: constant(uint256) = 24
|
|
|
94
94
|
|
|
95
95
|
P_EVAL_L1: constant(uint256) = 25
|
|
96
96
|
|
|
97
|
-
P_TOTAL_SIZE: constant(uint256) = <%=25+nPublic%>
|
|
97
|
+
P_TOTAL_SIZE: constant(uint256) = <%=25 + nPublic%>
|
|
98
98
|
|
|
99
99
|
EC_ADD_PRECOMPILED_ADDRESS: constant(address) = 0x0000000000000000000000000000000000000006
|
|
100
100
|
EC_MUL_PRECOMPILED_ADDRESS: constant(address) = 0x0000000000000000000000000000000000000007
|
|
@@ -218,20 +218,20 @@ def _inverse(a: uint256, q: uint256) -> uint256:
|
|
|
218
218
|
|
|
219
219
|
@pure
|
|
220
220
|
@internal
|
|
221
|
-
def _inverseArray(pVals: uint256[<%=nPublic+1%>]) -> uint256[<%=nPublic+1%>]:
|
|
221
|
+
def _inverseArray(pVals: uint256[<%=nPublic + 1%>]) -> uint256[<%=nPublic + 1%>]:
|
|
222
222
|
acc: uint256 = pVals[0]
|
|
223
|
-
inverses: uint256[<%=nPublic+1%>] = empty(uint256[<%=nPublic+1%>])
|
|
224
|
-
pAux: uint256[<%=nPublic+1%>] = empty(uint256[<%=nPublic+1%>])
|
|
223
|
+
inverses: uint256[<%=nPublic + 1%>] = empty(uint256[<%=nPublic + 1%>])
|
|
224
|
+
pAux: uint256[<%=nPublic + 1%>] = empty(uint256[<%=nPublic + 1%>])
|
|
225
225
|
|
|
226
|
-
for i: uint256 in range(1, <%=nPublic+1%>):
|
|
226
|
+
for i: uint256 in range(1, <%=nPublic + 1%>):
|
|
227
227
|
pAux[i] = acc
|
|
228
|
-
acc = uint256_mulmod(acc, pVals[i],
|
|
228
|
+
acc = uint256_mulmod(acc, pVals[i], SCALAR_SIZE)
|
|
229
229
|
|
|
230
|
-
inv_total: uint256 = self._inverse(acc,
|
|
230
|
+
inv_total: uint256 = self._inverse(acc, SCALAR_SIZE)
|
|
231
231
|
|
|
232
232
|
for i: uint256 in range(<%=nPublic%>):
|
|
233
|
-
inverses[<%=nPublic%> - i] = uint256_mulmod(inv_total, pAux[<%=nPublic%> - i],
|
|
234
|
-
inv_total = uint256_mulmod(inv_total, pVals[<%=nPublic%> - i],
|
|
233
|
+
inverses[<%=nPublic%> - i] = uint256_mulmod(inv_total, pAux[<%=nPublic%> - i], SCALAR_SIZE)
|
|
234
|
+
inv_total = uint256_mulmod(inv_total, pVals[<%=nPublic%> - i], SCALAR_SIZE)
|
|
235
235
|
|
|
236
236
|
inverses[0] = inv_total
|
|
237
237
|
|
|
@@ -241,22 +241,22 @@ def _inverseArray(pVals: uint256[<%=nPublic+1%>]) -> uint256[<%=nPublic+1%>]:
|
|
|
241
241
|
@pure
|
|
242
242
|
@internal
|
|
243
243
|
def _checkInput(proof: uint256[24]) -> bool:
|
|
244
|
-
if proof[P_EVAL_A] >=
|
|
244
|
+
if proof[P_EVAL_A] >= SCALAR_SIZE:
|
|
245
245
|
return False
|
|
246
246
|
|
|
247
|
-
if proof[P_EVAL_B] >=
|
|
247
|
+
if proof[P_EVAL_B] >= SCALAR_SIZE:
|
|
248
248
|
return False
|
|
249
249
|
|
|
250
|
-
if proof[P_EVAL_C] >=
|
|
250
|
+
if proof[P_EVAL_C] >= SCALAR_SIZE:
|
|
251
251
|
return False
|
|
252
252
|
|
|
253
|
-
if proof[P_EVAL_S1] >=
|
|
253
|
+
if proof[P_EVAL_S1] >= SCALAR_SIZE:
|
|
254
254
|
return False
|
|
255
255
|
|
|
256
|
-
if proof[P_EVAL_S2] >=
|
|
256
|
+
if proof[P_EVAL_S2] >= SCALAR_SIZE:
|
|
257
257
|
return False
|
|
258
258
|
|
|
259
|
-
if proof[P_EVAL_ZW] >=
|
|
259
|
+
if proof[P_EVAL_ZW] >= SCALAR_SIZE:
|
|
260
260
|
return False
|
|
261
261
|
|
|
262
262
|
return True
|
|
@@ -265,60 +265,60 @@ def _checkInput(proof: uint256[24]) -> bool:
|
|
|
265
265
|
@pure
|
|
266
266
|
@internal
|
|
267
267
|
def _calculateChallenges(proof: uint256[24], pubSignals: uint256[<%=nPublic%>]) -> uint256[P_TOTAL_SIZE]:
|
|
268
|
-
mIn<%=22+nPublic%>: uint256[<%=22+nPublic%>] = [
|
|
268
|
+
mIn<%=22 + nPublic%>: uint256[<%=22 + nPublic%>] = [
|
|
269
269
|
QM_X, QM_Y, QL_X, QL_Y, QR_X, QR_Y, QO_X, QO_Y, QC_X, QC_Y, S1_X, S1_Y, S2_X, S2_Y, S3_X, S3_Y,
|
|
270
270
|
<% for (let i = 0; i < nPublic; i++) { %>pubSignals[<%=i%>], <% } %>
|
|
271
271
|
proof[P_A], proof[P_A + 1], proof[P_B], proof[P_B + 1], proof[P_C], proof[P_C + 1],
|
|
272
272
|
]
|
|
273
273
|
|
|
274
|
-
beta: uint256 = convert(keccak256(abi_encode(mIn<%=22+nPublic%>)), uint256) %
|
|
274
|
+
beta: uint256 = convert(keccak256(abi_encode(mIn<%=22+nPublic%>)), uint256) % SCALAR_SIZE
|
|
275
275
|
|
|
276
276
|
p: uint256[P_TOTAL_SIZE] = empty(uint256[P_TOTAL_SIZE])
|
|
277
277
|
p[P_BETA] = beta
|
|
278
278
|
|
|
279
279
|
# challenges.gamma
|
|
280
|
-
p[P_GAMMA] = convert(keccak256(abi_encode(p[P_BETA])), uint256) %
|
|
280
|
+
p[P_GAMMA] = convert(keccak256(abi_encode(p[P_BETA])), uint256) % SCALAR_SIZE
|
|
281
281
|
|
|
282
282
|
# challenges.alpha
|
|
283
283
|
mIn4: uint256[4] = [beta, p[P_GAMMA], proof[P_Z], proof[P_Z + 1]]
|
|
284
|
-
aux: uint256 = convert(keccak256(abi_encode(mIn4)), uint256) %
|
|
284
|
+
aux: uint256 = convert(keccak256(abi_encode(mIn4)), uint256) % SCALAR_SIZE
|
|
285
285
|
p[P_ALPHA] = aux
|
|
286
|
-
p[P_ALPHA2] = uint256_mulmod(aux, aux,
|
|
286
|
+
p[P_ALPHA2] = uint256_mulmod(aux, aux, SCALAR_SIZE)
|
|
287
287
|
|
|
288
288
|
# challenges.xi
|
|
289
289
|
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]]
|
|
290
|
-
aux = convert(keccak256(abi_encode(mIn7)), uint256) %
|
|
290
|
+
aux = convert(keccak256(abi_encode(mIn7)), uint256) % SCALAR_SIZE
|
|
291
291
|
p[P_XI] = aux
|
|
292
292
|
|
|
293
293
|
# challenges.v
|
|
294
294
|
mIn7 = [
|
|
295
295
|
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]
|
|
296
296
|
]
|
|
297
|
-
v1: uint256 = convert(keccak256(abi_encode(mIn7)), uint256) %
|
|
297
|
+
v1: uint256 = convert(keccak256(abi_encode(mIn7)), uint256) % SCALAR_SIZE
|
|
298
298
|
p[P_V1] = v1
|
|
299
299
|
|
|
300
300
|
# challenges.v^2, challenges.v^3, challenges.v^4, challenges.v^5
|
|
301
|
-
p[P_V2] = uint256_mulmod(v1, v1,
|
|
302
|
-
p[P_V3] = uint256_mulmod(p[P_V2], v1,
|
|
303
|
-
p[P_V4] = uint256_mulmod(p[P_V3], v1,
|
|
304
|
-
p[P_V5] = uint256_mulmod(p[P_V4], v1,
|
|
301
|
+
p[P_V2] = uint256_mulmod(v1, v1, SCALAR_SIZE)
|
|
302
|
+
p[P_V3] = uint256_mulmod(p[P_V2], v1, SCALAR_SIZE)
|
|
303
|
+
p[P_V4] = uint256_mulmod(p[P_V3], v1, SCALAR_SIZE)
|
|
304
|
+
p[P_V5] = uint256_mulmod(p[P_V4], v1, SCALAR_SIZE)
|
|
305
305
|
|
|
306
306
|
# challenges.beta * challenges.xi
|
|
307
|
-
p[P_BETA_XI] = uint256_mulmod(beta, aux,
|
|
307
|
+
p[P_BETA_XI] = uint256_mulmod(beta, aux, SCALAR_SIZE)
|
|
308
308
|
|
|
309
309
|
# challenges.xi^n
|
|
310
|
-
<%for (let i=0; i<power;i++) {%>
|
|
311
|
-
aux = uint256_mulmod(aux, aux,
|
|
310
|
+
<%for (let i = 0; i < power; i++) {%>
|
|
311
|
+
aux = uint256_mulmod(aux, aux, SCALAR_SIZE)<% } %>
|
|
312
312
|
p[P_XIN] = aux
|
|
313
313
|
|
|
314
314
|
# Zh
|
|
315
|
-
aux = (aux - 1
|
|
315
|
+
aux = uint256_addmod(aux, SCALAR_SIZE - 1, SCALAR_SIZE)
|
|
316
316
|
p[P_ZH] = aux
|
|
317
317
|
p[P_ZH_INV] = aux
|
|
318
318
|
|
|
319
319
|
# challenges.u
|
|
320
320
|
mIn4 = [proof[P_WX_I], proof[P_WX_I + 1], proof[P_WX_IW], proof[P_WX_IW + 1]]
|
|
321
|
-
p[P_U] = convert(keccak256(abi_encode(mIn4)), uint256) %
|
|
321
|
+
p[P_U] = convert(keccak256(abi_encode(mIn4)), uint256) % SCALAR_SIZE
|
|
322
322
|
|
|
323
323
|
return p
|
|
324
324
|
|
|
@@ -326,7 +326,7 @@ def _calculateChallenges(proof: uint256[24], pubSignals: uint256[<%=nPublic%>])
|
|
|
326
326
|
@pure
|
|
327
327
|
@internal
|
|
328
328
|
def _evaluateLagrange(w: uint256, xi: uint256) -> uint256:
|
|
329
|
-
return uint256_mulmod(N, uint256_addmod(xi,
|
|
329
|
+
return uint256_mulmod(N, uint256_addmod(xi, SCALAR_SIZE - w, SCALAR_SIZE), SCALAR_SIZE)
|
|
330
330
|
|
|
331
331
|
|
|
332
332
|
@pure
|
|
@@ -334,29 +334,29 @@ def _evaluateLagrange(w: uint256, xi: uint256) -> uint256:
|
|
|
334
334
|
def _calculateLagrange(p: uint256[P_TOTAL_SIZE]) -> uint256[P_TOTAL_SIZE]:
|
|
335
335
|
w: uint256 = 1
|
|
336
336
|
|
|
337
|
-
for i: uint256 in range(1, <%=nPublic+1%>):
|
|
337
|
+
for i: uint256 in range(1, <%=nPublic + 1%>):
|
|
338
338
|
p[P_EVAL_L1 + (i - 1)] = self._evaluateLagrange(w, p[P_XI])
|
|
339
|
-
w = uint256_mulmod(w, W1,
|
|
339
|
+
w = uint256_mulmod(w, W1, SCALAR_SIZE)
|
|
340
340
|
|
|
341
|
-
pointsToInverse: uint256[<%=nPublic+1%>] = empty(uint256[<%=nPublic+1%>])
|
|
342
|
-
for i: uint256 in range(<%=nPublic+1%>):
|
|
341
|
+
pointsToInverse: uint256[<%=nPublic + 1%>] = empty(uint256[<%=nPublic + 1%>])
|
|
342
|
+
for i: uint256 in range(<%=nPublic + 1%>):
|
|
343
343
|
pointsToInverse[i] = p[P_ZH_INV + i]
|
|
344
344
|
|
|
345
|
-
inverses: uint256[<%=nPublic+1%>] = self._inverseArray(pointsToInverse)
|
|
345
|
+
inverses: uint256[<%=nPublic + 1%>] = self._inverseArray(pointsToInverse)
|
|
346
346
|
|
|
347
|
-
for i: uint256 in range(<%=nPublic+1%>):
|
|
347
|
+
for i: uint256 in range(<%=nPublic + 1%>):
|
|
348
348
|
p[P_ZH_INV + i] = inverses[i]
|
|
349
349
|
|
|
350
350
|
zh: uint256 = p[P_ZH]
|
|
351
351
|
w = 1
|
|
352
352
|
|
|
353
|
-
for i: uint256 in range(1, <%=nPublic+1%>):
|
|
353
|
+
for i: uint256 in range(1, <%=nPublic + 1%>):
|
|
354
354
|
p[P_EVAL_L1 + (i - 1)] = uint256_mulmod(
|
|
355
|
-
uint256_mulmod(p[P_EVAL_L1 + (i - 1)], zh,
|
|
355
|
+
uint256_mulmod(p[P_EVAL_L1 + (i - 1)], zh, SCALAR_SIZE),
|
|
356
356
|
w,
|
|
357
|
-
|
|
357
|
+
SCALAR_SIZE
|
|
358
358
|
)
|
|
359
|
-
w = uint256_mulmod(w, W1,
|
|
359
|
+
w = uint256_mulmod(w, W1, SCALAR_SIZE)
|
|
360
360
|
|
|
361
361
|
return p
|
|
362
362
|
|
|
@@ -369,8 +369,8 @@ def _calculatePI(p: uint256[P_TOTAL_SIZE], pPub: uint256[<%=nPublic%>]) -> uint2
|
|
|
369
369
|
for i: uint256 in range(<%=nPublic%>):
|
|
370
370
|
pl = uint256_addmod(
|
|
371
371
|
pl,
|
|
372
|
-
|
|
373
|
-
|
|
372
|
+
SCALAR_SIZE - uint256_mulmod(p[P_EVAL_L1 + i], pPub[i], SCALAR_SIZE),
|
|
373
|
+
SCALAR_SIZE
|
|
374
374
|
)
|
|
375
375
|
|
|
376
376
|
return pl
|
|
@@ -381,30 +381,30 @@ def _calculatePI(p: uint256[P_TOTAL_SIZE], pPub: uint256[<%=nPublic%>]) -> uint2
|
|
|
381
381
|
def _calculateR0(p: uint256[P_TOTAL_SIZE], proof: uint256[24]) -> uint256:
|
|
382
382
|
e1: uint256 = p[P_PI]
|
|
383
383
|
|
|
384
|
-
e2: uint256 = uint256_mulmod(p[P_EVAL_L1], p[P_ALPHA2],
|
|
384
|
+
e2: uint256 = uint256_mulmod(p[P_EVAL_L1], p[P_ALPHA2], SCALAR_SIZE)
|
|
385
385
|
|
|
386
386
|
e3a: uint256 = uint256_addmod(
|
|
387
387
|
proof[P_EVAL_A],
|
|
388
|
-
uint256_mulmod(p[P_BETA], proof[P_EVAL_S1],
|
|
389
|
-
|
|
388
|
+
uint256_mulmod(p[P_BETA], proof[P_EVAL_S1], SCALAR_SIZE),
|
|
389
|
+
SCALAR_SIZE
|
|
390
390
|
)
|
|
391
|
-
e3a = uint256_addmod(e3a, p[P_GAMMA],
|
|
391
|
+
e3a = uint256_addmod(e3a, p[P_GAMMA], SCALAR_SIZE)
|
|
392
392
|
|
|
393
393
|
e3b: uint256 = uint256_addmod(
|
|
394
394
|
proof[P_EVAL_B],
|
|
395
|
-
uint256_mulmod(p[P_BETA], proof[P_EVAL_S2],
|
|
396
|
-
|
|
395
|
+
uint256_mulmod(p[P_BETA], proof[P_EVAL_S2], SCALAR_SIZE),
|
|
396
|
+
SCALAR_SIZE
|
|
397
397
|
)
|
|
398
|
-
e3b = uint256_addmod(e3b, p[P_GAMMA],
|
|
398
|
+
e3b = uint256_addmod(e3b, p[P_GAMMA], SCALAR_SIZE)
|
|
399
399
|
|
|
400
|
-
e3c: uint256 = uint256_addmod(proof[P_EVAL_C], p[P_GAMMA],
|
|
400
|
+
e3c: uint256 = uint256_addmod(proof[P_EVAL_C], p[P_GAMMA], SCALAR_SIZE)
|
|
401
401
|
|
|
402
|
-
e3: uint256 = uint256_mulmod(uint256_mulmod(e3a, e3b,
|
|
403
|
-
e3 = uint256_mulmod(e3, proof[P_EVAL_ZW],
|
|
404
|
-
e3 = uint256_mulmod(e3, p[P_ALPHA],
|
|
402
|
+
e3: uint256 = uint256_mulmod(uint256_mulmod(e3a, e3b, SCALAR_SIZE), e3c, SCALAR_SIZE)
|
|
403
|
+
e3 = uint256_mulmod(e3, proof[P_EVAL_ZW], SCALAR_SIZE)
|
|
404
|
+
e3 = uint256_mulmod(e3, p[P_ALPHA], SCALAR_SIZE)
|
|
405
405
|
|
|
406
|
-
r0: uint256 = uint256_addmod(e1,
|
|
407
|
-
return uint256_addmod(r0,
|
|
406
|
+
r0: uint256 = uint256_addmod(e1, SCALAR_SIZE - e2, SCALAR_SIZE)
|
|
407
|
+
return uint256_addmod(r0, SCALAR_SIZE - e3, SCALAR_SIZE)
|
|
408
408
|
|
|
409
409
|
|
|
410
410
|
@pure
|
|
@@ -424,7 +424,7 @@ def _calculateD(p: uint256[P_TOTAL_SIZE], proof: uint256[24]) -> (bool, uint256[
|
|
|
424
424
|
success: bool = True
|
|
425
425
|
pd: uint256[2] = [QC_X, QC_Y]
|
|
426
426
|
|
|
427
|
-
success, pd = self._g1_mulAccC(pd, [QM_X, QM_Y], uint256_mulmod(proof[P_EVAL_A], proof[P_EVAL_B],
|
|
427
|
+
success, pd = self._g1_mulAccC(pd, [QM_X, QM_Y], uint256_mulmod(proof[P_EVAL_A], proof[P_EVAL_B], SCALAR_SIZE))
|
|
428
428
|
if not success:
|
|
429
429
|
return (False, [0, 0])
|
|
430
430
|
|
|
@@ -441,61 +441,61 @@ def _calculateD(p: uint256[P_TOTAL_SIZE], proof: uint256[24]) -> (bool, uint256[
|
|
|
441
441
|
return (False, [0, 0])
|
|
442
442
|
|
|
443
443
|
val1: uint256 = uint256_addmod(
|
|
444
|
-
uint256_addmod(proof[P_EVAL_A], p[P_BETA_XI],
|
|
444
|
+
uint256_addmod(proof[P_EVAL_A], p[P_BETA_XI], SCALAR_SIZE),
|
|
445
445
|
p[P_GAMMA],
|
|
446
|
-
|
|
446
|
+
SCALAR_SIZE
|
|
447
447
|
)
|
|
448
448
|
|
|
449
449
|
val2: uint256 = uint256_addmod(
|
|
450
|
-
uint256_addmod(proof[P_EVAL_B], uint256_mulmod(p[P_BETA_XI], K1,
|
|
450
|
+
uint256_addmod(proof[P_EVAL_B], uint256_mulmod(p[P_BETA_XI], K1, SCALAR_SIZE), SCALAR_SIZE),
|
|
451
451
|
p[P_GAMMA],
|
|
452
|
-
|
|
452
|
+
SCALAR_SIZE
|
|
453
453
|
)
|
|
454
454
|
|
|
455
455
|
val3: uint256 = uint256_addmod(
|
|
456
|
-
uint256_addmod(proof[P_EVAL_C], uint256_mulmod(p[P_BETA_XI], K2,
|
|
456
|
+
uint256_addmod(proof[P_EVAL_C], uint256_mulmod(p[P_BETA_XI], K2, SCALAR_SIZE), SCALAR_SIZE),
|
|
457
457
|
p[P_GAMMA],
|
|
458
|
-
|
|
458
|
+
SCALAR_SIZE
|
|
459
459
|
)
|
|
460
460
|
|
|
461
461
|
d2a: uint256 = uint256_mulmod(
|
|
462
|
-
uint256_mulmod(uint256_mulmod(val1, val2,
|
|
462
|
+
uint256_mulmod(uint256_mulmod(val1, val2, SCALAR_SIZE), val3, SCALAR_SIZE),
|
|
463
463
|
p[P_ALPHA],
|
|
464
|
-
|
|
464
|
+
SCALAR_SIZE
|
|
465
465
|
)
|
|
466
466
|
|
|
467
|
-
d2b: uint256 = uint256_mulmod(p[P_EVAL_L1], p[P_ALPHA2],
|
|
467
|
+
d2b: uint256 = uint256_mulmod(p[P_EVAL_L1], p[P_ALPHA2], SCALAR_SIZE)
|
|
468
468
|
|
|
469
469
|
mP: uint256[2] = [0, 0]
|
|
470
470
|
|
|
471
471
|
success, mP = self._ecmul(
|
|
472
472
|
[proof[P_Z], proof[P_Z + 1]],
|
|
473
|
-
uint256_addmod(uint256_addmod(d2a, d2b,
|
|
473
|
+
uint256_addmod(uint256_addmod(d2a, d2b, SCALAR_SIZE), p[P_U], SCALAR_SIZE)
|
|
474
474
|
)
|
|
475
475
|
if not success:
|
|
476
476
|
return (False, [0, 0])
|
|
477
477
|
|
|
478
478
|
val1 = uint256_addmod(
|
|
479
|
-
uint256_addmod(proof[P_EVAL_A], uint256_mulmod(p[P_BETA], proof[P_EVAL_S1],
|
|
479
|
+
uint256_addmod(proof[P_EVAL_A], uint256_mulmod(p[P_BETA], proof[P_EVAL_S1], SCALAR_SIZE), SCALAR_SIZE),
|
|
480
480
|
p[P_GAMMA],
|
|
481
|
-
|
|
481
|
+
SCALAR_SIZE
|
|
482
482
|
)
|
|
483
483
|
|
|
484
484
|
val2 = uint256_addmod(
|
|
485
|
-
uint256_addmod(proof[P_EVAL_B], uint256_mulmod(p[P_BETA], proof[P_EVAL_S2],
|
|
485
|
+
uint256_addmod(proof[P_EVAL_B], uint256_mulmod(p[P_BETA], proof[P_EVAL_S2], SCALAR_SIZE), SCALAR_SIZE),
|
|
486
486
|
p[P_GAMMA],
|
|
487
|
-
|
|
487
|
+
SCALAR_SIZE
|
|
488
488
|
)
|
|
489
489
|
|
|
490
490
|
val3 = uint256_mulmod(
|
|
491
|
-
uint256_mulmod(p[P_ALPHA], p[P_BETA],
|
|
491
|
+
uint256_mulmod(p[P_ALPHA], p[P_BETA], SCALAR_SIZE),
|
|
492
492
|
proof[P_EVAL_ZW],
|
|
493
|
-
|
|
493
|
+
SCALAR_SIZE
|
|
494
494
|
)
|
|
495
495
|
|
|
496
496
|
success, mP = self._ecmul(
|
|
497
497
|
[proof[P_Z], proof[P_Z + 1]],
|
|
498
|
-
uint256_addmod(uint256_addmod(d2a, d2b,
|
|
498
|
+
uint256_addmod(uint256_addmod(d2a, d2b, SCALAR_SIZE), p[P_U], SCALAR_SIZE)
|
|
499
499
|
)
|
|
500
500
|
if not success:
|
|
501
501
|
return (False, [0, 0])
|
|
@@ -506,9 +506,9 @@ def _calculateD(p: uint256[P_TOTAL_SIZE], proof: uint256[24]) -> (bool, uint256[
|
|
|
506
506
|
|
|
507
507
|
success, mP = self._ecmul(
|
|
508
508
|
[S3_X, S3_Y],
|
|
509
|
-
uint256_mulmod(uint256_mulmod(val1, val2,
|
|
509
|
+
uint256_mulmod(uint256_mulmod(val1, val2, SCALAR_SIZE), val3, SCALAR_SIZE)
|
|
510
510
|
)
|
|
511
|
-
mP[1] = (
|
|
511
|
+
mP[1] = (BASE_SIZE - mP[1]) % BASE_SIZE
|
|
512
512
|
|
|
513
513
|
success, pd = self._ecadd(pd, mP)
|
|
514
514
|
if not success:
|
|
@@ -519,13 +519,13 @@ def _calculateD(p: uint256[P_TOTAL_SIZE], proof: uint256[24]) -> (bool, uint256[
|
|
|
519
519
|
if not success:
|
|
520
520
|
return (False, [0, 0])
|
|
521
521
|
|
|
522
|
-
xin2: uint256 = uint256_mulmod(p[P_XIN], p[P_XIN],
|
|
522
|
+
xin2: uint256 = uint256_mulmod(p[P_XIN], p[P_XIN], SCALAR_SIZE)
|
|
523
523
|
success, pd2 = self._g1_mulAccC(pd2, [proof[P_T3], proof[P_T3 + 1]], xin2)
|
|
524
524
|
if not success:
|
|
525
525
|
return (False, [0, 0])
|
|
526
526
|
|
|
527
527
|
success, mP = self._ecmul(pd2, p[P_ZH])
|
|
528
|
-
mP[1] = (
|
|
528
|
+
mP[1] = (BASE_SIZE - mP[1]) % BASE_SIZE
|
|
529
529
|
|
|
530
530
|
return self._ecadd(pd, mP)
|
|
531
531
|
|
|
@@ -558,14 +558,14 @@ def _calculateF(p: uint256[P_TOTAL_SIZE], proof: uint256[24]) -> (bool, uint256[
|
|
|
558
558
|
@pure
|
|
559
559
|
@internal
|
|
560
560
|
def _calculateE(p: uint256[P_TOTAL_SIZE], proof: uint256[24]) -> (bool, uint256[2]):
|
|
561
|
-
s: uint256 = (
|
|
561
|
+
s: uint256 = (SCALAR_SIZE - p[P_EVAL_R0]) % SCALAR_SIZE
|
|
562
562
|
|
|
563
|
-
s = uint256_addmod(s, uint256_mulmod(proof[P_EVAL_A], p[P_V1],
|
|
564
|
-
s = uint256_addmod(s, uint256_mulmod(proof[P_EVAL_B], p[P_V2],
|
|
565
|
-
s = uint256_addmod(s, uint256_mulmod(proof[P_EVAL_C], p[P_V3],
|
|
566
|
-
s = uint256_addmod(s, uint256_mulmod(proof[P_EVAL_S1], p[P_V4],
|
|
567
|
-
s = uint256_addmod(s, uint256_mulmod(proof[P_EVAL_S2], p[P_V5],
|
|
568
|
-
s = uint256_addmod(s, uint256_mulmod(proof[P_EVAL_ZW], p[P_U],
|
|
563
|
+
s = uint256_addmod(s, uint256_mulmod(proof[P_EVAL_A], p[P_V1], SCALAR_SIZE), SCALAR_SIZE)
|
|
564
|
+
s = uint256_addmod(s, uint256_mulmod(proof[P_EVAL_B], p[P_V2], SCALAR_SIZE), SCALAR_SIZE)
|
|
565
|
+
s = uint256_addmod(s, uint256_mulmod(proof[P_EVAL_C], p[P_V3], SCALAR_SIZE), SCALAR_SIZE)
|
|
566
|
+
s = uint256_addmod(s, uint256_mulmod(proof[P_EVAL_S1], p[P_V4], SCALAR_SIZE), SCALAR_SIZE)
|
|
567
|
+
s = uint256_addmod(s, uint256_mulmod(proof[P_EVAL_S2], p[P_V5], SCALAR_SIZE), SCALAR_SIZE)
|
|
568
|
+
s = uint256_addmod(s, uint256_mulmod(proof[P_EVAL_ZW], p[P_U], SCALAR_SIZE), SCALAR_SIZE)
|
|
569
569
|
|
|
570
570
|
return self._ecmul([G1_X, G1_Y], s)
|
|
571
571
|
|
|
@@ -589,7 +589,7 @@ def _checkPairing(p: uint256[P_TOTAL_SIZE], proof: uint256[24]) -> bool:
|
|
|
589
589
|
return False
|
|
590
590
|
|
|
591
591
|
mIn[0] = aP[0]
|
|
592
|
-
mIn[1] = (
|
|
592
|
+
mIn[1] = (BASE_SIZE - aP[1]) % BASE_SIZE
|
|
593
593
|
|
|
594
594
|
# [X]_2
|
|
595
595
|
mIn[2] = X2_X2
|
|
@@ -605,8 +605,8 @@ def _checkPairing(p: uint256[P_TOTAL_SIZE], proof: uint256[24]) -> bool:
|
|
|
605
605
|
mIn[6] = mP[0]
|
|
606
606
|
mIn[7] = mP[1]
|
|
607
607
|
|
|
608
|
-
s: uint256 = uint256_mulmod(p[P_U], p[P_XI],
|
|
609
|
-
s = uint256_mulmod(s, W1,
|
|
608
|
+
s: uint256 = uint256_mulmod(p[P_U], p[P_XI], SCALAR_SIZE)
|
|
609
|
+
s = uint256_mulmod(s, W1, SCALAR_SIZE)
|
|
610
610
|
|
|
611
611
|
success, mP = self._ecmul([proof[P_WX_IW], proof[P_WX_IW + 1]], s)
|
|
612
612
|
if not success:
|
|
@@ -620,7 +620,7 @@ def _checkPairing(p: uint256[P_TOTAL_SIZE], proof: uint256[24]) -> bool:
|
|
|
620
620
|
if not success:
|
|
621
621
|
return False
|
|
622
622
|
|
|
623
|
-
p[P_E + 1] = (
|
|
623
|
+
p[P_E + 1] = (BASE_SIZE - p[P_E + 1]) % BASE_SIZE
|
|
624
624
|
|
|
625
625
|
success, aP = self._ecadd(aP, [p[P_E], p[P_E + 1]])
|
|
626
626
|
if not success:
|
package/package.json
CHANGED
|
@@ -22,7 +22,7 @@ DELTA_Y1: constant(uint256) = <%=vk_delta_2[1][1]%>
|
|
|
22
22
|
DELTA_Y2: constant(uint256) = <%=vk_delta_2[1][0] -%>
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
IC: constant(uint256[<%=IC.length%>]
|
|
25
|
+
IC: constant(uint256[2][<%=IC.length%>]) = [
|
|
26
26
|
<% IC.forEach(function(innerArray, index) { %> [
|
|
27
27
|
<%= innerArray[0] %>,
|
|
28
28
|
<%= innerArray[1] %>
|
|
@@ -36,7 +36,7 @@ EC_PAIRING_PRECOMPILED_ADDRESS: constant(address) = 0x00000000000000000000000000
|
|
|
36
36
|
|
|
37
37
|
@view
|
|
38
38
|
@external
|
|
39
|
-
def verifyProof(pointA: uint256[2], pointB: uint256[2][2], pointC: uint256[2], publicSignals: uint256[<%=IC.length-1%>]) -> bool:
|
|
39
|
+
def verifyProof(pointA: uint256[2], pointB: uint256[2][2], pointC: uint256[2], publicSignals: uint256[<%=IC.length - 1%>]) -> bool:
|
|
40
40
|
# @dev check that all public signals are in F
|
|
41
41
|
for signal: uint256 in publicSignals:
|
|
42
42
|
if signal >= BASE_FIELD_SIZE:
|
|
@@ -84,7 +84,7 @@ def _g1MulAdd(pR: uint256[2], pP: uint256[2], s: uint256) -> (bool, uint256[2]):
|
|
|
84
84
|
|
|
85
85
|
@view
|
|
86
86
|
@internal
|
|
87
|
-
def _checkPairing(pA: uint256[2], pB: uint256[2][2], pC: uint256[2], pubSignals: uint256[<%=IC.length-1%>]) -> bool:
|
|
87
|
+
def _checkPairing(pA: uint256[2], pB: uint256[2][2], pC: uint256[2], pubSignals: uint256[<%=IC.length - 1%>]) -> bool:
|
|
88
88
|
success: bool = True
|
|
89
89
|
mulAddResult: uint256[2] = IC[0]
|
|
90
90
|
|