zkjson 0.6.0 → 1.0.2
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 +537 -0
- package/assets/collection.png +0 -0
- package/assets/db.png +0 -0
- package/assets/encode.png +0 -0
- package/assets/query.png +0 -0
- package/assets/rollup.png +0 -0
- package/assets/structure.png +0 -0
- package/assets/weavedb.png +0 -0
- package/assets/zkjson.png +0 -0
- package/benchmark/components/ui/avatar.jsx +49 -0
- package/benchmark/components/ui/checkbox.jsx +17 -0
- package/benchmark/components/ui/close-button.jsx +20 -0
- package/benchmark/components/ui/color-mode.jsx +89 -0
- package/benchmark/components/ui/dialog.jsx +54 -0
- package/benchmark/components/ui/drawer.jsx +44 -0
- package/benchmark/components/ui/field.jsx +22 -0
- package/benchmark/components/ui/input-group.jsx +39 -0
- package/benchmark/components/ui/popover.jsx +49 -0
- package/benchmark/components/ui/provider.jsx +12 -0
- package/benchmark/components/ui/radio.jsx +17 -0
- package/benchmark/components/ui/slider.jsx +107 -0
- package/benchmark/components/ui/tooltip.jsx +35 -0
- package/benchmark/jsconfig.json +7 -0
- package/benchmark/lib/cbor.js +387 -0
- package/benchmark/lib/msgpack.js +651 -0
- package/benchmark/next.config.mjs +6 -0
- package/benchmark/package.json +22 -0
- package/benchmark/pages/_app.js +9 -0
- package/benchmark/pages/_document.js +13 -0
- package/benchmark/pages/api/hello.js +5 -0
- package/benchmark/pages/index.js +438 -0
- package/benchmark/public/favicon.ico +0 -0
- package/benchmark/public/file.svg +1 -0
- package/benchmark/public/globe.svg +1 -0
- package/benchmark/public/next.svg +1 -0
- package/benchmark/public/vercel.svg +1 -0
- package/benchmark/public/window.svg +1 -0
- package/benchmark/yarn.lock +2448 -0
- package/circom/collection/collection.circom +32 -0
- package/circom/collection/compile.sh +10 -0
- package/circom/collection/gen.js +34 -0
- package/circom/collection/generateInput.js +10 -0
- package/circom/collection/index.circom +4 -0
- package/circom/collection/test.js +21 -0
- package/circom/collection/verifier.sol +247 -0
- package/circom/db/compile.sh +10 -0
- package/circom/db/db.circom +39 -0
- package/circom/db/gen.js +30 -0
- package/circom/db/generateInput.js +10 -0
- package/circom/db/index.circom +4 -0
- package/circom/db/test.js +21 -0
- package/circom/db/verifier.sol +261 -0
- package/circom/ipfs/calculate_total.circom +17 -0
- package/circom/ipfs/compile.sh +10 -0
- package/circom/ipfs/gen.js +18 -0
- package/circom/ipfs/generateInput.js +10 -0
- package/circom/ipfs/index.circom +4 -0
- package/circom/ipfs/ipfs.circom +62 -0
- package/circom/ipfs/parse.circom +289 -0
- package/circom/ipfs/sha256.circom +99 -0
- package/circom/ipfs/test.js +167 -0
- package/circom/ipfs/verifier.sol +261 -0
- package/circom/json/compile.sh +10 -0
- package/circom/json/gen.js +22 -0
- package/circom/json/gen2.js +21 -0
- package/circom/json/generateInput.js +20 -0
- package/circom/json/index.circom +4 -0
- package/circom/json/json.circom +81 -0
- package/circom/json/test.js +100 -0
- package/circom/json/verifier.sol +247 -0
- package/circom/query/compile.sh +10 -0
- package/circom/query/gen.js +28 -0
- package/circom/query/generateInput.js +11 -0
- package/circom/query/index.circom +4 -0
- package/circom/query/query.circom +58 -0
- package/circom/query/test.js +20 -0
- package/circom/query/verifier.sol +177 -0
- package/circom/rollup/compile.sh +10 -0
- package/circom/rollup/gen.js +36 -0
- package/circom/rollup/generateInput.js +11 -0
- package/circom/rollup/index.circom +4 -0
- package/circom/rollup/rollup.circom +43 -0
- package/circom/rollup/test.js +35 -0
- package/circom/rollup/verifier.sol +240 -0
- package/circom/scripts/ceremony.js +39 -0
- package/circom/scripts/ceremony.sh +6 -0
- package/circom/scripts/compile.js +113 -0
- package/circom/scripts/compile.sh +16 -0
- package/circom/utils/uint.circom +512 -0
- package/circom/utils/utils.circom +628 -0
- package/demos/arweave/jsconfig.json +7 -0
- package/demos/arweave/lib/ZKArweave.json +617 -0
- package/demos/arweave/lib/encoder.js +375 -0
- package/demos/arweave/next.config.js +6 -0
- package/demos/arweave/package.json +26 -0
- package/demos/arweave/pages/_app.js +9 -0
- package/demos/arweave/pages/_document.js +19 -0
- package/demos/arweave/pages/api/arweave.js +31 -0
- package/demos/arweave/pages/api/hello.js +5 -0
- package/demos/arweave/pages/index.js +869 -0
- package/demos/arweave/public/circuit.wasm +0 -0
- package/demos/arweave/public/circuit_final.zkey +0 -0
- package/demos/arweave/public/verification_key.json +149 -0
- package/demos/arweave/vercel.json +7 -0
- package/demos/arweave/yarn.lock +2510 -0
- package/demos/simple/jsconfig.json +7 -0
- package/demos/simple/lib/encoder.js +375 -0
- package/demos/simple/next.config.js +6 -0
- package/demos/simple/package.json +24 -0
- package/demos/simple/pages/_app.js +9 -0
- package/demos/simple/pages/_document.js +13 -0
- package/demos/simple/pages/api/hello.js +5 -0
- package/demos/simple/pages/index.js +342 -0
- package/demos/simple/public/circuit.wasm +0 -0
- package/demos/simple/public/circuit_final.zkey +0 -0
- package/demos/simple/public/verification_key.json +149 -0
- package/demos/simple/yarn.lock +2519 -0
- package/docs/README.md +17 -0
- package/docs/simple-zkjson.md +210 -0
- package/docs/solidity-contracts.md +216 -0
- package/docs/zk-circuits.md +125 -0
- package/docs/zkdb-rollup.md +218 -0
- package/docs/zkjson-sdk.md +254 -0
- package/docs/zkjson-v1_5.md +365 -0
- package/package.json +16 -7
- package/sdk/contracts/NORollup.sol +13 -0
- package/sdk/package.json +15 -0
- package/sdk/yarn.lock +881 -0
- package/solidity/README.md +13 -0
- package/solidity/arguments.js +4 -0
- package/solidity/contracts/NORollup.sol +13 -0
- package/solidity/contracts/OPRollup.sol +14 -0
- package/solidity/contracts/ZKIPFS.sol +95 -0
- package/solidity/contracts/ZKJson.sol +21 -0
- package/solidity/contracts/ZKQuery.sol +286 -0
- package/solidity/contracts/ZKRollup.sol +35 -0
- package/solidity/contracts/apps/NORU.sol +66 -0
- package/solidity/contracts/apps/SimpleJSON.sol +64 -0
- package/solidity/contracts/apps/SimpleOPRU.sol +67 -0
- package/solidity/contracts/apps/SimpleRU.sol +67 -0
- package/solidity/contracts/apps/Token.sol +12 -0
- package/solidity/contracts/apps/ZKArweave.sol +89 -0
- package/solidity/contracts/apps/ZKBridge.sol +74 -0
- package/solidity/contracts/apps/ZKNFT.sol +63 -0
- package/solidity/contracts/verifiers/verifier_db.sol +275 -0
- package/solidity/contracts/verifiers/verifier_ipfs.sol +464 -0
- package/solidity/contracts/verifiers/verifier_json.sol +261 -0
- package/solidity/contracts/verifiers/verifier_rollup.sol +240 -0
- package/solidity/package.json +27 -0
- package/solidity/scripts/deploy.js +33 -0
- package/solidity/test/NORU.js +66 -0
- package/solidity/test/ZKArweave.js +97 -0
- package/solidity/test/arweave.js +55 -0
- package/solidity/test/bridge.js +71 -0
- package/solidity/test/simple.js +76 -0
- package/solidity/test/simpleOPRU.js +98 -0
- package/solidity/test/simpleRU.js +94 -0
- package/solidity/test/zknft.js +98 -0
- package/solidity/yarn.lock +4152 -0
- package/test/test.js +304 -0
- /package/{circomlibjs.js → sdk/circomlibjs.js} +0 -0
- /package/{collection.js → sdk/collection.js} +0 -0
- /package/{contracts → sdk/contracts}/OPRollup.sol +0 -0
- /package/{contracts → sdk/contracts}/ZKIPFS.sol +0 -0
- /package/{contracts → sdk/contracts}/ZKJson.sol +0 -0
- /package/{contracts → sdk/contracts}/ZKQuery.sol +0 -0
- /package/{contracts → sdk/contracts}/ZKRollup.sol +0 -0
- /package/{contracts → sdk/contracts}/apps/SimpleJSON.sol +0 -0
- /package/{contracts → sdk/contracts}/apps/SimpleOPRU.sol +0 -0
- /package/{contracts → sdk/contracts}/apps/SimpleRU.sol +0 -0
- /package/{contracts → sdk/contracts}/apps/Token.sol +0 -0
- /package/{contracts → sdk/contracts}/apps/ZKArweave.sol +0 -0
- /package/{contracts → sdk/contracts}/apps/ZKBridge.sol +0 -0
- /package/{contracts → sdk/contracts}/apps/ZKNFT.sol +0 -0
- /package/{contracts → sdk/contracts}/verifiers/verifier_db.sol +0 -0
- /package/{contracts → sdk/contracts}/verifiers/verifier_ipfs.sol +0 -0
- /package/{contracts → sdk/contracts}/verifiers/verifier_json.sol +0 -0
- /package/{contracts → sdk/contracts}/verifiers/verifier_rollup.sol +0 -0
- /package/{db.js → sdk/db.js} +0 -0
- /package/{doc.js → sdk/doc.js} +0 -0
- /package/{encoder-v1_5.js → sdk/encoder-v1_5.js} +0 -0
- /package/{encoder.js → sdk/encoder.js} +0 -0
- /package/{index.js → sdk/index.js} +0 -0
- /package/{json.js → sdk/json.js} +0 -0
- /package/{nft.js → sdk/nft.js} +0 -0
- /package/{parse.js → sdk/parse.js} +0 -0
- /package/{uint.js → sdk/uint.js} +0 -0
@@ -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 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 = 10548989649020101460514539324030972308502034681633392883991961616863130637984;
|
41
|
+
uint256 constant deltax2 = 1049946570122174039975801346728261460931086847141295177952236227197145479746;
|
42
|
+
uint256 constant deltay1 = 10558381744179704646192748283236903784158982943346653783344902335722321321384;
|
43
|
+
uint256 constant deltay2 = 16748276816739890599042583608461502899144793788720809401511640542800930620065;
|
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
|
+
uint256 constant IC13x = 2025484288051762304170760878169695013364214111997466862551524207031601382631;
|
86
|
+
uint256 constant IC13y = 7038960739366138059493181524660940249493960394838603142532679804397882049709;
|
87
|
+
|
88
|
+
uint256 constant IC14x = 11387856957329089595489992260814785056704488293876837097183204151395206987719;
|
89
|
+
uint256 constant IC14y = 17844362785282169318131685916181008035618810588862118232161118858351706006467;
|
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,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 = 12826039923985305509172445548825630308307897385636638314103089050117034765807;
|
41
|
+
uint256 constant deltax2 = 5777316040111550683119122338100696671533578054713112313962719197468777904391;
|
42
|
+
uint256 constant deltay1 = 13100118653411399080908320939554734522926116642572965561618759712020115377487;
|
43
|
+
uint256 constant deltay2 = 4863992084126820334137644474127866316351574790993028000936897867731380377202;
|
44
|
+
|
45
|
+
|
46
|
+
uint256 constant IC0x = 6270950016247133466336754274326443126017687703801742756948638236534086892047;
|
47
|
+
uint256 constant IC0y = 20310453393525738917452540227487036745129047678621136376195858836563533911527;
|
48
|
+
|
49
|
+
uint256 constant IC1x = 1141343197515056438569346347535803858564689453833647046018791462772549149227;
|
50
|
+
uint256 constant IC1y = 16491780663163267442130703331018113562992698794258578658230547724337214632511;
|
51
|
+
|
52
|
+
uint256 constant IC2x = 5569694830107596991306292701850289725347601942273592203980263593485643232633;
|
53
|
+
uint256 constant IC2y = 5496875873369182800954050214612959091907601104963709673444966250025502326758;
|
54
|
+
|
55
|
+
uint256 constant IC3x = 856226396972901355666350894014284120170327945287396680478814592107007149805;
|
56
|
+
uint256 constant IC3y = 4080222902213037494283476857599202091267684100021446005131603140238216815391;
|
57
|
+
|
58
|
+
uint256 constant IC4x = 10764306455319897189590233363611208010675243280639689255137625645138943859385;
|
59
|
+
uint256 constant IC4y = 19346540917500920047750697423047140511552971607568238316315807020898102730868;
|
60
|
+
|
61
|
+
uint256 constant IC5x = 16857068565745876906748660361991141069946983257614833579471638734061485457112;
|
62
|
+
uint256 constant IC5y = 14632180805427053926564788976583761986580123762441719835724709161702471836981;
|
63
|
+
|
64
|
+
uint256 constant IC6x = 12315747360356477219902572740218642460149278211574165192334271766621665438376;
|
65
|
+
uint256 constant IC6y = 1313234108449442273460693358644853644145068014633280121061495643296281134420;
|
66
|
+
|
67
|
+
uint256 constant IC7x = 15252212582859770288887248094717972825568314500168925087757606041256952964029;
|
68
|
+
uint256 constant IC7y = 19751607759272618647644406330677066920139018206963959740625861713276025168423;
|
69
|
+
|
70
|
+
uint256 constant IC8x = 8432690145128824085267914412714661508760195558814883868966832777728733350601;
|
71
|
+
uint256 constant IC8y = 20683188851611894785172396447809130386092126094512442322570355864144302756164;
|
72
|
+
|
73
|
+
uint256 constant IC9x = 19369987132771616043793275659835942692385855791064890369063891639761686156657;
|
74
|
+
uint256 constant IC9y = 8426683055759400985089789088504223062497842350159798813155638560974712761643;
|
75
|
+
|
76
|
+
uint256 constant IC10x = 20860096825664394339889589645802586392309097833727587594050802394079690409091;
|
77
|
+
uint256 constant IC10y = 17908147166318266417496260692526339764629505794576827802816790292654348457101;
|
78
|
+
|
79
|
+
uint256 constant IC11x = 7111525545052173450141644018481693095722931164254044734852844952175519360375;
|
80
|
+
uint256 constant IC11y = 14968059451881120855243147686628983750275388350316603656458857787322628363714;
|
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
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
{
|
2
|
+
"name": "hardhat-project",
|
3
|
+
"devDependencies": {
|
4
|
+
"@nomicfoundation/hardhat-chai-matchers": "^1.0.6",
|
5
|
+
"@nomicfoundation/hardhat-network-helpers": "^1.0.10",
|
6
|
+
"@nomicfoundation/hardhat-toolbox": "^2.0.2",
|
7
|
+
"@nomicfoundation/hardhat-verify": "^2.0.3",
|
8
|
+
"@nomiclabs/hardhat-ethers": "^2.2.3",
|
9
|
+
"@nomiclabs/hardhat-etherscan": "^3.1.8",
|
10
|
+
"@typechain/ethers-v5": "^10.2.1",
|
11
|
+
"@typechain/hardhat": "^6.1.6",
|
12
|
+
"@types/chai": "^4.3.11",
|
13
|
+
"@types/mocha": "^10.0.6",
|
14
|
+
"chai": "4",
|
15
|
+
"hardhat": "^2.19.4",
|
16
|
+
"hardhat-gas-reporter": "^1.0.9",
|
17
|
+
"solidity-coverage": "^0.8.5",
|
18
|
+
"ts-node": "^10.9.2",
|
19
|
+
"typechain": "^8.3.2",
|
20
|
+
"typescript": "^5.3.3"
|
21
|
+
},
|
22
|
+
"dependencies": {
|
23
|
+
"@openzeppelin/contracts": "^5.0.1",
|
24
|
+
"snarkjs": "^0.7.2"
|
25
|
+
},
|
26
|
+
"license": "MIT"
|
27
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
// We require the Hardhat Runtime Environment explicitly here. This is optional
|
2
|
+
// but useful for running the script in a standalone fashion through `node <script>`.
|
3
|
+
//
|
4
|
+
// You can also run a script with `npx hardhat run <script>`. If you do that, Hardhat
|
5
|
+
// will compile your contracts, add the Hardhat Runtime Environment's members to the
|
6
|
+
// global scope, and execute the script.
|
7
|
+
const hre = require("hardhat")
|
8
|
+
|
9
|
+
async function main() {
|
10
|
+
const VerifierJSON = await hre.ethers.getContractFactory(
|
11
|
+
"Groth16VerifierJSON"
|
12
|
+
)
|
13
|
+
const verifierJSON = await VerifierJSON.deploy()
|
14
|
+
await verifierJSON.deployed()
|
15
|
+
console.log("verifier", verifierJSON.address)
|
16
|
+
|
17
|
+
const ZKAR = await hre.ethers.getContractFactory("ZKArweave")
|
18
|
+
const zkar = await ZKAR.deploy(
|
19
|
+
verifierJSON.address,
|
20
|
+
"0x078694d69426112c7df330732e28F5117B02727A"
|
21
|
+
)
|
22
|
+
|
23
|
+
await zkar.deployed()
|
24
|
+
|
25
|
+
console.log("zkar", zkar.address)
|
26
|
+
}
|
27
|
+
|
28
|
+
// We recommend this pattern to be able to use async/await everywhere
|
29
|
+
// and properly handle errors.
|
30
|
+
main().catch(error => {
|
31
|
+
console.error(error)
|
32
|
+
process.exitCode = 1
|
33
|
+
})
|
@@ -0,0 +1,66 @@
|
|
1
|
+
const { loadFixture } = require("@nomicfoundation/hardhat-network-helpers")
|
2
|
+
const { toIndex, path, DB } = require("../../sdk")
|
3
|
+
const { resolve } = require("path")
|
4
|
+
const { expect } = require("chai")
|
5
|
+
|
6
|
+
async function deploy() {
|
7
|
+
const VerifierDB = await ethers.getContractFactory("Groth16VerifierDB")
|
8
|
+
const verifierDB = await VerifierDB.deploy()
|
9
|
+
|
10
|
+
const NORU = await ethers.getContractFactory("NORU")
|
11
|
+
const noru = await NORU.deploy(verifierDB.address)
|
12
|
+
return { noru }
|
13
|
+
}
|
14
|
+
|
15
|
+
describe("MyRollup", function () {
|
16
|
+
let noru
|
17
|
+
this.timeout(0)
|
18
|
+
|
19
|
+
beforeEach(async () => {
|
20
|
+
const dep = await loadFixture(deploy)
|
21
|
+
noru = dep.noru
|
22
|
+
})
|
23
|
+
|
24
|
+
it("should verify rollup transactions", async function () {
|
25
|
+
const db = new DB({
|
26
|
+
level: 168,
|
27
|
+
size_path: 4,
|
28
|
+
size_val: 8,
|
29
|
+
size_json: 256,
|
30
|
+
size_txs: 10,
|
31
|
+
level_col: 8,
|
32
|
+
wasm: resolve(
|
33
|
+
__dirname,
|
34
|
+
"../../circom/build/circuits/db/index_js/index.wasm",
|
35
|
+
),
|
36
|
+
zkey: resolve(
|
37
|
+
__dirname,
|
38
|
+
"../../circom/build/circuits/db/index_0001.zkey",
|
39
|
+
),
|
40
|
+
})
|
41
|
+
await db.init()
|
42
|
+
const col_id = await db.addCollection()
|
43
|
+
const people = [{ name: "Bob", age: 5 }]
|
44
|
+
let txs = people.map(v => {
|
45
|
+
return [col_id, v.name, v]
|
46
|
+
})
|
47
|
+
for (const v of txs) await db.insert(...v)
|
48
|
+
const zkp = await db.genProof({
|
49
|
+
json: people[0],
|
50
|
+
col_id,
|
51
|
+
path: "name",
|
52
|
+
id: "Bob",
|
53
|
+
})
|
54
|
+
|
55
|
+
expect(await noru.qString(zkp)).to.eql("Bob")
|
56
|
+
|
57
|
+
const zkp2 = await db.genProof({
|
58
|
+
json: people[0],
|
59
|
+
col_id,
|
60
|
+
path: "age",
|
61
|
+
id: "Bob",
|
62
|
+
query: ["$gt", 3],
|
63
|
+
})
|
64
|
+
expect(await noru.qCond(zkp2.slice(13, 14), zkp2)).to.eql(true)
|
65
|
+
})
|
66
|
+
})
|