Skip to content

Commit

Permalink
chore(utils): add utils circuits
Browse files Browse the repository at this point in the history
  • Loading branch information
cedoor committed May 8, 2024
1 parent fe5b16d commit 864f331
Show file tree
Hide file tree
Showing 18 changed files with 1,663 additions and 9 deletions.
90 changes: 82 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,101 @@
<th>Package</th>
<th>Version</th>
<th>Downloads</th>
<th>Size</th>
<tbody>
<tr>
<td>
<a href="https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/circuits">
@zk-kit/circuits
<a href="https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/binary-merkle-root">
@zk-kit/binary-merkle-root.circom
</a>
</td>
<td>
<!-- NPM version -->
<a href="https://npmjs.org/package/@zk-kit/circuits">
<img src="https://img.shields.io/npm/v/@zk-kit/circuits.svg?style=flat-square" alt="NPM version" />
<a href="https://npmjs.org/package/@zk-kit/binary-merkle-root.circom">
<img src="https://img.shields.io/npm/v/@zk-kit/binary-merkle-root.circom.svg?style=flat-square" alt="NPM version" />
</a>
</td>
<td>
<!-- Downloads -->
<a href="https://npmjs.org/package/@zk-kit/circuits">
<img src="https://img.shields.io/npm/dm/@zk-kit/circuits.svg?style=flat-square" alt="Downloads" />
<a href="https://npmjs.org/package/@zk-kit/binary-merkle-root.circom">
<img src="https://img.shields.io/npm/dm/@zk-kit/binary-merkle-root.circom.svg?style=flat-square" alt="Downloads" />
</a>
</td>
</tr>
<tr>
<td>
<a href="https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/ecdh">
@zk-kit/ecdh.circom
</a>
</td>
<td>
<!-- NPM version -->
<a href="https://npmjs.org/package/@zk-kit/ecdh.circom">
<img src="https://img.shields.io/npm/v/@zk-kit/ecdh.circom.svg?style=flat-square" alt="NPM version" />
</a>
</td>
<td>
<!-- Downloads -->
<a href="https://npmjs.org/package/@zk-kit/ecdh.circom">
<img src="https://img.shields.io/npm/dm/@zk-kit/ecdh.circom.svg?style=flat-square" alt="Downloads" />
</a>
</td>
</tr>
<tr>
<td>
<a href="https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/poseidon-cipher">
@zk-kit/poseidon-cipher.circom
</a>
</td>
<td>
<!-- NPM version -->
<a href="https://npmjs.org/package/@zk-kit/poseidon-cipher.circom">
<img src="https://img.shields.io/npm/v/@zk-kit/poseidon-cipher.circom.svg?style=flat-square" alt="NPM version" />
</a>
</td>
<td>
<!-- Downloads -->
<a href="https://npmjs.org/package/@zk-kit/poseidon-cipher.circom">
<img src="https://img.shields.io/npm/dm/@zk-kit/poseidon-cipher.circom.svg?style=flat-square" alt="Downloads" />
</a>
</td>
</tr>
<tr>
<td>
<a href="https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/poseidon-proof">
@zk-kit/poseidon-proof.circom
</a>
</td>
<td>
<!-- NPM version -->
<a href="https://npmjs.org/package/@zk-kit/poseidon-proof.circom">
<img src="https://img.shields.io/npm/v/@zk-kit/poseidon-proof.circom.svg?style=flat-square" alt="NPM version" />
</a>
</td>
<td>
<!-- Downloads -->
<a href="https://npmjs.org/package/@zk-kit/poseidon-proof.circom">
<img src="https://img.shields.io/npm/dm/@zk-kit/poseidon-proof.circom.svg?style=flat-square" alt="Downloads" />
</a>
</td>
</tr>
<tr>
<td>
<a href="https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/utils">
@zk-kit/utils.circom
</a>
</td>
<td>
<!-- NPM version -->
<a href="https://npmjs.org/package/@zk-kit/utils.circom">
<img src="https://img.shields.io/npm/v/@zk-kit/utils.circom.svg?style=flat-square" alt="NPM version" />
</a>
</td>
<td>
<!-- Downloads -->
<a href="https://npmjs.org/package/@zk-kit/utils.circom">
<img src="https://img.shields.io/npm/dm/@zk-kit/utils.circom.svg?style=flat-square" alt="Downloads" />
</a>
</td>
<td></td>
</tr>
<tbody>
</table>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scripts": {
"compile": "yarn workspaces foreach -A -t --no-private run compile",
"test": "yarn workspaces foreach -A -t --no-private run test",
"version:bump": "yarn workspace @zk-kit/${0} version ${1} && yarn remove:stable-version-field ${0} && NO_HOOK=1 git commit -am \"chore(${0}): v${1}\" && git tag ${0}-v${1}",
"version:bump": "yarn workspace @zk-kit/${0}.circom version ${1} && yarn remove:stable-version-field ${0}.circom && NO_HOOK=1 git commit -am \"chore(${0}): v${1}\" && git tag ${0}.circom-v${1}",
"version:publish": "yarn workspaces foreach -A --no-private npm publish --tolerate-republish --access public",
"version:release": "changelogithub",
"format:prettier": "prettier -c .",
Expand Down
3 changes: 3 additions & 0 deletions packages/utils/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ptau
src/main
src/test
7 changes: 7 additions & 0 deletions packages/utils/.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extension": ["ts"],
"require": "ts-node/register",
"spec": "./**/*.test.ts",
"timeout": 100000,
"exit": true
}
21 changes: 21 additions & 0 deletions packages/utils/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 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.
51 changes: 51 additions & 0 deletions packages/utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<p align="center">
<h1 align="center">
Utils
</h1>
<p align="center">An utility library of general-purpose Circom circuits.</p>
</p>

<p align="center">
<a href="https://github.com/privacy-scaling-explorations/zk-kit.circom">
<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.circom/tree/main/packages/utils/LICENSE">
<img alt="NPM license" src="https://img.shields.io/npm/l/%40zk-kit%2Futils?style=flat-square">
</a>
<a href="https://www.npmjs.com/package/@zk-kit/utils.circom">
<img alt="NPM version" src="https://img.shields.io/npm/v/@zk-kit/utils.circom?style=flat-square" />
</a>
<a href="https://npmjs.org/package/@zk-kit/utils.circom">
<img alt="Downloads" src="https://img.shields.io/npm/dm/@zk-kit/utils.circom.svg?style=flat-square" />
</a>
</p>

<div align="center">
<h4>
<span>&nbsp;&nbsp;|&nbsp;&nbsp;</span>
<a href="https://github.com/privacy-scaling-explorations/zk-kit.circom/issues/new/choose">
🔎 Issues
</a>
<span>&nbsp;&nbsp;|&nbsp;&nbsp;</span>
<a href="https://discord.com/invite/sF5CT5rzrR">
🗣️ Chat &amp; Support
</a>
</h4>
</div>

> [!WARNING]
> This library has **not** been audited.
## 🛠 Install

Install the `@zk-kit/utils.circom` package with npm:

```bash
npm i @zk-kit/utils.circom --save
```

or yarn:

```bash
yarn add @zk-kit/utils.circom
```
17 changes: 17 additions & 0 deletions packages/utils/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": "./circuits.json",
"dirPtau": "./ptau",
"dirCircuits": "./src",
"dirInputs": "./inputs",
"dirBuild": "./build",
"optimization": 2,
"inspect": true,
"include": ["../../node_modules/circomlib/circuits"],
"groth16numContributions": 1,
"groth16askForEntropy": false,
"logLevel": "INFO",
"verbose": true
}
72 changes: 72 additions & 0 deletions packages/utils/circuits.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"msb": {
"file": "float",
"template": "MSB",
"params": [252]
},
"shift": {
"file": "float",
"template": "Shift",
"params": [252]
},
"integer-division": {
"file": "float",
"template": "IntegerDivision",
"params": [252]
},
"to-float": {
"file": "float",
"template": "ToFloat",
"params": [74]
},
"division-from-float": {
"file": "float",
"template": "DivisionFromFloat",
"params": [74, 251]
},
"division-from-normal": {
"file": "float",
"template": "DivisionFromNormal",
"params": [74, 251]
},
"multiplication-from-float": {
"file": "float",
"template": "MultiplicationFromFloat",
"params": [74, 251]
},
"multiplication-from-normal": {
"file": "float",
"template": "MultiplicationFromNormal",
"params": [74, 251]
},
"safe-less-than": {
"file": "safe-comparators",
"template": "SafeLessThan",
"pubs": ["in"],
"params": [252]
},
"safe-less-eq-than": {
"file": "safe-comparators",
"template": "SafeLessEqThan",
"pubs": ["in"],
"params": [252]
},
"safe-greater-than": {
"file": "safe-comparators",
"template": "SafeGreaterThan",
"pubs": ["in"],
"params": [252]
},
"safe-greater-eq-than": {
"file": "safe-comparators",
"template": "SafeGreaterEqThan",
"pubs": ["in"],
"params": [252]
},
"unpack-element": {
"file": "unpack-element",
"template": "UnpackElement",
"params": [4],
"pubs": ["in"]
}
}
30 changes: 30 additions & 0 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@zk-kit/utils.circom",
"version": "1.0.0-beta",
"description": "An utility library of general-purpose Circom circuits.",
"license": "MIT",
"files": [
"src/**/*.circom",
"!src/main",
"!src/test",
"LICENSE",
"README.md"
],
"repository": "[email protected]:privacy-scaling-explorations/zk-kit.circom.git",
"homepage": "https://github.com/privacy-scaling-explorations/zk-kit.circom/tree/main/packages/utils",
"scripts": {
"compile": "circomkit compile utils",
"setup": "circomkit setup utils",
"test": "mocha"
},
"dependencies": {
"circomlib": "^2.0.5"
},
"devDependencies": {
"circomkit": "^0.1.0",
"mocha": "^10.2.0"
},
"publishConfig": {
"access": "public"
}
}
72 changes: 72 additions & 0 deletions packages/utils/src/circuits.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"msb": {
"file": "float",
"template": "MSB",
"params": [252]
},
"shift": {
"file": "float",
"template": "Shift",
"params": [252]
},
"integer-division": {
"file": "float",
"template": "IntegerDivision",
"params": [252]
},
"to-float": {
"file": "float",
"template": "ToFloat",
"params": [74]
},
"division-from-float": {
"file": "float",
"template": "DivisionFromFloat",
"params": [74, 251]
},
"division-from-normal": {
"file": "float",
"template": "DivisionFromNormal",
"params": [74, 251]
},
"multiplication-from-float": {
"file": "float",
"template": "MultiplicationFromFloat",
"params": [74, 251]
},
"multiplication-from-normal": {
"file": "float",
"template": "MultiplicationFromNormal",
"params": [74, 251]
},
"safe-less-than": {
"file": "safe-comparators",
"template": "SafeLessThan",
"pubs": ["in"],
"params": [252]
},
"safe-less-eq-than": {
"file": "safe-comparators",
"template": "SafeLessEqThan",
"pubs": ["in"],
"params": [252]
},
"safe-greater-than": {
"file": "safe-comparators",
"template": "SafeGreaterThan",
"pubs": ["in"],
"params": [252]
},
"safe-greater-eq-than": {
"file": "safe-comparators",
"template": "SafeGreaterEqThan",
"pubs": ["in"],
"params": [252]
},
"unpack-element": {
"file": "unpack-element",
"template": "UnpackElement",
"params": [4],
"pubs": ["in"]
}
}
Loading

0 comments on commit 864f331

Please sign in to comment.