privacy-scaling-explorations / zk-kit

A monorepo of reusable libraries for zero-knowledge technologies.
https://zkkit.pse.dev
MIT License
290 stars 74 forks source link
javascript monorepo typescript zero-knowledge zk-kit zk-snarks

ZK-Kit logo JS

Github license GitHub Workflow Tests Coveralls Linter eslint Code style prettier Commitizen friendly

👥 Contributing   |   🤝 Code of conduct   |   🔎 Issues   |   🗣️ Chat & Support

| ZK-Kit is a set of libraries (algorithms or utility functions) that can be reused in different projects and zero-knowledge protocols, making it easier for developers to access user-friendly, tested, and documented code for common tasks. ZK-Kit provides different repositories for each language - this one contains JavaScript code only. | | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ♚ [Yarn workspaces](https://yarnpkg.com/features/workspaces): minimal monorepo package management (`yarn`, `yarn build`, `yarn docs`)\ ♛ [Conventional Commits](https://www.conventionalcommits.org): human and machine readable meaning to commit messages (`yarn commit`)\ ♜ [Jest](https://jestjs.io/): tests and test coverage for all libraries (`yarn test:libraries`)\ ♞ [ESLint](https://eslint.org/), [Prettier](https://prettier.io/): code quality and formatting (`yarn prettier` & `yarn lint`)\ ♝ [Typedocs](https://typedoc.org/): documentation generator for TypeScript (`yarn docs`)\ ♟ [Benny](https://github.com/caderek/benny): simple benchmarking framework for JavaScript/TypeScript (`yarn benchmarks`)\ ♟ [Github actions](https://github.com/features/actions): software workflows for automatic testing, documentation deploy and code quality checks ## 🗂️ Repositories - Circom: [privacy-scaling-explorations/zk-kit.circom](https://github.com/privacy-scaling-explorations/zk-kit.circom) - Javascript: [privacy-scaling-explorations/zk-kit](https://github.com/privacy-scaling-explorations/zk-kit) - Noir: [privacy-scaling-explorations/zk-kit.noir](https://github.com/privacy-scaling-explorations/zk-kit.noir) - Rust: [privacy-scaling-explorations/zk-kit.rust](https://github.com/privacy-scaling-explorations/zk-kit.rust) - Solidity: [privacy-scaling-explorations/zk-kit.solidity](https://github.com/privacy-scaling-explorations/zk-kit.solidity) ## 📄 Papers - LeanIMT ([Download PDF](https://github.com/privacy-scaling-explorations/zk-kit/raw/main/papers/leanimt/paper/leanimt-paper.pdf)) ## 📦 Packages
Package Version Downloads Size Audited
@zk-kit/eddsa-poseidon (docs) NPM version Downloads npm bundle size (scoped) ✔️
@zk-kit/poseidon-cipher (docs) NPM version Downloads npm bundle size (scoped)
@zk-kit/baby-jubjub (docs) NPM version Downloads npm bundle size (scoped) ✔️
@zk-kit/utils (docs) NPM version Downloads npm bundle size (scoped) ✔️
@zk-kit/imt (docs) NPM version Downloads npm bundle size (scoped)
@zk-kit/lean-imt (docs) NPM version Downloads npm bundle size (scoped) ✔️
@zk-kit/smt (docs) NPM version Downloads npm bundle size (scoped)
@zk-kit/poseidon-proof (docs) NPM version Downloads npm bundle size (scoped)
@zk-kit/logical-expressions (docs) NPM version Downloads npm bundle size (scoped)
## 👥 Ways to contribute - 🔧 Work on [open issues](https://github.com/privacy-scaling-explorations/zk-kit/contribute) - 📦 Suggest new [packages](https://github.com/privacy-scaling-explorations/zk-kit/issues/new?assignees=&labels=feature+%3Arocket%3A&template=---package.md&title=) - 🚀 Share ideas for new [features](https://github.com/privacy-scaling-explorations/zk-kit/issues/new?assignees=&labels=feature+%3Arocket%3A&template=---feature.md&title=) - 🐛 Create a report if you find any [bugs](https://github.com/privacy-scaling-explorations/zk-kit/issues/new?assignees=&labels=bug+%F0%9F%90%9B&template=---bug.md&title=) in the code ## 🛠 Install Clone this repository: ```bash git clone https://github.com/privacy-scaling-explorations/zk-kit.git ``` and install the dependencies: ```bash cd zk-kit && yarn ``` ## 📜 Usage ### Code quality and formatting Run [ESLint](https://eslint.org/) to analyze the code and catch bugs: ```bash yarn lint ``` Run [Prettier](https://prettier.io/) to check formatting rules: ```bash yarn format ``` or to automatically format the code: ```bash yarn format:write ``` ### Conventional commits ZK-Kit uses [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/). A [command line utility](https://github.com/commitizen/cz-cli) to commit using the correct syntax can be used by running: ```bash yarn commit ``` It will also automatically check that the modified files comply with ESLint and Prettier rules. ### Testing Test the code: ```bash yarn test ``` ### Build Build all the packages: ```bash yarn build ``` A `dist` folder will be created inside each JavaScript package. ### Documentation Generate a documentation website for each package: ```bash yarn docs ``` The output will be placed on the `docs` folder. ### Releases 1. Bump a new version of the package with: ```bash yarn version:bump # e.g. yarn version:bump utils 2.0.0 ``` This step creates a commit and a git tag. 2. Push the changes to main: ```bash git push origin main ``` 3. Push the new git tag: ```bash git push origin - # e.g. git push origin utils-v2.0.0 ``` After pushing the new git tag, a workflow will be triggered and will publish the package on [npm](https://www.npmjs.com/) and release a new version on Github with its changelogs automatically. ## ❓ FAQ #### I have a library that could be reused in other projects. How can I integrate it on ZK-kit? ZK-kit provides a set of pre-configured development tools. All you have to deal with is your own code, testing and documentation. To create a package follow these steps: 1. Fork this repository and clone it (or simply clone it directly if you are a collaborator), 2. Copy one of our current libraries and update the `README.md` and `package.json` files with your package name: ```bash cd zk-kit cp -r packages/smt packages/my-package cd packages/my-package && rm -fr node_modules dist grep -r -l "smt" . | xargs sed -i 's/smt/my-package/' # Update the remaining description/usage sections, and write your code in the src & tests folders! ``` 3. Create an [issue](https://github.com/privacy-scaling-explorations/zk-kit/issues/new?assignees=&labels=feature+%3Arocket%3A&template=---package.md&title=) for your package and open a PR. #### How can I create benchmarks for my library? You can see some examples in the `benchmarks` folder. All you have to do is create a file that exports a function to run your benchmark in that folder and add that function to the `index.ts` file. The `yarn benchmarks` command can be run with no parameters (it will run all the benchmarks), or you can specify the name of your benchmark file to run just that. When you run the command it will create a `benchmarks/results` folder with your results. #### I need to use a Merkle Tree to prove the inclusion or exclusion of data elements within a set. Which type of Merkle Tree should I use? **Incremental:** Ideal for applications where you frequently add new elements and need to update the tree efficiently. **Lean Incremental:** A more memory-efficient version of the incremental Merkle tree. **Sparse:** Particularly useful when you need proof of non-membership. | Type | Library Name | Main Feature | Used by | | -------------------- | ------------------------------------------------------------------------------------------------------ | --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- | | **Incremental** | [@zk-kit/imt](https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/imt) | Fastest for incremental updates. | [Semaphore V3](https://github.com/semaphore-protocol/semaphore/tree/v3.15.2), [Worldcoin](https://github.com/worldcoin) | | **Lean Incremental** | [@zk-kit/lean-imt](https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/lean-imt) | Optimized for lightweight environments. | [Semaphore V4](https://github.com/semaphore-protocol/semaphore), [Zupass](https://github.com/proofcarryingdata/zupass) | | **Sparse** | [@zk-kit/smt](https://github.com/privacy-scaling-explorations/zk-kit/tree/main/packages/smt) | Handles very large sets efficiently. | [Iden3](https://github.com/iden3) | Following benchmarks data of zk-kit Merkle Trees implementations: |8 leafs|insert|delete|update|generate proof|verify proof| |--|:--:|:--:|:--:|:--:|:--:| |fastest|IMT|IMT ~ SparseMT|LeanIMT|LeanIMT|IMT| |slowest|LeanIMT|IMT ~ SparseMT|IMT|SparseMT|SparseMT| | 128 leafs | insert | delete | update | generate proof | verify proof | | --------- | :-----: | :------: | :-----: | :------------: | :----------: | | fastest | IMT | SparseMT | LeanIMT | LeanIMT | SparseMT | | slowest | LeanIMT | IMT | IMT | IMT | IMT | | 1024 leafs | insert | delete | update | generate proof | verify proof | | ---------- | :------: | :------: | :-----: | :------------: | :----------: | | fastest | SparseMT | SparseMT | LeanIMT | LeanIMT | SparseMT | | slowest | LeanIMT | IMT | IMT | IMT | IMT | From the benchmark data we can take another criteria to evaluate which Merkle tree should be used: - IMT have the best performance for medium and small size insert related operations. - LeanIMT have the best performance for all the merkle tree sizes for update and generate proof related operations. - Sparse is good for larger data insert, delete and verify proof.