From 3f1ccadfd2fbff1b879a19ab91a40d3d25accd1e Mon Sep 17 00:00:00 2001 From: cedoor Date: Tue, 28 Nov 2023 18:25:16 +0000 Subject: [PATCH] chore(circuits): new setup with circomkit re #73 --- .../circomkit-npm-0.0.18-e33b63f27f.patch | 76 +++++++++++++++++++ package.json | 6 +- packages/circuits/.gitignore | 2 + packages/circuits/LICENSE | 22 +++++- packages/circuits/README.md | 51 ++++++++++++- .../binary-merkle-root.circom | 0 packages/circuits/circom/circuits.json | 11 +++ .../poseidon-proof.circom | 0 packages/circuits/circomkit.json | 17 +++++ .../components/binary-merkle-root.circom | 5 -- .../circuits/components/poseidon-proof.circom | 5 -- packages/circuits/noir/.gitkeep | 0 packages/circuits/package.json | 26 ++++++- packages/circuits/templates/LICENSE | 21 ----- packages/circuits/templates/README.md | 50 ------------ packages/circuits/templates/package.json | 24 ------ yarn.lock | 68 ++++++++++++++--- 17 files changed, 261 insertions(+), 123 deletions(-) create mode 100644 .yarn/patches/circomkit-npm-0.0.18-e33b63f27f.patch mode change 120000 => 100644 packages/circuits/LICENSE mode change 120000 => 100644 packages/circuits/README.md rename packages/circuits/{templates => circom}/binary-merkle-root.circom (100%) create mode 100644 packages/circuits/circom/circuits.json rename packages/circuits/{templates => circom}/poseidon-proof.circom (100%) create mode 100644 packages/circuits/circomkit.json delete mode 100644 packages/circuits/components/binary-merkle-root.circom delete mode 100644 packages/circuits/components/poseidon-proof.circom create mode 100644 packages/circuits/noir/.gitkeep delete mode 100644 packages/circuits/templates/LICENSE delete mode 100644 packages/circuits/templates/README.md delete mode 100644 packages/circuits/templates/package.json diff --git a/.yarn/patches/circomkit-npm-0.0.18-e33b63f27f.patch b/.yarn/patches/circomkit-npm-0.0.18-e33b63f27f.patch new file mode 100644 index 000000000..22086de6f --- /dev/null +++ b/.yarn/patches/circomkit-npm-0.0.18-e33b63f27f.patch @@ -0,0 +1,76 @@ +diff --git a/dist/utils/instantiate.js b/dist/utils/instantiate.js +index 33cdff152e8b23d6853eb475097bda8c02712e01..418f57072c9c0ebf3778c8a9a50d379728128e5f 100644 +--- a/dist/utils/instantiate.js ++++ b/dist/utils/instantiate.js +@@ -1,15 +1,17 @@ +-"use strict"; +-Object.defineProperty(exports, "__esModule", { value: true }); +-exports.instantiate = void 0; +-const fs_1 = require("fs"); ++"use strict" ++Object.defineProperty(exports, "__esModule", { value: true }) ++exports.instantiate = void 0 ++const fs_1 = require("fs") + /** Circuit builder, kinda like `ejs.render`. **Be very careful when editing this file.** */ + const makeCircuit = (config) => `// auto-generated by circomkit + pragma circom ${config.version}; + + include "../${config.file}.circom"; + +-component main${config.pubs.length === 0 ? '' : ' {public[' + config.pubs.join(', ') + ']}'} = ${config.template}(${config.params.join(', ')}); +-`; ++component main${config.pubs.length === 0 ? "" : " {public[" + config.pubs.join(", ") + "]}"} = ${ ++ config.template ++}(${config.params.join(", ")}); ++` + /** + * Programmatically generate the `main` component of a circuit + * @param name name of the circuit to be generated +@@ -18,31 +20,32 @@ component main${config.pubs.length === 0 ? '' : ' {public[' + config.pubs.join(' + */ + function instantiate(name, circuitConfig) { + // directory to output the file +- const directory = circuitConfig.dir || 'test'; ++ const directory = circuitConfig.dir || "test" + // add "../" to the filename in include, one for each "/" in directory name + // if none, the prefix becomes empty string +- const filePrefixMatches = directory.match(/\//g); +- let file = circuitConfig.file; ++ const filePrefixMatches = directory.match(/\//g) ++ let file = circuitConfig.file + if (filePrefixMatches !== null) { +- file = '../'.repeat(filePrefixMatches.length) + file; ++ file = "../".repeat(filePrefixMatches.length) + file + } + const circuitCode = makeCircuit({ + file: file, + template: circuitConfig.template, +- version: circuitConfig.version || '2.0.0', ++ version: circuitConfig.version || "2.0.0", + dir: directory, + pubs: circuitConfig.pubs || [], +- params: circuitConfig.params || [], +- }); +- const targetDir = `./circuits/${directory}`; ++ params: circuitConfig.params || [] ++ }) ++ const targetDir = `./circom/${directory}` + if (!(0, fs_1.existsSync)(targetDir)) { +- (0, fs_1.mkdirSync)(targetDir, { +- recursive: true, +- }); ++ ;(0, fs_1.mkdirSync)(targetDir, { ++ recursive: true ++ }) + } +- const targetPath = `${targetDir}/${name}.circom`; +- (0, fs_1.writeFileSync)(targetPath, circuitCode); +- return targetPath; ++ const targetPath = `${targetDir}/${name}.circom` ++ ;(0, fs_1.writeFileSync)(targetPath, circuitCode) ++ return targetPath + } +-exports.instantiate = instantiate; ++exports.instantiate = instantiate + //# sourceMappingURL=instantiate.js.map ++ diff --git a/package.json b/package.json index e7772aad6..8d549fd88 100644 --- a/package.json +++ b/package.json @@ -32,8 +32,7 @@ "circom" ], "workspaces": [ - "packages/*", - "packages/circuits/templates" + "packages/*" ], "packageManager": "yarn@3.2.1", "devDependencies": { @@ -76,5 +75,8 @@ "commitizen": { "path": "./node_modules/cz-conventional-changelog" } + }, + "resolutions": { + "circomkit@0.0.18": "patch:circomkit@npm:0.0.18#.yarn/patches/circomkit-npm-0.0.18-e33b63f27f.patch" } } diff --git a/packages/circuits/.gitignore b/packages/circuits/.gitignore index 64183cbe9..928abb6f2 100644 --- a/packages/circuits/.gitignore +++ b/packages/circuits/.gitignore @@ -1,2 +1,4 @@ +ptau +main *.r1cs *.wasm diff --git a/packages/circuits/LICENSE b/packages/circuits/LICENSE deleted file mode 120000 index 8e505bcde..000000000 --- a/packages/circuits/LICENSE +++ /dev/null @@ -1 +0,0 @@ -templates/LICENSE \ No newline at end of file diff --git a/packages/circuits/LICENSE b/packages/circuits/LICENSE new file mode 100644 index 000000000..4377091ec --- /dev/null +++ b/packages/circuits/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Ethereum Foundation + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/circuits/README.md b/packages/circuits/README.md deleted file mode 120000 index 6cb99675b..000000000 --- a/packages/circuits/README.md +++ /dev/null @@ -1 +0,0 @@ -templates/README.md \ No newline at end of file diff --git a/packages/circuits/README.md b/packages/circuits/README.md new file mode 100644 index 000000000..4694f39e1 --- /dev/null +++ b/packages/circuits/README.md @@ -0,0 +1,50 @@ +

+

+ ZK-kit circuits +

+

A comprehensive library of general-purpose zero-knowledge circuits.

+

+ +

+ + + + + Github license + + + NPM version + + + Downloads + + + npm bundle size (scoped) + +

+ +
+

+ + 🗣️ Chat & Support + +

+
+ +--- + +## 🛠 Install + +### npm or yarn + +Install the `@zk-kit/circuits` package with npm: + +```bash +npm i @zk-kit/circuits --save +``` + +or yarn: + +```bash +yarn add @zk-kit/circuits +``` diff --git a/packages/circuits/templates/binary-merkle-root.circom b/packages/circuits/circom/binary-merkle-root.circom similarity index 100% rename from packages/circuits/templates/binary-merkle-root.circom rename to packages/circuits/circom/binary-merkle-root.circom diff --git a/packages/circuits/circom/circuits.json b/packages/circuits/circom/circuits.json new file mode 100644 index 000000000..5f6fa74fb --- /dev/null +++ b/packages/circuits/circom/circuits.json @@ -0,0 +1,11 @@ +{ + "poseidon-proof": { + "file": "poseidon-proof", + "template": "PoseidonProof" + }, + "binary-merkle-root": { + "file": "binary-merkle-root", + "template": "BinaryMerkleRoot", + "params": [20] + } +} diff --git a/packages/circuits/templates/poseidon-proof.circom b/packages/circuits/circom/poseidon-proof.circom similarity index 100% rename from packages/circuits/templates/poseidon-proof.circom rename to packages/circuits/circom/poseidon-proof.circom diff --git a/packages/circuits/circomkit.json b/packages/circuits/circomkit.json new file mode 100644 index 000000000..936e64b6e --- /dev/null +++ b/packages/circuits/circomkit.json @@ -0,0 +1,17 @@ +{ + "protocol": "groth16", + "prime": "bn128", + "version": "2.1.5", + "circuits": "./circom/circuits.json", + "dirPtau": "./ptau", + "dirCircuits": "./circom", + "dirInputs": "./inputs", + "dirBuild": "./build", + "optimization": 1, + "inspect": true, + "include": ["../../node_modules/circomlib/circuits"], + "groth16numContributions": 1, + "groth16askForEntropy": false, + "logLevel": "INFO", + "verbose": true +} diff --git a/packages/circuits/components/binary-merkle-root.circom b/packages/circuits/components/binary-merkle-root.circom deleted file mode 100644 index 7f59cddd4..000000000 --- a/packages/circuits/components/binary-merkle-root.circom +++ /dev/null @@ -1,5 +0,0 @@ -pragma circom 2.1.5; - -include "../templates/binary-merkle-root.circom"; - -component main {public [depth]} = BinaryMerkleRoot(16); diff --git a/packages/circuits/components/poseidon-proof.circom b/packages/circuits/components/poseidon-proof.circom deleted file mode 100644 index 4b45a3c87..000000000 --- a/packages/circuits/components/poseidon-proof.circom +++ /dev/null @@ -1,5 +0,0 @@ -pragma circom 2.1.5; - -include "../templates/poseidon-proof.circom"; - -component main {public [scope]} = PoseidonProof(); diff --git a/packages/circuits/noir/.gitkeep b/packages/circuits/noir/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/packages/circuits/package.json b/packages/circuits/package.json index 1b913981c..07fcbaab5 100644 --- a/packages/circuits/package.json +++ b/packages/circuits/package.json @@ -1,9 +1,27 @@ { - "name": "circuits", - "private": true, - "description": "A comprehensive library of general-purpose Circom circuits.", + "name": "@zk-kit/circuits", + "version": "0.2.0", + "description": "A comprehensive library of general-purpose zero-knowledge circuits.", "license": "MIT", + "files": [ + "circom", + "noir", + "LICENSE", + "README.md" + ], + "repository": "git@github.com:privacy-scaling-explorations/zk-kit.git", + "homepage": "https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/circuits.sol", "scripts": { - "compile": "circom --r1cs -l ../../node_modules/circomlib/circuits" + "circom:compile": "circomkit compile", + "circom:setup": "circomkit setup" + }, + "dependencies": { + "circomlib": "^2.0.5" + }, + "devDependencies": { + "circomkit": "^0.0.18" + }, + "publishConfig": { + "access": "public" } } diff --git a/packages/circuits/templates/LICENSE b/packages/circuits/templates/LICENSE deleted file mode 100644 index 4377091ec..000000000 --- a/packages/circuits/templates/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2023 Ethereum Foundation - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/packages/circuits/templates/README.md b/packages/circuits/templates/README.md deleted file mode 100644 index f8980fab3..000000000 --- a/packages/circuits/templates/README.md +++ /dev/null @@ -1,50 +0,0 @@ -

-

- ZK-kit circuits -

-

A comprehensive library of general-purpose Circom circuits.

-

- -

- - - - - Github license - - - NPM version - - - Downloads - - - npm bundle size (scoped) - -

- -
-

- - 🗣️ Chat & Support - -

-
- ---- - -## 🛠 Install - -### npm or yarn - -Install the `@zk-kit/circuits` package with npm: - -```bash -npm i @zk-kit/circuits --save -``` - -or yarn: - -```bash -yarn add @zk-kit/circuits -``` diff --git a/packages/circuits/templates/package.json b/packages/circuits/templates/package.json deleted file mode 100644 index 3fb074be9..000000000 --- a/packages/circuits/templates/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "@zk-kit/circuits", - "version": "0.1.0", - "description": "A comprehensive library of general-purpose Circom circuits.", - "license": "MIT", - "files": [ - "**/*.circom", - "LICENSE", - "README.md" - ], - "keywords": [ - "zk-kit", - "circom", - "circuits" - ], - "repository": "git@github.com:privacy-scaling-explorations/zk-kit.git", - "homepage": "https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/circuits.sol", - "publishConfig": { - "access": "public" - }, - "dependencies": { - "circomlib": "^2.0.5" - } -} diff --git a/yarn.lock b/yarn.lock index 0994e94aa..31977182a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4399,10 +4399,11 @@ __metadata: languageName: node linkType: hard -"@zk-kit/circuits@workspace:packages/circuits/templates": +"@zk-kit/circuits@workspace:packages/circuits": version: 0.0.0-use.local - resolution: "@zk-kit/circuits@workspace:packages/circuits/templates" + resolution: "@zk-kit/circuits@workspace:packages/circuits" dependencies: + circomkit: ^0.0.18 circomlib: ^2.0.5 languageName: unknown linkType: soft @@ -6080,7 +6081,7 @@ __metadata: languageName: node linkType: hard -"chai@npm:^4.2.0, chai@npm:^4.3.6": +"chai@npm:^4.2.0, chai@npm:^4.3.6, chai@npm:^4.3.7": version: 4.3.10 resolution: "chai@npm:4.3.10" dependencies: @@ -6409,6 +6410,20 @@ __metadata: languageName: node linkType: hard +"circomkit@npm:^0.0.18": + version: 0.0.18 + resolution: "circomkit@npm:0.0.18" + dependencies: + chai: ^4.3.7 + circom_tester: ^0.0.19 + loglevel: ^1.8.1 + snarkjs: ^0.7.0 + bin: + circomkit: dist/bin/index.js + checksum: 4120fdf8523f8d595a85e673bb74b8d683a302a401bf049ecb1a0ff4ad178e8f77ed7d12a50856c1be5f56bb8666f861a240d432f2ada78faa13dec161780cf1 + languageName: node + linkType: hard + "circomlib@npm:0.5.1": version: 0.5.1 resolution: "circomlib@npm:0.5.1" @@ -6455,12 +6470,6 @@ __metadata: languageName: node linkType: hard -"circuits@workspace:packages/circuits": - version: 0.0.0-use.local - resolution: "circuits@workspace:packages/circuits" - languageName: unknown - linkType: soft - "cjs-module-lexer@npm:^0.6.0": version: 0.6.0 resolution: "cjs-module-lexer@npm:0.6.0" @@ -9123,7 +9132,7 @@ __metadata: languageName: node linkType: hard -"ffjavascript@npm:^0.2.30, ffjavascript@npm:^0.2.35, ffjavascript@npm:^0.2.38": +"ffjavascript@npm:0.2.62, ffjavascript@npm:^0.2.30, ffjavascript@npm:^0.2.35, ffjavascript@npm:^0.2.38": version: 0.2.62 resolution: "ffjavascript@npm:0.2.62" dependencies: @@ -13351,6 +13360,13 @@ __metadata: languageName: node linkType: hard +"loglevel@npm:^1.8.1": + version: 1.8.1 + resolution: "loglevel@npm:1.8.1" + checksum: a1a62db40291aaeaef2f612334c49e531bff71cc1d01a2acab689ab80d59e092f852ab164a5aedc1a752fdc46b7b162cb097d8a9eb2cf0b299511106c29af61d + languageName: node + linkType: hard + "logplease@npm:^1.2.15": version: 1.2.15 resolution: "logplease@npm:1.2.15" @@ -15501,6 +15517,18 @@ __metadata: languageName: node linkType: hard +"r1csfile@npm:0.0.47": + version: 0.0.47 + resolution: "r1csfile@npm:0.0.47" + dependencies: + "@iden3/bigarray": 0.0.2 + "@iden3/binfileutils": 0.0.11 + fastfile: 0.0.20 + ffjavascript: 0.2.60 + checksum: edeb325b83851a71cbca2e5de56eb622ee5347ecae921b526a5fc484c4825b6b30c73b6fde40e9bc5112b9d21e046af885bf212ed9cee2efbc6de93b8454ec06 + languageName: node + linkType: hard + "randombytes@npm:^2.1.0": version: 2.1.0 resolution: "randombytes@npm:2.1.0" @@ -16839,6 +16867,26 @@ __metadata: languageName: node linkType: hard +"snarkjs@npm:^0.7.0": + version: 0.7.2 + resolution: "snarkjs@npm:0.7.2" + dependencies: + "@iden3/binfileutils": 0.0.11 + bfj: ^7.0.2 + blake2b-wasm: ^2.4.0 + circom_runtime: 0.1.24 + ejs: ^3.1.6 + fastfile: 0.0.20 + ffjavascript: 0.2.62 + js-sha3: ^0.8.0 + logplease: ^1.2.15 + r1csfile: 0.0.47 + bin: + snarkjs: build/cli.cjs + checksum: c784e2171278403b2356ddc42fac47093e7cf4c48c0ef46ac3c269c308795d2da63a00dd6b92521b166f3d0349d0b8301454f5a9633b5db447755b4568c4b5e7 + languageName: node + linkType: hard + "socks-proxy-agent@npm:^8.0.1": version: 8.0.2 resolution: "socks-proxy-agent@npm:8.0.2"