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,36 @@
|
|
1
|
+
const { DB } = require("../../sdk")
|
2
|
+
|
3
|
+
const gen = async ({
|
4
|
+
size_val = 256,
|
5
|
+
size_path = 256,
|
6
|
+
size_json = 256,
|
7
|
+
level = 168,
|
8
|
+
level_col = 8,
|
9
|
+
size_txs = 10,
|
10
|
+
}) => {
|
11
|
+
const db = new DB({
|
12
|
+
size_val,
|
13
|
+
size_path,
|
14
|
+
size_json,
|
15
|
+
level,
|
16
|
+
size_txs,
|
17
|
+
level_col,
|
18
|
+
})
|
19
|
+
await db.init()
|
20
|
+
const col1 = await db.addCollection()
|
21
|
+
const col2 = await db.addCollection()
|
22
|
+
let queries = [
|
23
|
+
[col2, "docA", { d: 4 }],
|
24
|
+
[col2, "docC", { d: 4 }],
|
25
|
+
[col2, "docD", { d: 4 }],
|
26
|
+
[col1, "docD", { b: 4 }],
|
27
|
+
[col1, "docA", { b: 5 }],
|
28
|
+
[col2, "docA2", { d: 4 }],
|
29
|
+
[col2, "docC2", { d: 4 }],
|
30
|
+
[col2, "docD2", { d: 4 }],
|
31
|
+
[col1, "docA2", { b: 4 }],
|
32
|
+
]
|
33
|
+
return { db, inputs: await db.getRollupInputs({ queries }) }
|
34
|
+
}
|
35
|
+
|
36
|
+
module.exports = gen
|
@@ -0,0 +1,11 @@
|
|
1
|
+
const gen = require("./gen")
|
2
|
+
|
3
|
+
const { writeFileSync } = require("fs")
|
4
|
+
const { resolve } = require("path")
|
5
|
+
|
6
|
+
const main = async () => {
|
7
|
+
const { inputs } = await gen({})
|
8
|
+
writeFileSync(resolve(__dirname, "input.json"), JSON.stringify(inputs))
|
9
|
+
}
|
10
|
+
|
11
|
+
main()
|
@@ -0,0 +1,43 @@
|
|
1
|
+
pragma circom 2.1.5;
|
2
|
+
include "../query/query.circom";
|
3
|
+
|
4
|
+
template Rollup (tx_size, level_col, level, size_json) {
|
5
|
+
signal input fnc[tx_size][2];
|
6
|
+
signal input siblings[tx_size][level];
|
7
|
+
signal input json[tx_size][size_json];
|
8
|
+
signal input newKey[tx_size];
|
9
|
+
signal input oldRoot[tx_size];
|
10
|
+
signal input newRoot[tx_size];
|
11
|
+
signal input isOld0[tx_size];
|
12
|
+
signal input oldValue[tx_size];
|
13
|
+
signal input oldKey[tx_size];
|
14
|
+
signal input oldRoot_db[tx_size];
|
15
|
+
signal input oldKey_db[tx_size];
|
16
|
+
signal input oldValue_db[tx_size];
|
17
|
+
signal input isOld0_db[tx_size];
|
18
|
+
signal input siblings_db[tx_size][level_col];
|
19
|
+
signal input newKey_db[tx_size];
|
20
|
+
|
21
|
+
signal output new_root;
|
22
|
+
component query[tx_size];
|
23
|
+
for(var i = 0;i < tx_size;i++){
|
24
|
+
query[i] = Query(level_col, level, size_json);
|
25
|
+
query[i].fnc <== fnc[i];
|
26
|
+
query[i].siblings <== siblings[i];
|
27
|
+
query[i].json <== json[i];
|
28
|
+
query[i].newKey <== newKey[i];
|
29
|
+
query[i].oldRoot <== oldRoot[i];
|
30
|
+
query[i].newRoot <== newRoot[i];
|
31
|
+
query[i].isOld0 <== isOld0[i];
|
32
|
+
query[i].oldValue <== oldValue[i];
|
33
|
+
query[i].oldKey <== oldKey[i];
|
34
|
+
query[i].oldRoot_db <== oldRoot_db[i];
|
35
|
+
query[i].oldKey_db <== oldKey_db[i];
|
36
|
+
query[i].oldValue_db <== oldValue_db[i];
|
37
|
+
query[i].isOld0_db <== isOld0_db[i];
|
38
|
+
query[i].siblings_db <== siblings_db[i];
|
39
|
+
query[i].newKey_db <== newKey_db[i];
|
40
|
+
if(i > 0) query[i - 1].new_root === query[i].oldRoot_db;
|
41
|
+
}
|
42
|
+
new_root <== query[tx_size - 1].new_root;
|
43
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
const chai = require("chai")
|
2
|
+
const { range } = require("ramda")
|
3
|
+
const path = require("path")
|
4
|
+
const Scalar = require("ffjavascript").Scalar
|
5
|
+
const wasm_tester = require("circom_tester").wasm
|
6
|
+
const assert = chai.assert
|
7
|
+
const gen = require("./gen")
|
8
|
+
const {
|
9
|
+
pad,
|
10
|
+
encode,
|
11
|
+
decode,
|
12
|
+
encodePath,
|
13
|
+
decodePath,
|
14
|
+
encodeVal,
|
15
|
+
decodeVal,
|
16
|
+
str2id,
|
17
|
+
val2str,
|
18
|
+
} = require("../../sdk")
|
19
|
+
|
20
|
+
describe("SMT Verifier test", function () {
|
21
|
+
let circuit
|
22
|
+
this.timeout(1000000000)
|
23
|
+
|
24
|
+
before(async () => {
|
25
|
+
circuit = await wasm_tester(path.join(__dirname, "index.circom"))
|
26
|
+
await circuit.loadSymbols()
|
27
|
+
})
|
28
|
+
|
29
|
+
it("should insert docs", async () => {
|
30
|
+
const { db, inputs } = await gen({})
|
31
|
+
const w = await circuit.calculateWitness(inputs, true)
|
32
|
+
await circuit.checkConstraints(w)
|
33
|
+
await circuit.assertOut(w, { new_root: db.tree.F.toObject(db.tree.root) })
|
34
|
+
})
|
35
|
+
})
|
@@ -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 Groth16Verifier {
|
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 = 7332885377758315278340183047560982420908393795468599595091895974752420296340;
|
31
|
+
uint256 constant alphay = 332255058049377868589021735422241784808251989994698755461004804814851540428;
|
32
|
+
uint256 constant betax1 = 14918511796604743115529252945397806548811923425844505517068409231790256866971;
|
33
|
+
uint256 constant betax2 = 211413574403138532859071680094500506786935898681671422463746292741380691281;
|
34
|
+
uint256 constant betay1 = 19126853899579995366417647673795374157635727056721981778430611935842415927913;
|
35
|
+
uint256 constant betay2 = 19131403844100444556608656382423150552404085133882015610549223179149801306375;
|
36
|
+
uint256 constant gammax1 = 11559732032986387107991004021392285783925812861821192530917403151452391805634;
|
37
|
+
uint256 constant gammax2 = 10857046999023057135944570762232829481370756359578518086990519993285655852781;
|
38
|
+
uint256 constant gammay1 = 4082367875863433681332203403145435568316851327593401208105741076214120093531;
|
39
|
+
uint256 constant gammay2 = 8495653923123431417604973247489272438418190587263600148770280649306958101930;
|
40
|
+
uint256 constant deltax1 = 6382598770963503221868241989178034505983713830030338706732180562135705228302;
|
41
|
+
uint256 constant deltax2 = 21197856141823471623406461430327045328337063888153217384477040020290521661075;
|
42
|
+
uint256 constant deltay1 = 3917474521378140980893240833218234849640957594604572843736203586085997385225;
|
43
|
+
uint256 constant deltay2 = 14835789719593847307069905718757171873703176299365135556708948375893296781197;
|
44
|
+
|
45
|
+
|
46
|
+
uint256 constant IC0x = 20662541603631784033783411850623466276814384175295295876709145346505559490785;
|
47
|
+
uint256 constant IC0y = 8006046329700423418312155249696418399477725117760743047451409025951309235053;
|
48
|
+
|
49
|
+
uint256 constant IC1x = 19285561784052895999071352462087059624897129991505522910816835510277875569935;
|
50
|
+
uint256 constant IC1y = 5088412779626932902831572326787948377088065901739480602177649205695253931298;
|
51
|
+
|
52
|
+
uint256 constant IC2x = 16906112931417150993762587715805291967453600986078866926780547005566937018229;
|
53
|
+
uint256 constant IC2y = 16406004371419885542963808166406455372466253891120090979075187559729759077887;
|
54
|
+
|
55
|
+
uint256 constant IC3x = 4341275995721556388393245268096468823912850229820335159079360530403892879981;
|
56
|
+
uint256 constant IC3y = 2462604992092891980616604542639214739312453086561777882013221218049200078781;
|
57
|
+
|
58
|
+
uint256 constant IC4x = 7277064584951076939263949249291030051988867251154537475629938673240559596853;
|
59
|
+
uint256 constant IC4y = 14713923541850473885477334331717851629619309015192464754711549104288430191729;
|
60
|
+
|
61
|
+
uint256 constant IC5x = 1380047561246268234648566758926047861819696113275790626094191145759794852616;
|
62
|
+
uint256 constant IC5y = 11975715682841217814475735189098358844548340304054540097172304523664666456818;
|
63
|
+
|
64
|
+
uint256 constant IC6x = 19889221053189663675835304903782776506012797094259239673796347297879541341425;
|
65
|
+
uint256 constant IC6y = 21623090991343843017885541457952366267759902394147084578214441440612592545561;
|
66
|
+
|
67
|
+
uint256 constant IC7x = 21101368779201512942514878828882076303149732417558876049841515757698295467276;
|
68
|
+
uint256 constant IC7y = 4028913196030058373760596313712820451799967403478544075073671694593735901590;
|
69
|
+
|
70
|
+
uint256 constant IC8x = 2455721476973704253152625771715175790589879242009886193103380068033322414438;
|
71
|
+
uint256 constant IC8y = 18625273757755157943711133805503013403206708905781199275078628565629116421776;
|
72
|
+
|
73
|
+
uint256 constant IC9x = 7029656770711039689598013638570045303993056662040279019499615994988338079507;
|
74
|
+
uint256 constant IC9y = 9726526515011675836347161915229713103383294389291653853844138945657504329227;
|
75
|
+
|
76
|
+
uint256 constant IC10x = 18497952841684321869489981207061325388935878843879925971858789217870939562666;
|
77
|
+
uint256 constant IC10y = 4639147689759224858781849014552611717322583925303475076193438536411426115416;
|
78
|
+
|
79
|
+
uint256 constant IC11x = 2644370262898202054035455297715425980763090245662003176644117618964138767359;
|
80
|
+
uint256 constant IC11y = 82929160403731179325725375411091817788513240869939263133699612899376085683;
|
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,39 @@
|
|
1
|
+
const { spawn } = require("node:child_process")
|
2
|
+
const { existsSync, mkdirSync } = require("fs")
|
3
|
+
const { resolve } = require("path")
|
4
|
+
const { v4: uuidv4 } = require("uuid")
|
5
|
+
|
6
|
+
let {
|
7
|
+
power,
|
8
|
+
entropy = uuidv4(),
|
9
|
+
name,
|
10
|
+
} = require("yargs")(process.argv.slice(2)).options({
|
11
|
+
entropy: { type: "string" },
|
12
|
+
power: { type: "number", demandOption: true },
|
13
|
+
name: { type: "string" },
|
14
|
+
}).argv
|
15
|
+
|
16
|
+
if (typeof name === "undefined") name = "first contribution"
|
17
|
+
|
18
|
+
const main = async () => {
|
19
|
+
const build = resolve(__dirname, "../build")
|
20
|
+
const ptau = resolve(__dirname, "../build/ptau")
|
21
|
+
const ptau_n = resolve(__dirname, "../build/ptau", power.toString())
|
22
|
+
for (const v of [build, ptau, ptau_n]) if (!existsSync(v)) mkdirSync(v)
|
23
|
+
|
24
|
+
const ceremony = resolve(__dirname, "./ceremony.sh")
|
25
|
+
const ls = spawn("sh", [ceremony, power, name, entropy])
|
26
|
+
|
27
|
+
ls.stdout.on("data", data => console.log(`${data}`))
|
28
|
+
|
29
|
+
ls.stderr.on("data", data => {
|
30
|
+
console.error(`stderr: ${data}`)
|
31
|
+
process.exit()
|
32
|
+
})
|
33
|
+
|
34
|
+
ls.on("close", code => {
|
35
|
+
console.log(`child process exited with code ${code}`)
|
36
|
+
process.exit()
|
37
|
+
})
|
38
|
+
}
|
39
|
+
main()
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
DIR="$( cd "$( dirname "$0" )" && pwd )/../build/ptau/$1"
|
3
|
+
|
4
|
+
snarkjs powersoftau new bn128 $1 $DIR/pot$1_0000.ptau -v \
|
5
|
+
&& echo "$3" | snarkjs powersoftau contribute $DIR/pot$1_0000.ptau $DIR/pot$1_0001.ptau --name="$2" -v \
|
6
|
+
&& snarkjs powersoftau prepare phase2 $DIR/pot$1_0001.ptau $DIR/pot$1_final.ptau -v
|
@@ -0,0 +1,113 @@
|
|
1
|
+
const { spawn } = require("node:child_process")
|
2
|
+
const { writeFileSync, existsSync, mkdirSync } = require("fs")
|
3
|
+
const { resolve } = require("path")
|
4
|
+
const { v4: uuidv4 } = require("uuid")
|
5
|
+
let {
|
6
|
+
power,
|
7
|
+
entropy = uuidv4(),
|
8
|
+
circuit,
|
9
|
+
size_val = 8,
|
10
|
+
size_path = 4,
|
11
|
+
size_json = 256,
|
12
|
+
level = 168,
|
13
|
+
level_col = 8,
|
14
|
+
size_txs = 10,
|
15
|
+
nBlocks = 10,
|
16
|
+
name,
|
17
|
+
} = require("yargs")(process.argv.slice(2)).options({
|
18
|
+
size: { type: "number" },
|
19
|
+
size_json: { type: "number" },
|
20
|
+
size_path: { type: "number" },
|
21
|
+
level: { type: "number" },
|
22
|
+
level_col: { type: "number" },
|
23
|
+
size_txs: { type: "number" },
|
24
|
+
name: { type: "string" },
|
25
|
+
entropy: { type: "string" },
|
26
|
+
power: { type: "number", demandOption: true },
|
27
|
+
circuit: {
|
28
|
+
type: "string",
|
29
|
+
demandOption: true,
|
30
|
+
choices: ["json", "collection", "db", "query", "rollup", "ipfs"],
|
31
|
+
},
|
32
|
+
}).argv
|
33
|
+
|
34
|
+
if (typeof name === "undefined") name = "zkJSON"
|
35
|
+
const main = async () => {
|
36
|
+
const build = resolve(__dirname, "../build")
|
37
|
+
const ptau = resolve(__dirname, "../build/ptau")
|
38
|
+
const ptau_n = resolve(__dirname, "../build/ptau", power.toString())
|
39
|
+
const circuits = resolve(__dirname, "../build/circuits")
|
40
|
+
const circuits_x = resolve(__dirname, "../build/circuits", circuit)
|
41
|
+
const index = resolve(__dirname, "../build/circuits", circuit, "index.circom")
|
42
|
+
const input = resolve(__dirname, "../build/circuits", circuit, "input.json")
|
43
|
+
|
44
|
+
for (const v of [build, ptau, ptau_n])
|
45
|
+
if (!existsSync(v)) {
|
46
|
+
console.log("power of tau missing")
|
47
|
+
process.exit()
|
48
|
+
}
|
49
|
+
for (const v of [circuits, circuits_x]) if (!existsSync(v)) mkdirSync(v)
|
50
|
+
|
51
|
+
let script = ""
|
52
|
+
if (circuit === "ipfs") {
|
53
|
+
script = `pragma circom 2.1.5;
|
54
|
+
include "../../../ipfs/ipfs.circom";
|
55
|
+
|
56
|
+
component main {public [path, val]} = IPFS(${size_json}, ${size_path}, ${size_val}, ${nBlocks});`
|
57
|
+
} else if (circuit === "json") {
|
58
|
+
script = `pragma circom 2.1.5;
|
59
|
+
include "../../../json/json.circom";
|
60
|
+
|
61
|
+
component main {public [path, val]} = JSON(${size_json}, ${size_path}, ${size_val});`
|
62
|
+
} else if (circuit === "collection") {
|
63
|
+
script = `pragma circom 2.1.5;
|
64
|
+
include "../../../collection/collection.circom";
|
65
|
+
|
66
|
+
component main {public [key, path, val]} = Collection(${level}, ${size_json}, ${size_path}, ${size_val});`
|
67
|
+
console.log(script)
|
68
|
+
} else if (circuit === "db") {
|
69
|
+
script = `pragma circom 2.1.5;
|
70
|
+
include "../../../db/db.circom";
|
71
|
+
|
72
|
+
component main {public [col_key, key, path, val, col_root]} = DB(${level_col}, ${level}, ${size_json}, ${size_path}, ${size_val});`
|
73
|
+
} else if (circuit === "query") {
|
74
|
+
script = `pragma circom 2.1.5;
|
75
|
+
include "../../../query/query.circom";
|
76
|
+
|
77
|
+
component main {public [oldRoot]} = Query(${level_col}, ${level}, ${size_json});`
|
78
|
+
} else if (circuit === "rollup") {
|
79
|
+
script = `pragma circom 2.1.5;
|
80
|
+
include "../../../rollup/rollup.circom";
|
81
|
+
|
82
|
+
component main {public [oldRoot]} = Rollup(${size_txs}, ${level_col}, ${level}, ${size_json});`
|
83
|
+
}
|
84
|
+
writeFileSync(index, script)
|
85
|
+
|
86
|
+
const gen = require(`../${circuit}/gen`)
|
87
|
+
const { inputs } = await gen({
|
88
|
+
size_json,
|
89
|
+
size_val,
|
90
|
+
size_path,
|
91
|
+
level,
|
92
|
+
size_txs,
|
93
|
+
level_col,
|
94
|
+
})
|
95
|
+
|
96
|
+
writeFileSync(input, JSON.stringify(inputs))
|
97
|
+
|
98
|
+
const compile = resolve(__dirname, "./compile.sh")
|
99
|
+
const ls = spawn("sh", [compile, circuit, power, entropy, name])
|
100
|
+
|
101
|
+
ls.stdout.on("data", data => console.log(`${data}`))
|
102
|
+
|
103
|
+
ls.stderr.on("data", data => {
|
104
|
+
console.error(`stderr: ${data}`)
|
105
|
+
process.exit()
|
106
|
+
})
|
107
|
+
|
108
|
+
ls.on("close", code => {
|
109
|
+
console.log(`child process exited with code ${code}`)
|
110
|
+
process.exit()
|
111
|
+
})
|
112
|
+
}
|
113
|
+
main()
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
DIR="$( cd "$( dirname "$0" )" && pwd )/../build/circuits/$1"
|
3
|
+
|
4
|
+
cd $DIR \
|
5
|
+
&& circom index.circom --r1cs --wasm --sym --c \
|
6
|
+
&& cd index_js \
|
7
|
+
&& node generate_witness.js index.wasm ../input.json witness.wtns \
|
8
|
+
&& cd .. \
|
9
|
+
&& snarkjs groth16 setup index.r1cs ../../ptau/$2/pot$2_final.ptau index_0000.zkey \
|
10
|
+
&& echo $3 | snarkjs zkey contribute index_0000.zkey index_0001.zkey --name="$4" -v \
|
11
|
+
&& snarkjs zkey export verificationkey index_0001.zkey verification_key.json \
|
12
|
+
&& snarkjs groth16 prove index_0001.zkey index_js/witness.wtns proof.json public.json \
|
13
|
+
&& snarkjs groth16 verify verification_key.json public.json proof.json \
|
14
|
+
&& snarkjs zkey export solidityverifier index_0001.zkey verifier.sol;
|
15
|
+
|
16
|
+
|