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: minimal monorepo package management (yarn
, yarn build
, yarn docs
)
♛ Conventional Commits: human and machine readable meaning to commit messages (yarn commit
)
♜ Jest: tests and test coverage for all libraries (yarn test:libraries
)
♞ ESLint, Prettier: code quality and formatting (yarn prettier
& yarn lint
)
♝ Typedocs: documentation generator for TypeScript (yarn docs
)
♟ Benny: simple benchmarking framework for JavaScript/TypeScript (yarn benchmarks
)
♟ Github actions: software workflows for automatic testing, documentation deploy and code quality checks
Package | Version | Downloads | Size | Audited |
---|---|---|---|---|
@zk-kit/eddsa-poseidon (docs) | ✔️ | |||
@zk-kit/poseidon-cipher (docs) | ❌ | |||
@zk-kit/baby-jubjub (docs) | ✔️ | |||
@zk-kit/utils (docs) | ✔️ | |||
@zk-kit/imt (docs) | ❌ | |||
@zk-kit/lean-imt (docs) | ✔️ | |||
@zk-kit/smt (docs) | ❌ | |||
@zk-kit/poseidon-proof (docs) | ❌ | |||
@zk-kit/logical-expressions (docs) | ❌ |
Clone this repository:
git clone https://github.com/privacy-scaling-explorations/zk-kit.git
and install the dependencies:
cd zk-kit && yarn
Run ESLint to analyze the code and catch bugs:
yarn lint
Run Prettier to check formatting rules:
yarn format
or to automatically format the code:
yarn format:write
ZK-Kit uses conventional commits. A command line utility to commit using the correct syntax can be used by running:
yarn commit
It will also automatically check that the modified files comply with ESLint and Prettier rules.
Test the code:
yarn test
Build all the packages:
yarn build
A dist
folder will be created inside each JavaScript package.
Generate a documentation website for each package:
yarn docs
The output will be placed on the docs
folder.
yarn version:bump <package-name> <version>
# e.g. yarn version:bump utils 2.0.0
This step creates a commit and a git tag.
git push origin main
git push origin <package-name>-<version>
# 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 and release a new version on Github with its changelogs automatically.
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:
README.md
and package.json
files with your package name: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!
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.
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 | Fastest for incremental updates. | Semaphore V3, Worldcoin |
Lean Incremental | @zk-kit/lean-imt | Optimized for lightweight environments. | Semaphore V4, Zupass |
Sparse | @zk-kit/smt | Handles very large sets efficiently. | 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: