Skip to content

Commit

Permalink
chore(circuits): new setup with circomkit
Browse files Browse the repository at this point in the history
re #73
  • Loading branch information
cedoor committed Nov 28, 2023
1 parent bde1116 commit 3f1ccad
Show file tree
Hide file tree
Showing 17 changed files with 261 additions and 123 deletions.
76 changes: 76 additions & 0 deletions .yarn/patches/circomkit-npm-0.0.18-e33b63f27f.patch
Original file line number Diff line number Diff line change
@@ -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
+
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
"circom"
],
"workspaces": [
"packages/*",
"packages/circuits/templates"
"packages/*"
],
"packageManager": "[email protected]",
"devDependencies": {
Expand Down Expand Up @@ -76,5 +75,8 @@
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"resolutions": {
"[email protected]": "patch:circomkit@npm:0.0.18#.yarn/patches/circomkit-npm-0.0.18-e33b63f27f.patch"
}
}
2 changes: 2 additions & 0 deletions packages/circuits/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
ptau
main
*.r1cs
*.wasm
1 change: 0 additions & 1 deletion packages/circuits/LICENSE

This file was deleted.

21 changes: 21 additions & 0 deletions packages/circuits/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
1 change: 0 additions & 1 deletion packages/circuits/README.md

This file was deleted.

50 changes: 50 additions & 0 deletions packages/circuits/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<p align="center">
<h1 align="center">
ZK-kit circuits
</h1>
<p align="center">A comprehensive library of general-purpose zero-knowledge circuits.</p>
</p>

<p align="center">
<a href="https://github.com/privacy-scaling-explorations/zk-kit">
<img src="https://img.shields.io/badge/project-zk--kit-blue.svg?style=flat-square">
</a>
<a href="https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/circuits.sol/LICENSE">
<img alt="Github license" src="https://img.shields.io/github/license/privacy-scaling-explorations/zk-kit.svg?style=flat-square">
</a>
<a href="https://www.npmjs.com/package/@zk-kit/circuits">
<img alt="NPM version" src="https://img.shields.io/npm/v/@zk-kit/circuits?style=flat-square" />
</a>
<a href="https://npmjs.org/package/@zk-kit/circuits">
<img alt="Downloads" src="https://img.shields.io/npm/dm/@zk-kit/circuits.svg?style=flat-square" />
</a>
<a href="https://bundlephobia.com/package/@zk-kit/circuits">
<img alt="npm bundle size (scoped)" src="https://img.shields.io/bundlephobia/minzip/@zk-kit/circuits" />
</a>
</p>

<div align="center">
<h4>
<a href="https://appliedzkp.org/discord">
🗣️ Chat &amp; Support
</a>
</h4>
</div>

---

## 🛠 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
```
11 changes: 11 additions & 0 deletions packages/circuits/circom/circuits.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"poseidon-proof": {
"file": "poseidon-proof",
"template": "PoseidonProof"
},
"binary-merkle-root": {
"file": "binary-merkle-root",
"template": "BinaryMerkleRoot",
"params": [20]
}
}
17 changes: 17 additions & 0 deletions packages/circuits/circomkit.json
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 0 additions & 5 deletions packages/circuits/components/binary-merkle-root.circom

This file was deleted.

5 changes: 0 additions & 5 deletions packages/circuits/components/poseidon-proof.circom

This file was deleted.

Empty file added packages/circuits/noir/.gitkeep
Empty file.
26 changes: 22 additions & 4 deletions packages/circuits/package.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]: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"
}
}
21 changes: 0 additions & 21 deletions packages/circuits/templates/LICENSE

This file was deleted.

50 changes: 0 additions & 50 deletions packages/circuits/templates/README.md

This file was deleted.

24 changes: 0 additions & 24 deletions packages/circuits/templates/package.json

This file was deleted.

Loading

0 comments on commit 3f1ccad

Please sign in to comment.