zkjson 0.1.31 → 0.1.32

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.
@@ -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
+ }
@@ -0,0 +1,464 @@
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 Groth16VerifierIPFS {
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 = 8551455248674230780518198335645580391815322773286870598810054651838967299672;
31
+ uint256 constant alphay = 1822605387108025140575069082054190850227141558696531247142891893091219886493;
32
+ uint256 constant betax1 = 6151367606487818189201999906120650299611606451623678689177389411304419268223;
33
+ uint256 constant betax2 = 9585957668075684565639768228347335094019763845243950076866922751115551536304;
34
+ uint256 constant betay1 = 2026097150013581222441635945892661894188408324649667941263256601457130520770;
35
+ uint256 constant betay2 = 16354572769783365930749379657708807277561854621377074748225632025050952415294;
36
+ uint256 constant gammax1 = 11559732032986387107991004021392285783925812861821192530917403151452391805634;
37
+ uint256 constant gammax2 = 10857046999023057135944570762232829481370756359578518086990519993285655852781;
38
+ uint256 constant gammay1 = 4082367875863433681332203403145435568316851327593401208105741076214120093531;
39
+ uint256 constant gammay2 = 8495653923123431417604973247489272438418190587263600148770280649306958101930;
40
+ uint256 constant deltax1 = 146777209207054605867012766179094502537968350551215607925008955076263549067;
41
+ uint256 constant deltax2 = 2633871596100807401284925083226459189796882085586154321492118367916651237117;
42
+ uint256 constant deltay1 = 21012385740760062171685374025920180961146768579042536716146176459660919755825;
43
+ uint256 constant deltay2 = 609193939489547291159258179603724194177454651776958423928855714448170018063;
44
+
45
+
46
+ uint256 constant IC0x = 14336108542425917447460243179215548887531443288921789758034763267112594821597;
47
+ uint256 constant IC0y = 3063213467055302869374991715296034939540087046417250761544285949694763841224;
48
+
49
+ uint256 constant IC1x = 4649077026587766761105661538801822811988500686660034528257902152995286226420;
50
+ uint256 constant IC1y = 12476233742593937621066536626700126467027086901944282038169835118443143832808;
51
+
52
+ uint256 constant IC2x = 8360661053332583973195437525518843345679737721254788511839602890275293657231;
53
+ uint256 constant IC2y = 17787996208475963315027667576666223922798463669064180714282632392130781352372;
54
+
55
+ uint256 constant IC3x = 9785946569079751391790764046446286786358664716750710071871199052326292539659;
56
+ uint256 constant IC3y = 882817021266081946311354002521419385351487574180348607719516996266190947737;
57
+
58
+ uint256 constant IC4x = 12640809291531477845870075407023311270862795189161180453532797575567652906794;
59
+ uint256 constant IC4y = 19250290048961761008598356232356849064316055284499983192468783482080590733004;
60
+
61
+ uint256 constant IC5x = 3198295856781295857057806156834726458390487561260194669912832637191868555057;
62
+ uint256 constant IC5y = 8868721020835362932335076322428234697810491236107884777501043742060235784522;
63
+
64
+ uint256 constant IC6x = 2390514925938908056105222000048474798061414661077134335973534900416551578765;
65
+ uint256 constant IC6y = 18883933119651599452018586778571926484219893156571441861996812826417265802414;
66
+
67
+ uint256 constant IC7x = 15567735182868663313348652396736838594417606007485390406094199614279723158262;
68
+ uint256 constant IC7y = 19899783647699456279776467890503763801710062356400886856148489342470135803967;
69
+
70
+ uint256 constant IC8x = 2922198146313718955094653112638333704853847719783139987672963810850958623221;
71
+ uint256 constant IC8y = 3211087459991011312413694578006874376946148198550163814081916529506248827593;
72
+
73
+ uint256 constant IC9x = 9280481517335805553019773877827568388027208648564094894076810187486828340182;
74
+ uint256 constant IC9y = 2731446469023583556556729659060863588647053155331668021298670538047182930916;
75
+
76
+ uint256 constant IC10x = 7035120402594659715437206973891969111861616263537882691220816912555808912102;
77
+ uint256 constant IC10y = 8370859161564184043870414118742730294716324516315488627679669627182324762731;
78
+
79
+ uint256 constant IC11x = 18252892156409549471503582711942818186827898810269534550816546500103237657138;
80
+ uint256 constant IC11y = 6950088786053252068858608708134843976953853650037336267170927255140899434651;
81
+
82
+ uint256 constant IC12x = 1755334072548569264255483825752328756660188502261310823252508026502612340595;
83
+ uint256 constant IC12y = 12909479005409400076810176928877098887011256368485947999972819085993034755040;
84
+
85
+ uint256 constant IC13x = 16552097706159454847442530278886453064027141214501763360789580344863692453677;
86
+ uint256 constant IC13y = 5953929881514293853952996241019965086771550587823788071996449823934001732390;
87
+
88
+ uint256 constant IC14x = 3619185968560138174014630305975632830516758120217041036852576895912618097991;
89
+ uint256 constant IC14y = 9281821052864420364933957831589472205720239940338123268483559666384084907310;
90
+
91
+ uint256 constant IC15x = 8254503030347082641414552423570190634778931316381219189926097849958527585897;
92
+ uint256 constant IC15y = 364992073027338908344465820235200531762259034144802123806746602200531788638;
93
+
94
+ uint256 constant IC16x = 5526967546231986666584937042885735121525132484493928084139764638439494777879;
95
+ uint256 constant IC16y = 5238298736071644765241632504874656258530712298519490697816165224135772674015;
96
+
97
+ uint256 constant IC17x = 11928052158849068333141322537401085721326834497814420594439681913154248710859;
98
+ uint256 constant IC17y = 6819923895885234828441212107217745771874421854826251598301558050245481472152;
99
+
100
+ uint256 constant IC18x = 13945286268685774585609284245816122274534387542425213152741186224804686735403;
101
+ uint256 constant IC18y = 20023689850736852834109177652413698312032305876184320679250698041789812935094;
102
+
103
+ uint256 constant IC19x = 7345507858994618648486291116179494001930311013835063487161165329704325424673;
104
+ uint256 constant IC19y = 13928084575810620402150382964740122579679242576231832883484884405840679683901;
105
+
106
+ uint256 constant IC20x = 1542441211724186377808041204123941120846139064048464703338728903271040045155;
107
+ uint256 constant IC20y = 3137377505747175717463089909181680260568123949190130340237345349107426734620;
108
+
109
+ uint256 constant IC21x = 18089876871595627141331157080961334994521269475674526479685363215994451907921;
110
+ uint256 constant IC21y = 9556757584162576607270540349818518035313172920973593402949336403762080493424;
111
+
112
+ uint256 constant IC22x = 2126963146484286503213121003041916545819167147574473267028159001088956325722;
113
+ uint256 constant IC22y = 4923799230582507077776334588235423484373707349019813468005175190929445597332;
114
+
115
+ uint256 constant IC23x = 1630008211499579806083756573010653820366097456772208529610704186894072654114;
116
+ uint256 constant IC23y = 21437256692871950627902345579957133056203192045088530552506588351495386493166;
117
+
118
+ uint256 constant IC24x = 6235978833784508527303135386340770208795082800621337764375680315249012051641;
119
+ uint256 constant IC24y = 12520301994905913552569827428623824498834825369768182952275266194107133887225;
120
+
121
+ uint256 constant IC25x = 9557042378880522891280724245561857565447408880647499944291316491268970962716;
122
+ uint256 constant IC25y = 4173053254415271189443551378493704301370073903364032874912232886621214855107;
123
+
124
+ uint256 constant IC26x = 5558907137697988062356440590341908538012066339933041966524965383919631140772;
125
+ uint256 constant IC26y = 1265354759221499511400922895984559714213033403777454282193151605098116101224;
126
+
127
+ uint256 constant IC27x = 9751551689854585596056969317163661915316163388666152587113212932637176997224;
128
+ uint256 constant IC27y = 686959062408464500590766187395139140177788305086921348267296100926858548877;
129
+
130
+ uint256 constant IC28x = 15204338996215015644140305596940498013424414654865369050416831529709084870388;
131
+ uint256 constant IC28y = 17585032747777531711309342640732261489304745528556013313094390294891315463238;
132
+
133
+ uint256 constant IC29x = 8528266626121058510818266872617216484482519464579558987555612207506785300417;
134
+ uint256 constant IC29y = 12342223818139102981014759549174695502236137848012989763919197196673493022149;
135
+
136
+ uint256 constant IC30x = 17119266520828561648406080997934525667613304604584000471035966025020243600422;
137
+ uint256 constant IC30y = 18421665471214296462582991761975569758896336070160927846098291580332941148620;
138
+
139
+ uint256 constant IC31x = 4742762351654917727826973627189432694622053729108562318066638202153782440166;
140
+ uint256 constant IC31y = 296418244077098783759573476971605864587653722780349167140381095009970460627;
141
+
142
+ uint256 constant IC32x = 6373420478804238387526525255482563203767655965084763378892963777920233699752;
143
+ uint256 constant IC32y = 5240958927388120686836069809918888077195822596812702309572478339377048402239;
144
+
145
+ uint256 constant IC33x = 13182478548935811389881548821935789228860539963311772803469562081018115532203;
146
+ uint256 constant IC33y = 19284181554103240542859588738713963104558064730061150915875196846838455400202;
147
+
148
+ uint256 constant IC34x = 21857338780008700862459533002904678051496231226601438919471980062102870905222;
149
+ uint256 constant IC34y = 3162181165857557107956455208621687938114163201485659733697090034359684494963;
150
+
151
+ uint256 constant IC35x = 18030435880968799586938446245851850883375555870437835535112389707810653422623;
152
+ uint256 constant IC35y = 6125202981561085887220354823672469411551765147522670503222156517716519021152;
153
+
154
+ uint256 constant IC36x = 20499082633153844200671399519686952035360656473274597348828366396398130332391;
155
+ uint256 constant IC36y = 13503388222737966031252942835877664971660349955260197529036833213452538737513;
156
+
157
+ uint256 constant IC37x = 9976650628289049705156258459926814563874838911412039589394403452533373103130;
158
+ uint256 constant IC37y = 18608902514616151728316800918889818634703085071916159657497665588826618088908;
159
+
160
+ uint256 constant IC38x = 16784044963369659319370859422589778652522513891006184311796525491223728540376;
161
+ uint256 constant IC38y = 8419252415782463868730211466135640742417360023777427336012667855758092038197;
162
+
163
+ uint256 constant IC39x = 19129231125664208150578540534225171515241799100174060685106316051780978435187;
164
+ uint256 constant IC39y = 973856925697381735132603011380839579759091829854878575966871466822882495496;
165
+
166
+ uint256 constant IC40x = 14184795124277783646007275929709329324671049214116615584525996529650843521730;
167
+ uint256 constant IC40y = 1859538865466811488301745101236111602321138751356202468635736130353767165622;
168
+
169
+ uint256 constant IC41x = 18975537178323438898430609035810514729962354228862856866418673050920797403688;
170
+ uint256 constant IC41y = 185704805308515213561416117318340746577106200793007151416881264294248110191;
171
+
172
+ uint256 constant IC42x = 12125731756235036914584256713314621906042150042060439205906356190683778190245;
173
+ uint256 constant IC42y = 348763894998779702959420179945011307061937360949313997838646683785393984577;
174
+
175
+ uint256 constant IC43x = 7988582464934572644816260889693611174097545127855725643395669489301033617204;
176
+ uint256 constant IC43y = 3364614427630396450372969209269125691931038516189762459489331306338139035298;
177
+
178
+
179
+ // Memory data
180
+ uint16 constant pVk = 0;
181
+ uint16 constant pPairing = 128;
182
+
183
+ uint16 constant pLastMem = 896;
184
+
185
+ function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[43] calldata _pubSignals) public view returns (bool) {
186
+ assembly {
187
+ function checkField(v) {
188
+ if iszero(lt(v, q)) {
189
+ mstore(0, 0)
190
+ return(0, 0x20)
191
+ }
192
+ }
193
+
194
+ // G1 function to multiply a G1 value(x,y) to value in an address
195
+ function g1_mulAccC(pR, x, y, s) {
196
+ let success
197
+ let mIn := mload(0x40)
198
+ mstore(mIn, x)
199
+ mstore(add(mIn, 32), y)
200
+ mstore(add(mIn, 64), s)
201
+
202
+ success := staticcall(sub(gas(), 2000), 7, mIn, 96, mIn, 64)
203
+
204
+ if iszero(success) {
205
+ mstore(0, 0)
206
+ return(0, 0x20)
207
+ }
208
+
209
+ mstore(add(mIn, 64), mload(pR))
210
+ mstore(add(mIn, 96), mload(add(pR, 32)))
211
+
212
+ success := staticcall(sub(gas(), 2000), 6, mIn, 128, pR, 64)
213
+
214
+ if iszero(success) {
215
+ mstore(0, 0)
216
+ return(0, 0x20)
217
+ }
218
+ }
219
+
220
+ function checkPairing(pA, pB, pC, pubSignals, pMem) -> isOk {
221
+ let _pPairing := add(pMem, pPairing)
222
+ let _pVk := add(pMem, pVk)
223
+
224
+ mstore(_pVk, IC0x)
225
+ mstore(add(_pVk, 32), IC0y)
226
+
227
+ // Compute the linear combination vk_x
228
+
229
+ g1_mulAccC(_pVk, IC1x, IC1y, calldataload(add(pubSignals, 0)))
230
+
231
+ g1_mulAccC(_pVk, IC2x, IC2y, calldataload(add(pubSignals, 32)))
232
+
233
+ g1_mulAccC(_pVk, IC3x, IC3y, calldataload(add(pubSignals, 64)))
234
+
235
+ g1_mulAccC(_pVk, IC4x, IC4y, calldataload(add(pubSignals, 96)))
236
+
237
+ g1_mulAccC(_pVk, IC5x, IC5y, calldataload(add(pubSignals, 128)))
238
+
239
+ g1_mulAccC(_pVk, IC6x, IC6y, calldataload(add(pubSignals, 160)))
240
+
241
+ g1_mulAccC(_pVk, IC7x, IC7y, calldataload(add(pubSignals, 192)))
242
+
243
+ g1_mulAccC(_pVk, IC8x, IC8y, calldataload(add(pubSignals, 224)))
244
+
245
+ g1_mulAccC(_pVk, IC9x, IC9y, calldataload(add(pubSignals, 256)))
246
+
247
+ g1_mulAccC(_pVk, IC10x, IC10y, calldataload(add(pubSignals, 288)))
248
+
249
+ g1_mulAccC(_pVk, IC11x, IC11y, calldataload(add(pubSignals, 320)))
250
+
251
+ g1_mulAccC(_pVk, IC12x, IC12y, calldataload(add(pubSignals, 352)))
252
+
253
+ g1_mulAccC(_pVk, IC13x, IC13y, calldataload(add(pubSignals, 384)))
254
+
255
+ g1_mulAccC(_pVk, IC14x, IC14y, calldataload(add(pubSignals, 416)))
256
+
257
+ g1_mulAccC(_pVk, IC15x, IC15y, calldataload(add(pubSignals, 448)))
258
+
259
+ g1_mulAccC(_pVk, IC16x, IC16y, calldataload(add(pubSignals, 480)))
260
+
261
+ g1_mulAccC(_pVk, IC17x, IC17y, calldataload(add(pubSignals, 512)))
262
+
263
+ g1_mulAccC(_pVk, IC18x, IC18y, calldataload(add(pubSignals, 544)))
264
+
265
+ g1_mulAccC(_pVk, IC19x, IC19y, calldataload(add(pubSignals, 576)))
266
+
267
+ g1_mulAccC(_pVk, IC20x, IC20y, calldataload(add(pubSignals, 608)))
268
+
269
+ g1_mulAccC(_pVk, IC21x, IC21y, calldataload(add(pubSignals, 640)))
270
+
271
+ g1_mulAccC(_pVk, IC22x, IC22y, calldataload(add(pubSignals, 672)))
272
+
273
+ g1_mulAccC(_pVk, IC23x, IC23y, calldataload(add(pubSignals, 704)))
274
+
275
+ g1_mulAccC(_pVk, IC24x, IC24y, calldataload(add(pubSignals, 736)))
276
+
277
+ g1_mulAccC(_pVk, IC25x, IC25y, calldataload(add(pubSignals, 768)))
278
+
279
+ g1_mulAccC(_pVk, IC26x, IC26y, calldataload(add(pubSignals, 800)))
280
+
281
+ g1_mulAccC(_pVk, IC27x, IC27y, calldataload(add(pubSignals, 832)))
282
+
283
+ g1_mulAccC(_pVk, IC28x, IC28y, calldataload(add(pubSignals, 864)))
284
+
285
+ g1_mulAccC(_pVk, IC29x, IC29y, calldataload(add(pubSignals, 896)))
286
+
287
+ g1_mulAccC(_pVk, IC30x, IC30y, calldataload(add(pubSignals, 928)))
288
+
289
+ g1_mulAccC(_pVk, IC31x, IC31y, calldataload(add(pubSignals, 960)))
290
+
291
+ g1_mulAccC(_pVk, IC32x, IC32y, calldataload(add(pubSignals, 992)))
292
+
293
+ g1_mulAccC(_pVk, IC33x, IC33y, calldataload(add(pubSignals, 1024)))
294
+
295
+ g1_mulAccC(_pVk, IC34x, IC34y, calldataload(add(pubSignals, 1056)))
296
+
297
+ g1_mulAccC(_pVk, IC35x, IC35y, calldataload(add(pubSignals, 1088)))
298
+
299
+ g1_mulAccC(_pVk, IC36x, IC36y, calldataload(add(pubSignals, 1120)))
300
+
301
+ g1_mulAccC(_pVk, IC37x, IC37y, calldataload(add(pubSignals, 1152)))
302
+
303
+ g1_mulAccC(_pVk, IC38x, IC38y, calldataload(add(pubSignals, 1184)))
304
+
305
+ g1_mulAccC(_pVk, IC39x, IC39y, calldataload(add(pubSignals, 1216)))
306
+
307
+ g1_mulAccC(_pVk, IC40x, IC40y, calldataload(add(pubSignals, 1248)))
308
+
309
+ g1_mulAccC(_pVk, IC41x, IC41y, calldataload(add(pubSignals, 1280)))
310
+
311
+ g1_mulAccC(_pVk, IC42x, IC42y, calldataload(add(pubSignals, 1312)))
312
+
313
+ g1_mulAccC(_pVk, IC43x, IC43y, calldataload(add(pubSignals, 1344)))
314
+
315
+
316
+ // -A
317
+ mstore(_pPairing, calldataload(pA))
318
+ mstore(add(_pPairing, 32), mod(sub(q, calldataload(add(pA, 32))), q))
319
+
320
+ // B
321
+ mstore(add(_pPairing, 64), calldataload(pB))
322
+ mstore(add(_pPairing, 96), calldataload(add(pB, 32)))
323
+ mstore(add(_pPairing, 128), calldataload(add(pB, 64)))
324
+ mstore(add(_pPairing, 160), calldataload(add(pB, 96)))
325
+
326
+ // alpha1
327
+ mstore(add(_pPairing, 192), alphax)
328
+ mstore(add(_pPairing, 224), alphay)
329
+
330
+ // beta2
331
+ mstore(add(_pPairing, 256), betax1)
332
+ mstore(add(_pPairing, 288), betax2)
333
+ mstore(add(_pPairing, 320), betay1)
334
+ mstore(add(_pPairing, 352), betay2)
335
+
336
+ // vk_x
337
+ mstore(add(_pPairing, 384), mload(add(pMem, pVk)))
338
+ mstore(add(_pPairing, 416), mload(add(pMem, add(pVk, 32))))
339
+
340
+
341
+ // gamma2
342
+ mstore(add(_pPairing, 448), gammax1)
343
+ mstore(add(_pPairing, 480), gammax2)
344
+ mstore(add(_pPairing, 512), gammay1)
345
+ mstore(add(_pPairing, 544), gammay2)
346
+
347
+ // C
348
+ mstore(add(_pPairing, 576), calldataload(pC))
349
+ mstore(add(_pPairing, 608), calldataload(add(pC, 32)))
350
+
351
+ // delta2
352
+ mstore(add(_pPairing, 640), deltax1)
353
+ mstore(add(_pPairing, 672), deltax2)
354
+ mstore(add(_pPairing, 704), deltay1)
355
+ mstore(add(_pPairing, 736), deltay2)
356
+
357
+
358
+ let success := staticcall(sub(gas(), 2000), 8, _pPairing, 768, _pPairing, 0x20)
359
+
360
+ isOk := and(success, mload(_pPairing))
361
+ }
362
+
363
+ let pMem := mload(0x40)
364
+ mstore(0x40, add(pMem, pLastMem))
365
+
366
+ // Validate that all evaluations ∈ F
367
+
368
+ checkField(calldataload(add(_pubSignals, 0)))
369
+
370
+ checkField(calldataload(add(_pubSignals, 32)))
371
+
372
+ checkField(calldataload(add(_pubSignals, 64)))
373
+
374
+ checkField(calldataload(add(_pubSignals, 96)))
375
+
376
+ checkField(calldataload(add(_pubSignals, 128)))
377
+
378
+ checkField(calldataload(add(_pubSignals, 160)))
379
+
380
+ checkField(calldataload(add(_pubSignals, 192)))
381
+
382
+ checkField(calldataload(add(_pubSignals, 224)))
383
+
384
+ checkField(calldataload(add(_pubSignals, 256)))
385
+
386
+ checkField(calldataload(add(_pubSignals, 288)))
387
+
388
+ checkField(calldataload(add(_pubSignals, 320)))
389
+
390
+ checkField(calldataload(add(_pubSignals, 352)))
391
+
392
+ checkField(calldataload(add(_pubSignals, 384)))
393
+
394
+ checkField(calldataload(add(_pubSignals, 416)))
395
+
396
+ checkField(calldataload(add(_pubSignals, 448)))
397
+
398
+ checkField(calldataload(add(_pubSignals, 480)))
399
+
400
+ checkField(calldataload(add(_pubSignals, 512)))
401
+
402
+ checkField(calldataload(add(_pubSignals, 544)))
403
+
404
+ checkField(calldataload(add(_pubSignals, 576)))
405
+
406
+ checkField(calldataload(add(_pubSignals, 608)))
407
+
408
+ checkField(calldataload(add(_pubSignals, 640)))
409
+
410
+ checkField(calldataload(add(_pubSignals, 672)))
411
+
412
+ checkField(calldataload(add(_pubSignals, 704)))
413
+
414
+ checkField(calldataload(add(_pubSignals, 736)))
415
+
416
+ checkField(calldataload(add(_pubSignals, 768)))
417
+
418
+ checkField(calldataload(add(_pubSignals, 800)))
419
+
420
+ checkField(calldataload(add(_pubSignals, 832)))
421
+
422
+ checkField(calldataload(add(_pubSignals, 864)))
423
+
424
+ checkField(calldataload(add(_pubSignals, 896)))
425
+
426
+ checkField(calldataload(add(_pubSignals, 928)))
427
+
428
+ checkField(calldataload(add(_pubSignals, 960)))
429
+
430
+ checkField(calldataload(add(_pubSignals, 992)))
431
+
432
+ checkField(calldataload(add(_pubSignals, 1024)))
433
+
434
+ checkField(calldataload(add(_pubSignals, 1056)))
435
+
436
+ checkField(calldataload(add(_pubSignals, 1088)))
437
+
438
+ checkField(calldataload(add(_pubSignals, 1120)))
439
+
440
+ checkField(calldataload(add(_pubSignals, 1152)))
441
+
442
+ checkField(calldataload(add(_pubSignals, 1184)))
443
+
444
+ checkField(calldataload(add(_pubSignals, 1216)))
445
+
446
+ checkField(calldataload(add(_pubSignals, 1248)))
447
+
448
+ checkField(calldataload(add(_pubSignals, 1280)))
449
+
450
+ checkField(calldataload(add(_pubSignals, 1312)))
451
+
452
+ checkField(calldataload(add(_pubSignals, 1344)))
453
+
454
+ checkField(calldataload(add(_pubSignals, 1376)))
455
+
456
+
457
+ // Validate all evaluations
458
+ let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem)
459
+
460
+ mstore(0, isValid)
461
+ return(0, 0x20)
462
+ }
463
+ }
464
+ }
@@ -0,0 +1,247 @@
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 Groth16VerifierJSON {
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 = 20906723375066628996538723964948705883807515490851236717549543933647949219571;
31
+ uint256 constant alphay = 16603277405602064515576336929405274585704793668006611444340674010517699111175;
32
+ uint256 constant betax1 = 15094144295718056060696456976805274960280819890173699163580614297205641683890;
33
+ uint256 constant betax2 = 2598197794696234583089212408001367512889853689394097760090270035862816362448;
34
+ uint256 constant betay1 = 13019389669452630605176375079598340867413494236340581417103700533129069013294;
35
+ uint256 constant betay2 = 17948608722772603517072567060031950359342932415845723852078363636578090462964;
36
+ uint256 constant gammax1 = 11559732032986387107991004021392285783925812861821192530917403151452391805634;
37
+ uint256 constant gammax2 = 10857046999023057135944570762232829481370756359578518086990519993285655852781;
38
+ uint256 constant gammay1 = 4082367875863433681332203403145435568316851327593401208105741076214120093531;
39
+ uint256 constant gammay2 = 8495653923123431417604973247489272438418190587263600148770280649306958101930;
40
+ uint256 constant deltax1 = 16323886806377948767625289345386923912488425685292264502851407533751890364893;
41
+ uint256 constant deltax2 = 15728036135898260810892479278030679906213338463446298332250898095140196532350;
42
+ uint256 constant deltay1 = 7311361608150524708643711937539709432213365833416427921151717898214981893794;
43
+ uint256 constant deltay2 = 5360237348765695204487062346058482342794521371770543578645384390456849442785;
44
+
45
+
46
+ uint256 constant IC0x = 11086791052709537593958527982551466373543557342479473456486918346706557110272;
47
+ uint256 constant IC0y = 20506728735254563637401848289764804706365355653222631223947955738675551382105;
48
+
49
+ uint256 constant IC1x = 3395672018504856885331557568801382430991065622809977080049087938633695466505;
50
+ uint256 constant IC1y = 16008515660025396265007279223380117478922266924915694760300639683710667540804;
51
+
52
+ uint256 constant IC2x = 21765086794018723313508040688349754864858333265049520578918793850946099000275;
53
+ uint256 constant IC2y = 697811386339903182398036069234656900767187661360875928460814734795207770242;
54
+
55
+ uint256 constant IC3x = 19890134840469468860269808836413274874961102551504281644286795822862783578836;
56
+ uint256 constant IC3y = 10501563686653873312925081348712045837799559277882754134863746661191456585317;
57
+
58
+ uint256 constant IC4x = 3369539760301949842926296294765952701286437018123521538030683232199073077793;
59
+ uint256 constant IC4y = 17029305206701174018920590641604979023986372135961726666915339433517762654894;
60
+
61
+ uint256 constant IC5x = 16249858468384073197585049724261300836640451596079332252974671216468387477562;
62
+ uint256 constant IC5y = 15430518669979717234332245816406403303816581724709051740811390921375347110404;
63
+
64
+ uint256 constant IC6x = 15005432332128787752647304265070458721246744260154464921566645180007742802279;
65
+ uint256 constant IC6y = 12228853074973908182958795852882093001137862796451033278357411806506635324421;
66
+
67
+ uint256 constant IC7x = 8279149102391716348028737479566814742618645832848275208331642895717107868296;
68
+ uint256 constant IC7y = 9028245630419080537816021983399031211599915437683007034212436702559232452386;
69
+
70
+ uint256 constant IC8x = 9920315178591554201395269399878868095438996004668427910727172420497691574268;
71
+ uint256 constant IC8y = 13977539708344722958417991918934496531835259337681036150638988886470196226252;
72
+
73
+ uint256 constant IC9x = 64865284880675837338119066159408029670824664912895548295809933993597129855;
74
+ uint256 constant IC9y = 16596614162936398597796948615700133880646516840294055167278997135786201638865;
75
+
76
+ uint256 constant IC10x = 20041216278333661355857000399562164892538427870735609885548447419114215265900;
77
+ uint256 constant IC10y = 7188425125877597681508434156838946918685965411196380330181753494345911319474;
78
+
79
+ uint256 constant IC11x = 10344667596317540812042141319424780533548696928275174590606414302423871416439;
80
+ uint256 constant IC11y = 15177912543756596934916481207669485500307163540835148656062032711878901603531;
81
+
82
+ uint256 constant IC12x = 3003572233500184455318954446784006239696026573012811847295348627074111281539;
83
+ uint256 constant IC12y = 6485361686957307324235352983357156310358934769793375149333110905137006337248;
84
+
85
+
86
+ // Memory data
87
+ uint16 constant pVk = 0;
88
+ uint16 constant pPairing = 128;
89
+
90
+ uint16 constant pLastMem = 896;
91
+
92
+ function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[12] calldata _pubSignals) public view returns (bool) {
93
+ assembly {
94
+ function checkField(v) {
95
+ if iszero(lt(v, q)) {
96
+ mstore(0, 0)
97
+ return(0, 0x20)
98
+ }
99
+ }
100
+
101
+ // G1 function to multiply a G1 value(x,y) to value in an address
102
+ function g1_mulAccC(pR, x, y, s) {
103
+ let success
104
+ let mIn := mload(0x40)
105
+ mstore(mIn, x)
106
+ mstore(add(mIn, 32), y)
107
+ mstore(add(mIn, 64), s)
108
+
109
+ success := staticcall(sub(gas(), 2000), 7, mIn, 96, mIn, 64)
110
+
111
+ if iszero(success) {
112
+ mstore(0, 0)
113
+ return(0, 0x20)
114
+ }
115
+
116
+ mstore(add(mIn, 64), mload(pR))
117
+ mstore(add(mIn, 96), mload(add(pR, 32)))
118
+
119
+ success := staticcall(sub(gas(), 2000), 6, mIn, 128, pR, 64)
120
+
121
+ if iszero(success) {
122
+ mstore(0, 0)
123
+ return(0, 0x20)
124
+ }
125
+ }
126
+
127
+ function checkPairing(pA, pB, pC, pubSignals, pMem) -> isOk {
128
+ let _pPairing := add(pMem, pPairing)
129
+ let _pVk := add(pMem, pVk)
130
+
131
+ mstore(_pVk, IC0x)
132
+ mstore(add(_pVk, 32), IC0y)
133
+
134
+ // Compute the linear combination vk_x
135
+
136
+ g1_mulAccC(_pVk, IC1x, IC1y, calldataload(add(pubSignals, 0)))
137
+
138
+ g1_mulAccC(_pVk, IC2x, IC2y, calldataload(add(pubSignals, 32)))
139
+
140
+ g1_mulAccC(_pVk, IC3x, IC3y, calldataload(add(pubSignals, 64)))
141
+
142
+ g1_mulAccC(_pVk, IC4x, IC4y, calldataload(add(pubSignals, 96)))
143
+
144
+ g1_mulAccC(_pVk, IC5x, IC5y, calldataload(add(pubSignals, 128)))
145
+
146
+ g1_mulAccC(_pVk, IC6x, IC6y, calldataload(add(pubSignals, 160)))
147
+
148
+ g1_mulAccC(_pVk, IC7x, IC7y, calldataload(add(pubSignals, 192)))
149
+
150
+ g1_mulAccC(_pVk, IC8x, IC8y, calldataload(add(pubSignals, 224)))
151
+
152
+ g1_mulAccC(_pVk, IC9x, IC9y, calldataload(add(pubSignals, 256)))
153
+
154
+ g1_mulAccC(_pVk, IC10x, IC10y, calldataload(add(pubSignals, 288)))
155
+
156
+ g1_mulAccC(_pVk, IC11x, IC11y, calldataload(add(pubSignals, 320)))
157
+
158
+ g1_mulAccC(_pVk, IC12x, IC12y, calldataload(add(pubSignals, 352)))
159
+
160
+
161
+ // -A
162
+ mstore(_pPairing, calldataload(pA))
163
+ mstore(add(_pPairing, 32), mod(sub(q, calldataload(add(pA, 32))), q))
164
+
165
+ // B
166
+ mstore(add(_pPairing, 64), calldataload(pB))
167
+ mstore(add(_pPairing, 96), calldataload(add(pB, 32)))
168
+ mstore(add(_pPairing, 128), calldataload(add(pB, 64)))
169
+ mstore(add(_pPairing, 160), calldataload(add(pB, 96)))
170
+
171
+ // alpha1
172
+ mstore(add(_pPairing, 192), alphax)
173
+ mstore(add(_pPairing, 224), alphay)
174
+
175
+ // beta2
176
+ mstore(add(_pPairing, 256), betax1)
177
+ mstore(add(_pPairing, 288), betax2)
178
+ mstore(add(_pPairing, 320), betay1)
179
+ mstore(add(_pPairing, 352), betay2)
180
+
181
+ // vk_x
182
+ mstore(add(_pPairing, 384), mload(add(pMem, pVk)))
183
+ mstore(add(_pPairing, 416), mload(add(pMem, add(pVk, 32))))
184
+
185
+
186
+ // gamma2
187
+ mstore(add(_pPairing, 448), gammax1)
188
+ mstore(add(_pPairing, 480), gammax2)
189
+ mstore(add(_pPairing, 512), gammay1)
190
+ mstore(add(_pPairing, 544), gammay2)
191
+
192
+ // C
193
+ mstore(add(_pPairing, 576), calldataload(pC))
194
+ mstore(add(_pPairing, 608), calldataload(add(pC, 32)))
195
+
196
+ // delta2
197
+ mstore(add(_pPairing, 640), deltax1)
198
+ mstore(add(_pPairing, 672), deltax2)
199
+ mstore(add(_pPairing, 704), deltay1)
200
+ mstore(add(_pPairing, 736), deltay2)
201
+
202
+
203
+ let success := staticcall(sub(gas(), 2000), 8, _pPairing, 768, _pPairing, 0x20)
204
+
205
+ isOk := and(success, mload(_pPairing))
206
+ }
207
+
208
+ let pMem := mload(0x40)
209
+ mstore(0x40, add(pMem, pLastMem))
210
+
211
+ // Validate that all evaluations ∈ F
212
+
213
+ checkField(calldataload(add(_pubSignals, 0)))
214
+
215
+ checkField(calldataload(add(_pubSignals, 32)))
216
+
217
+ checkField(calldataload(add(_pubSignals, 64)))
218
+
219
+ checkField(calldataload(add(_pubSignals, 96)))
220
+
221
+ checkField(calldataload(add(_pubSignals, 128)))
222
+
223
+ checkField(calldataload(add(_pubSignals, 160)))
224
+
225
+ checkField(calldataload(add(_pubSignals, 192)))
226
+
227
+ checkField(calldataload(add(_pubSignals, 224)))
228
+
229
+ checkField(calldataload(add(_pubSignals, 256)))
230
+
231
+ checkField(calldataload(add(_pubSignals, 288)))
232
+
233
+ checkField(calldataload(add(_pubSignals, 320)))
234
+
235
+ checkField(calldataload(add(_pubSignals, 352)))
236
+
237
+ checkField(calldataload(add(_pubSignals, 384)))
238
+
239
+
240
+ // Validate all evaluations
241
+ let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem)
242
+
243
+ mstore(0, isValid)
244
+ return(0, 0x20)
245
+ }
246
+ }
247
+ }
@@ -0,0 +1,240 @@
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 Groth16VerifierRU {
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 = 8154397773694967106321908543225581308345926075547707849461770589063806208933;
31
+ uint256 constant alphay = 5677108055266898448889486339855982693826760854574703967712162419621387623014;
32
+ uint256 constant betax1 = 4355293952982460708458173032048895255835173115891032808050720056003898803424;
33
+ uint256 constant betax2 = 3059800330157143526908077176335177789758447764497844662322128804304930412762;
34
+ uint256 constant betay1 = 12948155637479005941322226125984465377528965309571693953410360452319923301251;
35
+ uint256 constant betay2 = 7332222563511878888805485279601765944630172818413249156252409812683246711891;
36
+ uint256 constant gammax1 = 11559732032986387107991004021392285783925812861821192530917403151452391805634;
37
+ uint256 constant gammax2 = 10857046999023057135944570762232829481370756359578518086990519993285655852781;
38
+ uint256 constant gammay1 = 4082367875863433681332203403145435568316851327593401208105741076214120093531;
39
+ uint256 constant gammay2 = 8495653923123431417604973247489272438418190587263600148770280649306958101930;
40
+ uint256 constant deltax1 = 20503591479484091524389745903571071797103515451455738548515763475839920684921;
41
+ uint256 constant deltax2 = 5617943403828393228867947181181000280381763965560908736009901041763172427158;
42
+ uint256 constant deltay1 = 19083313989582849416852727426203922087129577621288485271208858162180563989517;
43
+ uint256 constant deltay2 = 6862756714407978275897080062526754044127957156216819881004695153747745594448;
44
+
45
+
46
+ uint256 constant IC0x = 8117166905692109919104291343856029475477412767491303376211389191152967038468;
47
+ uint256 constant IC0y = 9786515749803639719852807382408592347129424775311166090035686108630492765324;
48
+
49
+ uint256 constant IC1x = 8372619712685736857836778212277410061184000966061820660353663736436010324900;
50
+ uint256 constant IC1y = 7067497483771029122224543049910217766313555809959258482125432607420578209549;
51
+
52
+ uint256 constant IC2x = 8664544978528071254218294973797032588678014503773496766308416357733046318778;
53
+ uint256 constant IC2y = 1718370739886043626655047048989167081845643514431816517183086335106787323814;
54
+
55
+ uint256 constant IC3x = 17751478333748864683647456466294726036073972233143791990284780060329145813120;
56
+ uint256 constant IC3y = 5332438974111244723611637766367681701415489964863909660487320379077476391752;
57
+
58
+ uint256 constant IC4x = 20742828080385750796683930560189396553036781354782278562302384256732853843949;
59
+ uint256 constant IC4y = 1351673933396889997409523595926983213620423546050525776383348532660582633773;
60
+
61
+ uint256 constant IC5x = 20503268205499473416904271262498573431374552398139117269682363052068963140978;
62
+ uint256 constant IC5y = 3732804412299701993142127591762498360367649767364421523113109866299226710165;
63
+
64
+ uint256 constant IC6x = 14257995503266038917376264725392135727319727614567664291464265707947560137941;
65
+ uint256 constant IC6y = 341674734661014039525000101720981104421961371042562178520683297866596707154;
66
+
67
+ uint256 constant IC7x = 8193832556543527639708689676411352413933876589415237015016698770441031255042;
68
+ uint256 constant IC7y = 6594427869611603078697503063082014095062802376771554910392397589449346189644;
69
+
70
+ uint256 constant IC8x = 13583345943944676979948187443700187050998549308300528606491967244177176520006;
71
+ uint256 constant IC8y = 4938411793249197289917720689106756285526796809363092891408044710943884674802;
72
+
73
+ uint256 constant IC9x = 11332284497411134754454830299053795514601435700763578724160974435166700044531;
74
+ uint256 constant IC9y = 13019000604073974366403109311897527900603263821666939992822627393063021671404;
75
+
76
+ uint256 constant IC10x = 14399226292391120536283418546213611923264868223599916657548457588778188745914;
77
+ uint256 constant IC10y = 15721807309515116598525148493431362514780681023570830598111469229105621080436;
78
+
79
+ uint256 constant IC11x = 9762413796519510440691741324561546062505760014187240868624893625208356342750;
80
+ uint256 constant IC11y = 16246137136591544636923946475468706707718504791810616178029498386514365251482;
81
+
82
+
83
+ // Memory data
84
+ uint16 constant pVk = 0;
85
+ uint16 constant pPairing = 128;
86
+
87
+ uint16 constant pLastMem = 896;
88
+
89
+ function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[11] calldata _pubSignals) public view returns (bool) {
90
+ assembly {
91
+ function checkField(v) {
92
+ if iszero(lt(v, q)) {
93
+ mstore(0, 0)
94
+ return(0, 0x20)
95
+ }
96
+ }
97
+
98
+ // G1 function to multiply a G1 value(x,y) to value in an address
99
+ function g1_mulAccC(pR, x, y, s) {
100
+ let success
101
+ let mIn := mload(0x40)
102
+ mstore(mIn, x)
103
+ mstore(add(mIn, 32), y)
104
+ mstore(add(mIn, 64), s)
105
+
106
+ success := staticcall(sub(gas(), 2000), 7, mIn, 96, mIn, 64)
107
+
108
+ if iszero(success) {
109
+ mstore(0, 0)
110
+ return(0, 0x20)
111
+ }
112
+
113
+ mstore(add(mIn, 64), mload(pR))
114
+ mstore(add(mIn, 96), mload(add(pR, 32)))
115
+
116
+ success := staticcall(sub(gas(), 2000), 6, mIn, 128, pR, 64)
117
+
118
+ if iszero(success) {
119
+ mstore(0, 0)
120
+ return(0, 0x20)
121
+ }
122
+ }
123
+
124
+ function checkPairing(pA, pB, pC, pubSignals, pMem) -> isOk {
125
+ let _pPairing := add(pMem, pPairing)
126
+ let _pVk := add(pMem, pVk)
127
+
128
+ mstore(_pVk, IC0x)
129
+ mstore(add(_pVk, 32), IC0y)
130
+
131
+ // Compute the linear combination vk_x
132
+
133
+ g1_mulAccC(_pVk, IC1x, IC1y, calldataload(add(pubSignals, 0)))
134
+
135
+ g1_mulAccC(_pVk, IC2x, IC2y, calldataload(add(pubSignals, 32)))
136
+
137
+ g1_mulAccC(_pVk, IC3x, IC3y, calldataload(add(pubSignals, 64)))
138
+
139
+ g1_mulAccC(_pVk, IC4x, IC4y, calldataload(add(pubSignals, 96)))
140
+
141
+ g1_mulAccC(_pVk, IC5x, IC5y, calldataload(add(pubSignals, 128)))
142
+
143
+ g1_mulAccC(_pVk, IC6x, IC6y, calldataload(add(pubSignals, 160)))
144
+
145
+ g1_mulAccC(_pVk, IC7x, IC7y, calldataload(add(pubSignals, 192)))
146
+
147
+ g1_mulAccC(_pVk, IC8x, IC8y, calldataload(add(pubSignals, 224)))
148
+
149
+ g1_mulAccC(_pVk, IC9x, IC9y, calldataload(add(pubSignals, 256)))
150
+
151
+ g1_mulAccC(_pVk, IC10x, IC10y, calldataload(add(pubSignals, 288)))
152
+
153
+ g1_mulAccC(_pVk, IC11x, IC11y, calldataload(add(pubSignals, 320)))
154
+
155
+
156
+ // -A
157
+ mstore(_pPairing, calldataload(pA))
158
+ mstore(add(_pPairing, 32), mod(sub(q, calldataload(add(pA, 32))), q))
159
+
160
+ // B
161
+ mstore(add(_pPairing, 64), calldataload(pB))
162
+ mstore(add(_pPairing, 96), calldataload(add(pB, 32)))
163
+ mstore(add(_pPairing, 128), calldataload(add(pB, 64)))
164
+ mstore(add(_pPairing, 160), calldataload(add(pB, 96)))
165
+
166
+ // alpha1
167
+ mstore(add(_pPairing, 192), alphax)
168
+ mstore(add(_pPairing, 224), alphay)
169
+
170
+ // beta2
171
+ mstore(add(_pPairing, 256), betax1)
172
+ mstore(add(_pPairing, 288), betax2)
173
+ mstore(add(_pPairing, 320), betay1)
174
+ mstore(add(_pPairing, 352), betay2)
175
+
176
+ // vk_x
177
+ mstore(add(_pPairing, 384), mload(add(pMem, pVk)))
178
+ mstore(add(_pPairing, 416), mload(add(pMem, add(pVk, 32))))
179
+
180
+
181
+ // gamma2
182
+ mstore(add(_pPairing, 448), gammax1)
183
+ mstore(add(_pPairing, 480), gammax2)
184
+ mstore(add(_pPairing, 512), gammay1)
185
+ mstore(add(_pPairing, 544), gammay2)
186
+
187
+ // C
188
+ mstore(add(_pPairing, 576), calldataload(pC))
189
+ mstore(add(_pPairing, 608), calldataload(add(pC, 32)))
190
+
191
+ // delta2
192
+ mstore(add(_pPairing, 640), deltax1)
193
+ mstore(add(_pPairing, 672), deltax2)
194
+ mstore(add(_pPairing, 704), deltay1)
195
+ mstore(add(_pPairing, 736), deltay2)
196
+
197
+
198
+ let success := staticcall(sub(gas(), 2000), 8, _pPairing, 768, _pPairing, 0x20)
199
+
200
+ isOk := and(success, mload(_pPairing))
201
+ }
202
+
203
+ let pMem := mload(0x40)
204
+ mstore(0x40, add(pMem, pLastMem))
205
+
206
+ // Validate that all evaluations ∈ F
207
+
208
+ checkField(calldataload(add(_pubSignals, 0)))
209
+
210
+ checkField(calldataload(add(_pubSignals, 32)))
211
+
212
+ checkField(calldataload(add(_pubSignals, 64)))
213
+
214
+ checkField(calldataload(add(_pubSignals, 96)))
215
+
216
+ checkField(calldataload(add(_pubSignals, 128)))
217
+
218
+ checkField(calldataload(add(_pubSignals, 160)))
219
+
220
+ checkField(calldataload(add(_pubSignals, 192)))
221
+
222
+ checkField(calldataload(add(_pubSignals, 224)))
223
+
224
+ checkField(calldataload(add(_pubSignals, 256)))
225
+
226
+ checkField(calldataload(add(_pubSignals, 288)))
227
+
228
+ checkField(calldataload(add(_pubSignals, 320)))
229
+
230
+ checkField(calldataload(add(_pubSignals, 352)))
231
+
232
+
233
+ // Validate all evaluations
234
+ let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem)
235
+
236
+ mstore(0, isValid)
237
+ return(0, 0x20)
238
+ }
239
+ }
240
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zkjson",
3
- "version": "0.1.31",
3
+ "version": "0.1.32",
4
4
  "description": "Zero Knowledge Provable JSON",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
package/fpjson.js DELETED
@@ -1,3 +0,0 @@
1
- function add(a, b) {}
2
-
3
- module.exports = { add }