zerokit/utils/README.md

74 lines
2.8 KiB
Markdown
Raw Normal View History

# Zerokit Utils Crate
[![Crates.io](https://img.shields.io/crates/v/zerokit_utils.svg)](https://crates.io/crates/zerokit_utils)
Cryptographic primitives for zero-knowledge applications, featuring efficient Merkle tree implementations and a Poseidon hash function.
## Overview
This crate provides core cryptographic components optimized for zero-knowledge proof systems:
1. Multiple Merkle tree implementations with different space/time tradeoffs
2. A Poseidon hash implementation
## Merkle Tree Implementations
The crate supports two interchangeable Merkle tree implementations:
- **FullMerkleTree**
- Stores each tree node in memory
- **OptimalMerkleTree**
- Only stores nodes used to prove accumulation of set leaves
## Poseidon Hash Implementation
This crate provides an implementation to compute the Poseidon hash round constants and MDS matrices:
- **Customizable parameters**: Supports different security levels and input sizes
- **Arkworks-friendly**: Adapted to work over arkworks field traits and custom data structures
### Security Note
The MDS matrices are generated iteratively using the Grain LFSR until certain criteria are met. According to the paper, such matrices must respect specific conditions which are checked by 3 different algorithms in the reference implementation.
These validation algorithms are not currently implemented in this crate. For the hardcoded parameters, the first random matrix generated satisfies these conditions. If using different parameters, you should check against the reference implementation how many matrices are generated before outputting the correct one, and pass this number to the `skip_matrices` parameter of the `find_poseidon_ark_and_mds` function.
## Installation
Add Zerokit Utils to your Rust project:
```toml
[dependencies]
zerokit-utils = "0.5.1"
```
## Performance Considerations
- **FullMerkleTree**: Use when memory is abundant and operation speed is critical
- **OptimalMerkleTree**: Use when memory efficiency is more important than raw speed
- **Poseidon**: Offers a good balance between security and performance for ZK applications
## Building and Testing
```bash
# Build the crate
cargo build
# Run tests
cargo test
# Run benchmarks
cargo bench
```
chore: Update dependencies to latest versions (#276) * chore: Update dependencies to latest versions Upgrade various dependencies across multiple crates to their latest compatible versions * chore: Update Cargo.toml dependency versions to latest compatible releases Upgrade serde and serde_json dependency versions using more flexible version specifiers * chore: Update Cargo dependencies to latest compatible versions Upgrade Ark and Wasmer dependencies to their latest minor versions, including: - ark-circom from 0.1.0 to 0.5.0 - ark-zkey from 0.1.0 to 0.1.2 - wasmer from 2.3.0 to 2.3.x - num-traits to 0.2.19 Also update Makefile to improve cross-platform build process for wabt * chore: Update Ark dependencies to latest patch versions * chore: Revert ark-zkey dependency and update Wasmer to 4.4.0 Remove ark-zkey optional dependency and update Wasmer to version 4.4.0 across multiple crates. Modify circuit module to include necessary structs and functions previously provided by ark-zkey. * chore: Update zkey path to use uncompressed arkzkey file * Remove rln-wasm package and related configurations Clean up project structure by removing the rln-wasm package, associated GitHub workflows, and WASM-specific configurations. This includes: - Removing rln-wasm directory and its contents - Updating Cargo.toml workspace configuration - Removing WASM-specific build and test configurations from CI workflows - Removing WASM-related dependencies and features from RLN crate * Fix CI workflow for default feature testing * rollback to default * Fix CI workflow to support default feature testing * Fix CI workflow syntax for feature testing condition * Update README.md with clearer testing instructions for RLN module
2025-02-07 17:44:19 +07:00
To view the results of the benchmark, open the `target/criterion/report/index.html` file generated after the bench
## Acknowledgements
- The Merkle tree implementations are adapted from:
- [kilic/rln](https://github.com/kilic/rln/blob/master/src/merkle.rs)
- [worldcoin/semaphore-rs](https://github.com/worldcoin/semaphore-rs/blob/d462a4372f1fd9c27610f2acfe4841fab1d396aa/src/merkle_tree.rs)
- The Poseidon implementation references:
- [Poseidon reference implementation](https://extgit.iaik.tugraz.at/krypto/hadeshash/-/blob/master/code/generate_parameters_grain.sage)