@solarity/zkit 0.2.5 → 0.3.0-rc.0
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 +8 -8
- package/dist/core/CircuitZKit.d.ts +24 -22
- package/dist/core/CircuitZKit.d.ts.map +1 -1
- package/dist/core/CircuitZKit.js +30 -44
- package/dist/core/CircuitZKit.js.map +1 -1
- package/dist/core/protocols/AbstractImplementer.d.ts +15 -0
- package/dist/core/protocols/AbstractImplementer.d.ts.map +1 -0
- package/dist/core/protocols/AbstractImplementer.js +36 -0
- package/dist/core/protocols/AbstractImplementer.js.map +1 -0
- package/dist/core/protocols/Groth16Implementer.d.ts +10 -0
- package/dist/core/protocols/Groth16Implementer.d.ts.map +1 -0
- package/dist/core/protocols/Groth16Implementer.js +50 -0
- package/dist/core/protocols/Groth16Implementer.js.map +1 -0
- package/dist/core/protocols/PlonkImplementer.d.ts +10 -0
- package/dist/core/protocols/PlonkImplementer.d.ts.map +1 -0
- package/dist/core/protocols/PlonkImplementer.js +51 -0
- package/dist/core/protocols/PlonkImplementer.js.map +1 -0
- package/dist/core/protocols/index.d.ts +4 -0
- package/dist/core/protocols/index.d.ts.map +1 -0
- package/dist/core/protocols/index.js +10 -0
- package/dist/core/protocols/index.js.map +1 -0
- package/dist/core/templates/verifier_groth16.vy.ejs +118 -0
- package/dist/core/templates/verifier_plonk.sol.ejs +681 -0
- package/dist/core/templates/verifier_plonk.vy.ejs +650 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/types/circuit-zkit.d.ts +1 -34
- package/dist/types/circuit-zkit.d.ts.map +1 -1
- package/dist/types/proof-utils.d.ts +7 -0
- package/dist/types/proof-utils.d.ts.map +1 -0
- package/dist/types/proof-utils.js +3 -0
- package/dist/types/proof-utils.js.map +1 -0
- package/dist/types/protocols/groth16.d.ts +28 -0
- package/dist/types/protocols/groth16.d.ts.map +1 -0
- package/dist/types/protocols/groth16.js +3 -0
- package/dist/types/protocols/groth16.js.map +1 -0
- package/dist/types/protocols/index.d.ts +31 -0
- package/dist/types/protocols/index.d.ts.map +1 -0
- package/dist/types/protocols/index.js +19 -0
- package/dist/types/protocols/index.js.map +1 -0
- package/dist/types/protocols/plonk.d.ts +26 -0
- package/dist/types/protocols/plonk.d.ts.map +1 -0
- package/dist/types/{types.js → protocols/plonk.js} +1 -1
- package/dist/types/protocols/plonk.js.map +1 -0
- package/package.json +7 -6
- package/src/core/CircuitZKit.ts +42 -63
- package/src/core/protocols/AbstractImplementer.ts +67 -0
- package/src/core/protocols/Groth16Implementer.ts +29 -0
- package/src/core/protocols/PlonkImplementer.ts +32 -0
- package/src/core/protocols/index.ts +3 -0
- package/src/core/templates/verifier_groth16.vy.ejs +118 -0
- package/src/core/templates/verifier_plonk.sol.ejs +681 -0
- package/src/core/templates/verifier_plonk.vy.ejs +650 -0
- package/src/index.ts +5 -1
- package/src/types/circuit-zkit.ts +1 -31
- package/src/types/proof-utils.ts +9 -0
- package/src/types/protocols/groth16.ts +21 -0
- package/src/types/protocols/index.ts +49 -0
- package/src/types/protocols/plonk.ts +28 -0
- package/dist/config/config.d.ts +0 -27
- package/dist/config/config.d.ts.map +0 -1
- package/dist/config/config.js +0 -19
- package/dist/config/config.js.map +0 -1
- package/dist/core/CircomZKit.d.ts +0 -39
- package/dist/core/CircomZKit.d.ts.map +0 -1
- package/dist/core/CircomZKit.js +0 -94
- package/dist/core/CircomZKit.js.map +0 -1
- package/dist/core/ManagerZKit.d.ts +0 -97
- package/dist/core/ManagerZKit.d.ts.map +0 -1
- package/dist/core/ManagerZKit.js +0 -222
- package/dist/core/ManagerZKit.js.map +0 -1
- package/dist/types/types.d.ts +0 -46
- package/dist/types/types.d.ts.map +0 -1
- package/dist/types/types.js.map +0 -1
- package/dist/utils/utils.d.ts +0 -18
- package/dist/utils/utils.d.ts.map +0 -1
- package/dist/utils/utils.js +0 -58
- package/dist/utils/utils.js.map +0 -1
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# pragma version ~=0.4.0
|
|
2
|
+
|
|
3
|
+
# AUTOGENERATED FILE BY HARDHAT-ZKIT. DO NOT EDIT.
|
|
4
|
+
|
|
5
|
+
# @dev base field size
|
|
6
|
+
BASE_FIELD_SIZE: constant(uint256) = 21888242871839275222246405745257275088696311157297823662689037894645226208583
|
|
7
|
+
|
|
8
|
+
# @dev verification key data
|
|
9
|
+
ALPHA_X: constant(uint256) = <%=vk_alpha_1[0]%>
|
|
10
|
+
ALPHA_Y: constant(uint256) = <%=vk_alpha_1[1]%>
|
|
11
|
+
BETA_X1: constant(uint256) = <%=vk_beta_2[0][1]%>
|
|
12
|
+
BETA_X2: constant(uint256) = <%=vk_beta_2[0][0]%>
|
|
13
|
+
BETA_Y1: constant(uint256) = <%=vk_beta_2[1][1]%>
|
|
14
|
+
BETA_Y2: constant(uint256) = <%=vk_beta_2[1][0]%>
|
|
15
|
+
GAMMA_X1: constant(uint256) = <%=vk_gamma_2[0][1]%>
|
|
16
|
+
GAMMA_X2: constant(uint256) = <%=vk_gamma_2[0][0]%>
|
|
17
|
+
GAMMA_Y1: constant(uint256) = <%=vk_gamma_2[1][1]%>
|
|
18
|
+
GAMMA_Y2: constant(uint256) = <%=vk_gamma_2[1][0]%>
|
|
19
|
+
DELTA_X1: constant(uint256) = <%=vk_delta_2[0][1]%>
|
|
20
|
+
DELTA_X2: constant(uint256) = <%=vk_delta_2[0][0]%>
|
|
21
|
+
DELTA_Y1: constant(uint256) = <%=vk_delta_2[1][1]%>
|
|
22
|
+
DELTA_Y2: constant(uint256) = <%=vk_delta_2[1][0] -%>
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
IC: constant(uint256[<%=IC.length%>][2]) = [
|
|
26
|
+
<% IC.forEach(function(innerArray, index) { %> [
|
|
27
|
+
<%= innerArray[0] %>,
|
|
28
|
+
<%= innerArray[1] %>
|
|
29
|
+
]<%= index < IC.length - 1 ? ',' : '' %>
|
|
30
|
+
<% }); %>]
|
|
31
|
+
|
|
32
|
+
EC_ADD_PRECOMPILED_ADDRESS: constant(address) = 0x0000000000000000000000000000000000000006
|
|
33
|
+
EC_MUL_PRECOMPILED_ADDRESS: constant(address) = 0x0000000000000000000000000000000000000007
|
|
34
|
+
EC_PAIRING_PRECOMPILED_ADDRESS: constant(address) = 0x0000000000000000000000000000000000000008
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@view
|
|
38
|
+
@external
|
|
39
|
+
def verifyProof(pointA: uint256[2], pointB: uint256[2][2], pointC: uint256[2], publicSignals: uint256[<%=IC.length-1%>]) -> bool:
|
|
40
|
+
# @dev check that all public signals are in F
|
|
41
|
+
for signal: uint256 in publicSignals:
|
|
42
|
+
if signal >= BASE_FIELD_SIZE:
|
|
43
|
+
return False
|
|
44
|
+
|
|
45
|
+
return self._checkPairing(pointA, pointB, pointC, publicSignals)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@view
|
|
49
|
+
@internal
|
|
50
|
+
def _g1MulAdd(pR: uint256[2], pP: uint256[2], s: uint256) -> (bool, uint256[2]):
|
|
51
|
+
success: bool = True
|
|
52
|
+
response: Bytes[64] = b""
|
|
53
|
+
success, response = raw_call(
|
|
54
|
+
EC_MUL_PRECOMPILED_ADDRESS,
|
|
55
|
+
abi_encode(pP, s),
|
|
56
|
+
max_outsize=64,
|
|
57
|
+
is_static_call=True,
|
|
58
|
+
revert_on_failure=False
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
if not success or len(response) != 64:
|
|
62
|
+
return (False, [0, 0])
|
|
63
|
+
|
|
64
|
+
x: uint256 = convert(slice(response, 0, 32), uint256)
|
|
65
|
+
y: uint256 = convert(slice(response, 32, 32), uint256)
|
|
66
|
+
pS: uint256[2] = [x, y]
|
|
67
|
+
|
|
68
|
+
success, response = raw_call(
|
|
69
|
+
EC_ADD_PRECOMPILED_ADDRESS,
|
|
70
|
+
abi_encode(pR, pS),
|
|
71
|
+
max_outsize=64,
|
|
72
|
+
is_static_call=True,
|
|
73
|
+
revert_on_failure=False
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
if not success or len(response) != 64:
|
|
77
|
+
return (False, [0, 0])
|
|
78
|
+
|
|
79
|
+
x = convert(slice(response, 0, 32), uint256)
|
|
80
|
+
y = convert(slice(response, 32, 32), uint256)
|
|
81
|
+
|
|
82
|
+
return (True, [x, y])
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@view
|
|
86
|
+
@internal
|
|
87
|
+
def _checkPairing(pA: uint256[2], pB: uint256[2][2], pC: uint256[2], pubSignals: uint256[<%=IC.length-1%>]) -> bool:
|
|
88
|
+
success: bool = True
|
|
89
|
+
mulAddResult: uint256[2] = IC[0]
|
|
90
|
+
|
|
91
|
+
# @dev compute the linear combination of public signals
|
|
92
|
+
for i: uint256 in range(1, <%=IC.length%>):
|
|
93
|
+
success, mulAddResult = self._g1MulAdd(mulAddResult, IC[i], pubSignals[i - 1])
|
|
94
|
+
if not success:
|
|
95
|
+
return False
|
|
96
|
+
|
|
97
|
+
response: Bytes[32] = b""
|
|
98
|
+
success, response = raw_call(
|
|
99
|
+
EC_PAIRING_PRECOMPILED_ADDRESS,
|
|
100
|
+
abi_encode(
|
|
101
|
+
pA[0], (BASE_FIELD_SIZE - pA[1]) % BASE_FIELD_SIZE,
|
|
102
|
+
pB,
|
|
103
|
+
ALPHA_X, ALPHA_Y,
|
|
104
|
+
BETA_X1, BETA_X2, BETA_Y1, BETA_Y2,
|
|
105
|
+
mulAddResult,
|
|
106
|
+
GAMMA_X1, GAMMA_X2, GAMMA_Y1, GAMMA_Y2,
|
|
107
|
+
pC,
|
|
108
|
+
DELTA_X1, DELTA_X2, DELTA_Y1, DELTA_Y2
|
|
109
|
+
),
|
|
110
|
+
max_outsize=32,
|
|
111
|
+
is_static_call=True,
|
|
112
|
+
revert_on_failure=False
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
if not success:
|
|
116
|
+
return False
|
|
117
|
+
|
|
118
|
+
return convert(response, bool)
|