-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Vyper groth16 verifier template
- Loading branch information
Showing
8 changed files
with
316 additions
and
453 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const languageMap = { | ||
solidity: "sol", | ||
vyper: "vy", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# pragma version ~=0.4.0 | ||
|
||
# AUTOGENERATED FILE BY HARDHAT-ZKIT. DO NOT EDIT. | ||
|
||
# @dev base field size | ||
BASE_FIELD_SIZE: constant(uint256) = 21888242871839275222246405745257275088696311157297823662689037894645226208583 | ||
|
||
# @dev verification key data | ||
ALPHA_X: constant(uint256) = <%=vk_alpha_1[0]%> | ||
ALPHA_Y: constant(uint256) = <%=vk_alpha_1[1]%> | ||
BETA_X1: constant(uint256) = <%=vk_beta_2[0][1]%> | ||
BETA_X2: constant(uint256) = <%=vk_beta_2[0][0]%> | ||
BETA_Y1: constant(uint256) = <%=vk_beta_2[1][1]%> | ||
BETA_Y2: constant(uint256) = <%=vk_beta_2[1][0]%> | ||
GAMMA_X1: constant(uint256) = <%=vk_gamma_2[0][1]%> | ||
GAMMA_X2: constant(uint256) = <%=vk_gamma_2[0][0]%> | ||
GAMMA_Y1: constant(uint256) = <%=vk_gamma_2[1][1]%> | ||
GAMMA_Y2: constant(uint256) = <%=vk_gamma_2[1][0]%> | ||
DELTA_X1: constant(uint256) = <%=vk_delta_2[0][1]%> | ||
DELTA_X2: constant(uint256) = <%=vk_delta_2[0][0]%> | ||
DELTA_Y1: constant(uint256) = <%=vk_delta_2[1][1]%> | ||
DELTA_Y2: constant(uint256) = <%=vk_delta_2[1][0] -%> | ||
|
||
|
||
<% for (let i = 0; i < IC.length; i++) { %>IC<%=i%>_X: constant(uint256) = <%=IC[i][0]%> | ||
IC<%=i%>_Y: constant(uint256) = <%=IC[i][1]%> | ||
<% } -%> | ||
|
||
EC_PAIRING_PRECOMPILED_ADDRESS: constant(address) = 0x0000000000000000000000000000000000000008 | ||
|
||
|
||
@view | ||
@external | ||
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 (let i = 0; i < nPublic; i++) { %>if publicSignals[<%=i%>] >= BASE_FIELD_SIZE: | ||
return False | ||
<% } -%> | ||
|
||
return self._checkPairing(pointA, pointB, pointC, publicSignals) | ||
|
||
|
||
@view | ||
@internal | ||
def _g1MulAdd(pR: uint256[2], pP: uint256[2], s: uint256) -> (bool, uint256[2]): | ||
pS: uint256[2] = ecmul(pP, s) | ||
|
||
if pS[0] == 0 and pS[1] == 0: | ||
return (False, [0, 0]) | ||
|
||
finalPoint: uint256[2] = ecadd(pR, pS) | ||
|
||
if finalPoint[0] == 0 and finalPoint[1] == 0: | ||
return (False, [0, 0]) | ||
|
||
return (True, finalPoint) | ||
|
||
|
||
@view | ||
@internal | ||
def _checkPairing(pA: uint256[2], pB: uint256[2][2], pC: uint256[2], pubSignals: uint256[<%=IC.length-1%>]) -> bool: | ||
success: bool = True | ||
mulAddResult: uint256[2] = [IC0_X, IC0_Y] | ||
|
||
# @dev compute the linear combination of public signals | ||
<% for (let i = 1; i <= nPublic; i++) { %>success, mulAddResult = self._g1MulAdd(mulAddResult, [IC<%=i%>_X, IC<%=i%>_Y], pubSignals[<%=i-1%>]) | ||
if not success: | ||
return False | ||
<% } -%> | ||
|
||
response: Bytes[32] = b"" | ||
success, response = raw_call( | ||
EC_PAIRING_PRECOMPILED_ADDRESS, | ||
abi_encode( | ||
pA[0], (BASE_FIELD_SIZE - pA[1]) % BASE_FIELD_SIZE, | ||
pB, | ||
ALPHA_X, ALPHA_Y, | ||
BETA_X1, BETA_X2, BETA_Y1, BETA_Y2, | ||
mulAddResult, | ||
GAMMA_X1, GAMMA_X2, GAMMA_Y1, GAMMA_Y2, | ||
pC, | ||
DELTA_X1, DELTA_X2, DELTA_Y1, DELTA_Y2 | ||
), | ||
max_outsize=32, | ||
is_static_call=True, | ||
revert_on_failure=False | ||
) | ||
|
||
if not success: | ||
return False | ||
|
||
return convert(response, bool) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.