zkjson 0.1.30 → 0.1.32
Sign up to get free protection for your applications and to get access to all the features.
- package/circomlibjs.js +169 -127
- package/contracts/OPRollup.sol +33 -0
- package/contracts/verifiers/verifier_db.sol +261 -0
- package/contracts/verifiers/verifier_ipfs.sol +464 -0
- package/contracts/verifiers/verifier_json.sol +247 -0
- package/contracts/verifiers/verifier_rollup.sol +240 -0
- package/package.json +1 -1
@@ -0,0 +1,33 @@
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
2
|
+
|
3
|
+
pragma solidity >=0.7.0 <0.9.0;
|
4
|
+
import "./ZKQuery.sol";
|
5
|
+
|
6
|
+
interface VerifierRU {
|
7
|
+
function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[11] calldata _pubSignals) view external returns (bool);
|
8
|
+
|
9
|
+
}
|
10
|
+
|
11
|
+
contract OPRollup is ZKQuery {
|
12
|
+
address public verifierRU;
|
13
|
+
address public committer;
|
14
|
+
uint public root;
|
15
|
+
|
16
|
+
function _validateQueryRU(uint[] memory path, uint[] memory zkp, uint size_path, uint size_val) internal view returns(uint[] memory){
|
17
|
+
require(zkp[19] == root, "root mismatch");
|
18
|
+
require(zkp[size_path + size_val + 10] == path[0], "wrong collection");
|
19
|
+
require(zkp[size_path + size_val + 11] == path[1], "wrong doc");
|
20
|
+
require(zkp[8] == 1, "value doesn't exist");
|
21
|
+
require(path.length <= size_path + size_val, "path too long");
|
22
|
+
for(uint i = 9; i < 9 + path.length - 2; i++) require(path[i - 7] == zkp[i], "wrong path");
|
23
|
+
uint[] memory value = new uint[](size_val);
|
24
|
+
for(uint i = 9 + size_path; i < 9 + size_path + size_val; i++) value[i - (9 + size_path)] = zkp[i];
|
25
|
+
return toArr(value);
|
26
|
+
}
|
27
|
+
|
28
|
+
function commit (uint _root) public returns (uint) {
|
29
|
+
require(msg.sender == committer, "sender is not committer");
|
30
|
+
root = _root;
|
31
|
+
return root;
|
32
|
+
}
|
33
|
+
}
|
@@ -0,0 +1,261 @@
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0
|
2
|
+
/*
|
3
|
+
Copyright 2021 0KIMS association.
|
4
|
+
|
5
|
+
This file is generated with [snarkJS](https://github.com/iden3/snarkjs).
|
6
|
+
|
7
|
+
snarkJS is a free software: you can redistribute it and/or modify it
|
8
|
+
under the terms of the GNU General Public License as published by
|
9
|
+
the Free Software Foundation, either version 3 of the License, or
|
10
|
+
(at your option) any later version.
|
11
|
+
|
12
|
+
snarkJS is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
14
|
+
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
15
|
+
License for more details.
|
16
|
+
|
17
|
+
You should have received a copy of the GNU General Public License
|
18
|
+
along with snarkJS. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
*/
|
20
|
+
|
21
|
+
pragma solidity >=0.7.0 <0.9.0;
|
22
|
+
|
23
|
+
contract Groth16VerifierDB {
|
24
|
+
// Scalar field size
|
25
|
+
uint256 constant r = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
|
26
|
+
// Base field size
|
27
|
+
uint256 constant q = 21888242871839275222246405745257275088696311157297823662689037894645226208583;
|
28
|
+
|
29
|
+
// Verification Key data
|
30
|
+
uint256 constant alphax = 15666102625973721621314372231502757622972672186869992706298330320625360022168;
|
31
|
+
uint256 constant alphay = 7860317584437807811785184551736117381909584923230858144057222694769024311858;
|
32
|
+
uint256 constant betax1 = 5694626294852239414951192660282103704402907520663058613604080680299155414738;
|
33
|
+
uint256 constant betax2 = 5842324628399168549713701697348354919163878880337475549755337604460908215719;
|
34
|
+
uint256 constant betay1 = 15299555850342023627325133664905760186157697378199428660903779519265533045460;
|
35
|
+
uint256 constant betay2 = 19369932919467500712513911930210382196103616502274926080161996489344136260171;
|
36
|
+
uint256 constant gammax1 = 11559732032986387107991004021392285783925812861821192530917403151452391805634;
|
37
|
+
uint256 constant gammax2 = 10857046999023057135944570762232829481370756359578518086990519993285655852781;
|
38
|
+
uint256 constant gammay1 = 4082367875863433681332203403145435568316851327593401208105741076214120093531;
|
39
|
+
uint256 constant gammay2 = 8495653923123431417604973247489272438418190587263600148770280649306958101930;
|
40
|
+
uint256 constant deltax1 = 4503582552430561212779022449004306860952515258252510730703342683904433748529;
|
41
|
+
uint256 constant deltax2 = 18425111920911215222332253146797783332823283746160018203034073853247125442993;
|
42
|
+
uint256 constant deltay1 = 4453946082216241594348271243333609134155973515870520791839116124952157106489;
|
43
|
+
uint256 constant deltay2 = 6299943403529237547647875143706632408243402531062446767696226637461756039372;
|
44
|
+
|
45
|
+
|
46
|
+
uint256 constant IC0x = 21321207194104473227475304543920529140777253812445062785414102137810628823351;
|
47
|
+
uint256 constant IC0y = 17435301628228161373103753422842813332325503638744597201144754851019312998703;
|
48
|
+
|
49
|
+
uint256 constant IC1x = 12820400866256307684567623036475747952236795131426943895421353782394091927742;
|
50
|
+
uint256 constant IC1y = 60275713036652700837316478219950928712704126788272985582350169411243461644;
|
51
|
+
|
52
|
+
uint256 constant IC2x = 857253043166092910744552687303159485904872523742588131455423770248915368285;
|
53
|
+
uint256 constant IC2y = 14195849356583660474308242114329315396764028733952643683061195745221866004517;
|
54
|
+
|
55
|
+
uint256 constant IC3x = 21758746957477097206930100418195981232696693412252142756415630022251620498988;
|
56
|
+
uint256 constant IC3y = 13410227681809155220050013564476536866963972600821261716783794631827707904349;
|
57
|
+
|
58
|
+
uint256 constant IC4x = 863580107893288900828264046203999618333374859561603309534755206187548007845;
|
59
|
+
uint256 constant IC4y = 17276530052140799694039014154041098203841609580394223470304419489978941020095;
|
60
|
+
|
61
|
+
uint256 constant IC5x = 20860866781226655978193967912232894914994034954825205708931667985751271655154;
|
62
|
+
uint256 constant IC5y = 12177441101666309938978105246002445372089044967481369877555009124474329640505;
|
63
|
+
|
64
|
+
uint256 constant IC6x = 10253410591025171769139608115823458515554722863591962190480237037964222989835;
|
65
|
+
uint256 constant IC6y = 2300854166049230775727949815888955384104705675980904483480782073188875432218;
|
66
|
+
|
67
|
+
uint256 constant IC7x = 9245031860281158825371686872766118053567656180865626846873554393892189651843;
|
68
|
+
uint256 constant IC7y = 18513814971835729370836379685375481264692236826421466003977840558207277913353;
|
69
|
+
|
70
|
+
uint256 constant IC8x = 2754620511499804101010165108130638609126165250442796483020701485428889593474;
|
71
|
+
uint256 constant IC8y = 21543955085620310283456271839558892054215536683326587016759091514123004776495;
|
72
|
+
|
73
|
+
uint256 constant IC9x = 7226523333475405455471783299389388256960485582655675212929034730327278898093;
|
74
|
+
uint256 constant IC9y = 5056090250187692130221637329845012688890940869984044755973476873548610820578;
|
75
|
+
|
76
|
+
uint256 constant IC10x = 10107033883545633867195921318423461010318227740867478163570877213298959179572;
|
77
|
+
uint256 constant IC10y = 503817861296261242201817887974509587032687921855950877235697350857170430743;
|
78
|
+
|
79
|
+
uint256 constant IC11x = 21035943047303381225570192698677598249462130417684515089990469613546011008550;
|
80
|
+
uint256 constant IC11y = 7261441348374767801093007257999121003733259642366629311136938544979253433119;
|
81
|
+
|
82
|
+
uint256 constant IC12x = 20453521999827294992536897361543222148394244433474196230498330885560620003829;
|
83
|
+
uint256 constant IC12y = 18476327162478621518583504728598744035870583497372084378654039079117097682;
|
84
|
+
|
85
|
+
uint256 constant IC13x = 15724968258919878061585416513119667249637764275276227548708222282031970422796;
|
86
|
+
uint256 constant IC13y = 15146709066947881278827713419811426264008528066434458265193671798769307857310;
|
87
|
+
|
88
|
+
uint256 constant IC14x = 9097393479338656770619464061691689490135837081335461486896937720741934261539;
|
89
|
+
uint256 constant IC14y = 3771549967344233937612853274190217413635208199629257189936808052809357297423;
|
90
|
+
|
91
|
+
|
92
|
+
// Memory data
|
93
|
+
uint16 constant pVk = 0;
|
94
|
+
uint16 constant pPairing = 128;
|
95
|
+
|
96
|
+
uint16 constant pLastMem = 896;
|
97
|
+
|
98
|
+
function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[14] calldata _pubSignals) public view returns (bool) {
|
99
|
+
assembly {
|
100
|
+
function checkField(v) {
|
101
|
+
if iszero(lt(v, q)) {
|
102
|
+
mstore(0, 0)
|
103
|
+
return(0, 0x20)
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
// G1 function to multiply a G1 value(x,y) to value in an address
|
108
|
+
function g1_mulAccC(pR, x, y, s) {
|
109
|
+
let success
|
110
|
+
let mIn := mload(0x40)
|
111
|
+
mstore(mIn, x)
|
112
|
+
mstore(add(mIn, 32), y)
|
113
|
+
mstore(add(mIn, 64), s)
|
114
|
+
|
115
|
+
success := staticcall(sub(gas(), 2000), 7, mIn, 96, mIn, 64)
|
116
|
+
|
117
|
+
if iszero(success) {
|
118
|
+
mstore(0, 0)
|
119
|
+
return(0, 0x20)
|
120
|
+
}
|
121
|
+
|
122
|
+
mstore(add(mIn, 64), mload(pR))
|
123
|
+
mstore(add(mIn, 96), mload(add(pR, 32)))
|
124
|
+
|
125
|
+
success := staticcall(sub(gas(), 2000), 6, mIn, 128, pR, 64)
|
126
|
+
|
127
|
+
if iszero(success) {
|
128
|
+
mstore(0, 0)
|
129
|
+
return(0, 0x20)
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
function checkPairing(pA, pB, pC, pubSignals, pMem) -> isOk {
|
134
|
+
let _pPairing := add(pMem, pPairing)
|
135
|
+
let _pVk := add(pMem, pVk)
|
136
|
+
|
137
|
+
mstore(_pVk, IC0x)
|
138
|
+
mstore(add(_pVk, 32), IC0y)
|
139
|
+
|
140
|
+
// Compute the linear combination vk_x
|
141
|
+
|
142
|
+
g1_mulAccC(_pVk, IC1x, IC1y, calldataload(add(pubSignals, 0)))
|
143
|
+
|
144
|
+
g1_mulAccC(_pVk, IC2x, IC2y, calldataload(add(pubSignals, 32)))
|
145
|
+
|
146
|
+
g1_mulAccC(_pVk, IC3x, IC3y, calldataload(add(pubSignals, 64)))
|
147
|
+
|
148
|
+
g1_mulAccC(_pVk, IC4x, IC4y, calldataload(add(pubSignals, 96)))
|
149
|
+
|
150
|
+
g1_mulAccC(_pVk, IC5x, IC5y, calldataload(add(pubSignals, 128)))
|
151
|
+
|
152
|
+
g1_mulAccC(_pVk, IC6x, IC6y, calldataload(add(pubSignals, 160)))
|
153
|
+
|
154
|
+
g1_mulAccC(_pVk, IC7x, IC7y, calldataload(add(pubSignals, 192)))
|
155
|
+
|
156
|
+
g1_mulAccC(_pVk, IC8x, IC8y, calldataload(add(pubSignals, 224)))
|
157
|
+
|
158
|
+
g1_mulAccC(_pVk, IC9x, IC9y, calldataload(add(pubSignals, 256)))
|
159
|
+
|
160
|
+
g1_mulAccC(_pVk, IC10x, IC10y, calldataload(add(pubSignals, 288)))
|
161
|
+
|
162
|
+
g1_mulAccC(_pVk, IC11x, IC11y, calldataload(add(pubSignals, 320)))
|
163
|
+
|
164
|
+
g1_mulAccC(_pVk, IC12x, IC12y, calldataload(add(pubSignals, 352)))
|
165
|
+
|
166
|
+
g1_mulAccC(_pVk, IC13x, IC13y, calldataload(add(pubSignals, 384)))
|
167
|
+
|
168
|
+
g1_mulAccC(_pVk, IC14x, IC14y, calldataload(add(pubSignals, 416)))
|
169
|
+
|
170
|
+
|
171
|
+
// -A
|
172
|
+
mstore(_pPairing, calldataload(pA))
|
173
|
+
mstore(add(_pPairing, 32), mod(sub(q, calldataload(add(pA, 32))), q))
|
174
|
+
|
175
|
+
// B
|
176
|
+
mstore(add(_pPairing, 64), calldataload(pB))
|
177
|
+
mstore(add(_pPairing, 96), calldataload(add(pB, 32)))
|
178
|
+
mstore(add(_pPairing, 128), calldataload(add(pB, 64)))
|
179
|
+
mstore(add(_pPairing, 160), calldataload(add(pB, 96)))
|
180
|
+
|
181
|
+
// alpha1
|
182
|
+
mstore(add(_pPairing, 192), alphax)
|
183
|
+
mstore(add(_pPairing, 224), alphay)
|
184
|
+
|
185
|
+
// beta2
|
186
|
+
mstore(add(_pPairing, 256), betax1)
|
187
|
+
mstore(add(_pPairing, 288), betax2)
|
188
|
+
mstore(add(_pPairing, 320), betay1)
|
189
|
+
mstore(add(_pPairing, 352), betay2)
|
190
|
+
|
191
|
+
// vk_x
|
192
|
+
mstore(add(_pPairing, 384), mload(add(pMem, pVk)))
|
193
|
+
mstore(add(_pPairing, 416), mload(add(pMem, add(pVk, 32))))
|
194
|
+
|
195
|
+
|
196
|
+
// gamma2
|
197
|
+
mstore(add(_pPairing, 448), gammax1)
|
198
|
+
mstore(add(_pPairing, 480), gammax2)
|
199
|
+
mstore(add(_pPairing, 512), gammay1)
|
200
|
+
mstore(add(_pPairing, 544), gammay2)
|
201
|
+
|
202
|
+
// C
|
203
|
+
mstore(add(_pPairing, 576), calldataload(pC))
|
204
|
+
mstore(add(_pPairing, 608), calldataload(add(pC, 32)))
|
205
|
+
|
206
|
+
// delta2
|
207
|
+
mstore(add(_pPairing, 640), deltax1)
|
208
|
+
mstore(add(_pPairing, 672), deltax2)
|
209
|
+
mstore(add(_pPairing, 704), deltay1)
|
210
|
+
mstore(add(_pPairing, 736), deltay2)
|
211
|
+
|
212
|
+
|
213
|
+
let success := staticcall(sub(gas(), 2000), 8, _pPairing, 768, _pPairing, 0x20)
|
214
|
+
|
215
|
+
isOk := and(success, mload(_pPairing))
|
216
|
+
}
|
217
|
+
|
218
|
+
let pMem := mload(0x40)
|
219
|
+
mstore(0x40, add(pMem, pLastMem))
|
220
|
+
|
221
|
+
// Validate that all evaluations ∈ F
|
222
|
+
|
223
|
+
checkField(calldataload(add(_pubSignals, 0)))
|
224
|
+
|
225
|
+
checkField(calldataload(add(_pubSignals, 32)))
|
226
|
+
|
227
|
+
checkField(calldataload(add(_pubSignals, 64)))
|
228
|
+
|
229
|
+
checkField(calldataload(add(_pubSignals, 96)))
|
230
|
+
|
231
|
+
checkField(calldataload(add(_pubSignals, 128)))
|
232
|
+
|
233
|
+
checkField(calldataload(add(_pubSignals, 160)))
|
234
|
+
|
235
|
+
checkField(calldataload(add(_pubSignals, 192)))
|
236
|
+
|
237
|
+
checkField(calldataload(add(_pubSignals, 224)))
|
238
|
+
|
239
|
+
checkField(calldataload(add(_pubSignals, 256)))
|
240
|
+
|
241
|
+
checkField(calldataload(add(_pubSignals, 288)))
|
242
|
+
|
243
|
+
checkField(calldataload(add(_pubSignals, 320)))
|
244
|
+
|
245
|
+
checkField(calldataload(add(_pubSignals, 352)))
|
246
|
+
|
247
|
+
checkField(calldataload(add(_pubSignals, 384)))
|
248
|
+
|
249
|
+
checkField(calldataload(add(_pubSignals, 416)))
|
250
|
+
|
251
|
+
checkField(calldataload(add(_pubSignals, 448)))
|
252
|
+
|
253
|
+
|
254
|
+
// Validate all evaluations
|
255
|
+
let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem)
|
256
|
+
|
257
|
+
mstore(0, isValid)
|
258
|
+
return(0, 0x20)
|
259
|
+
}
|
260
|
+
}
|
261
|
+
}
|