Skip to content

Commit

Permalink
Fix vyper verifier (#15)
Browse files Browse the repository at this point in the history
* fix + pretty

* version
  • Loading branch information
Arvolear authored Oct 19, 2024
1 parent 1074fe2 commit b27544a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@solarity/zkit",
"version": "0.3.0-rc.0",
"version": "0.3.0-rc.1",
"license": "MIT",
"author": "Distributed Lab",
"readme": "README.md",
Expand Down
6 changes: 3 additions & 3 deletions src/core/templates/verifier_groth16.vy.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ DELTA_Y1: constant(uint256) = <%=vk_delta_2[1][1]%>
DELTA_Y2: constant(uint256) = <%=vk_delta_2[1][0] -%>


IC: constant(uint256[<%=IC.length%>][2]) = [
IC: constant(uint256[2][<%=IC.length%>]) = [
<% IC.forEach(function(innerArray, index) { %> [
<%= innerArray[0] %>,
<%= innerArray[1] %>
Expand All @@ -36,7 +36,7 @@ EC_PAIRING_PRECOMPILED_ADDRESS: constant(address) = 0x00000000000000000000000000

@view
@external
def verifyProof(pointA: uint256[2], pointB: uint256[2][2], pointC: uint256[2], publicSignals: uint256[<%=IC.length-1%>]) -> bool:
def verifyProof(pointA: uint256[2], pointB: uint256[2][2], pointC: uint256[2], publicSignals: uint256[<%=IC.length - 1%>]) -> bool:
# @dev check that all public signals are in F
for signal: uint256 in publicSignals:
if signal >= BASE_FIELD_SIZE:
Expand Down Expand Up @@ -84,7 +84,7 @@ def _g1MulAdd(pR: uint256[2], pP: uint256[2], s: uint256) -> (bool, uint256[2]):

@view
@internal
def _checkPairing(pA: uint256[2], pB: uint256[2][2], pC: uint256[2], pubSignals: uint256[<%=IC.length-1%>]) -> bool:
def _checkPairing(pA: uint256[2], pB: uint256[2][2], pC: uint256[2], pubSignals: uint256[<%=IC.length - 1%>]) -> bool:
success: bool = True
mulAddResult: uint256[2] = IC[0]

Expand Down
26 changes: 13 additions & 13 deletions src/core/templates/verifier_plonk.vy.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ P_ZH_INV: constant(uint256) = 24

P_EVAL_L1: constant(uint256) = 25

P_TOTAL_SIZE: constant(uint256) = <%=25+nPublic%>
P_TOTAL_SIZE: constant(uint256) = <%=25 + nPublic%>

EC_ADD_PRECOMPILED_ADDRESS: constant(address) = 0x0000000000000000000000000000000000000006
EC_MUL_PRECOMPILED_ADDRESS: constant(address) = 0x0000000000000000000000000000000000000007
Expand Down Expand Up @@ -218,12 +218,12 @@ def _inverse(a: uint256, q: uint256) -> uint256:

@pure
@internal
def _inverseArray(pVals: uint256[<%=nPublic+1%>]) -> uint256[<%=nPublic+1%>]:
def _inverseArray(pVals: uint256[<%=nPublic + 1%>]) -> uint256[<%=nPublic + 1%>]:
acc: uint256 = pVals[0]
inverses: uint256[<%=nPublic+1%>] = empty(uint256[<%=nPublic+1%>])
pAux: uint256[<%=nPublic+1%>] = empty(uint256[<%=nPublic+1%>])
inverses: uint256[<%=nPublic + 1%>] = empty(uint256[<%=nPublic + 1%>])
pAux: uint256[<%=nPublic + 1%>] = empty(uint256[<%=nPublic + 1%>])

for i: uint256 in range(1, <%=nPublic+1%>):
for i: uint256 in range(1, <%=nPublic + 1%>):
pAux[i] = acc
acc = uint256_mulmod(acc, pVals[i], BASE_FIELD_SIZE)

Expand Down Expand Up @@ -265,7 +265,7 @@ def _checkInput(proof: uint256[24]) -> bool:
@pure
@internal
def _calculateChallenges(proof: uint256[24], pubSignals: uint256[<%=nPublic%>]) -> uint256[P_TOTAL_SIZE]:
mIn<%=22+nPublic%>: uint256[<%=22+nPublic%>] = [
mIn<%=22 + nPublic%>: uint256[<%=22 + nPublic%>] = [
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,
<% for (let i = 0; i < nPublic; i++) { %>pubSignals[<%=i%>], <% } %>
proof[P_A], proof[P_A + 1], proof[P_B], proof[P_B + 1], proof[P_C], proof[P_C + 1],
Expand Down Expand Up @@ -307,7 +307,7 @@ def _calculateChallenges(proof: uint256[24], pubSignals: uint256[<%=nPublic%>])
p[P_BETA_XI] = uint256_mulmod(beta, aux, BASE_FIELD_SIZE)

# challenges.xi^n
<%for (let i=0; i<power;i++) {%>
<%for (let i = 0; i < power; i++) {%>
aux = uint256_mulmod(aux, aux, BASE_FIELD_SIZE)<% } %>
p[P_XIN] = aux

Expand All @@ -334,23 +334,23 @@ def _evaluateLagrange(w: uint256, xi: uint256) -> uint256:
def _calculateLagrange(p: uint256[P_TOTAL_SIZE]) -> uint256[P_TOTAL_SIZE]:
w: uint256 = 1

for i: uint256 in range(1, <%=nPublic+1%>):
for i: uint256 in range(1, <%=nPublic + 1%>):
p[P_EVAL_L1 + (i - 1)] = self._evaluateLagrange(w, p[P_XI])
w = uint256_mulmod(w, W1, BASE_FIELD_SIZE)

pointsToInverse: uint256[<%=nPublic+1%>] = empty(uint256[<%=nPublic+1%>])
for i: uint256 in range(<%=nPublic+1%>):
pointsToInverse: uint256[<%=nPublic + 1%>] = empty(uint256[<%=nPublic + 1%>])
for i: uint256 in range(<%=nPublic + 1%>):
pointsToInverse[i] = p[P_ZH_INV + i]

inverses: uint256[<%=nPublic+1%>] = self._inverseArray(pointsToInverse)
inverses: uint256[<%=nPublic + 1%>] = self._inverseArray(pointsToInverse)

for i: uint256 in range(<%=nPublic+1%>):
for i: uint256 in range(<%=nPublic + 1%>):
p[P_ZH_INV + i] = inverses[i]

zh: uint256 = p[P_ZH]
w = 1

for i: uint256 in range(1, <%=nPublic+1%>):
for i: uint256 in range(1, <%=nPublic + 1%>):
p[P_EVAL_L1 + (i - 1)] = uint256_mulmod(
uint256_mulmod(p[P_EVAL_L1 + (i - 1)], zh, BASE_FIELD_SIZE),
w,
Expand Down

0 comments on commit b27544a

Please sign in to comment.