Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Zerokit RLN Module
The Zerokit RLN Module provides a Rust implementation for working with Rate-Limiting Nullifier RLN zkSNARK proofs and primitives. This module allows you to:
- Generate and verify RLN proofs
- Work with Merkle trees for commitment storage
- Implement rate-limiting mechanisms for distributed systems
Quick Start
[!IMPORTANT] Version 0.6.1 is required for WASM support or x32 architecture. Current version doesn't support these platforms due to dependency issues. WASM support will return in a future release.
Add RLN as dependency
We start by adding zerokit RLN to our Cargo.toml
[]
= { = "https://github.com/vacp2p/zerokit" }
Basic Usage Example
Note that we need to pass to RLN object constructor the path where the graph file (graph.bin
, built for the input tree size), the corresponding proving key (rln_final.zkey
) or (rln_final_uncompr.arkzkey
) and verification key (verification_key.arkvkey
, optional) are found.
In the following we will use cursors as readers/writers for interfacing with RLN public APIs.
use Cursor;
use ;
use json;
Comments for the code above for point 4
The external nullifier
includes two parameters.
The first one is epoch
and it's used to identify messages received in a certain time frame.
It usually corresponds to the current UNIX time but can also be set to a random value or generated by a seed, provided that it corresponds to a field element.
The second one is rln_identifier
and it's used to prevent a RLN ZK proof generated for one application to be re-used in another one.
Features
- Multiple Backend Support: Choose between different zkey formats with feature flags
arkzkey
: Use the optimized Arkworks-compatible zkey format (faster loading)stateless
: For stateless proof verification
- Pre-compiled Circuits: Ready-to-use circuits with Merkle tree height of 20
Building and Testing
Prerequisites
Build Commands
# Build with default features
# Test with default features
# Test with specific features
Advanced: Custom Circuit Compilation
The rln
(https://github.com/rate-limiting-nullifier/circom-rln) repository, which contains the RLN circuit implementation is using for pre-compiled RLN circuit for zerokit RLN.
If you want to compile your own RLN circuit, you can follow the instructions below.
1. Compile ZK Circuits for getting the zkey and verification key files
This script actually generates not only the zkey and verification key files for the RLN circuit, but also the execution wasm file used for witness calculation.
However, the wasm file is not needed for the rln
module, because current implementation uses the iden3 graph file for witness calculation.
This graph file is generated by the circom-witnesscalc
tool in step 2.
To customize the circuit parameters, modify circom-rln/circuits/rln.circom
:
pragma circom 2.1.0;
include "./rln.circom";
component main { public [x, externalNullifier] } = RLN(N, M);
Where:
-
N
: Merkle tree height, determining the maximum membership capacity (2^N members). -
M
: Bit size for range checks, setting an upper bound for the number of messages per epoch (2^M messages).
[!NOTE] However, if
N
is too big, this might require a larger Powers of Tau ceremony than the one hardcoded in./scripts/build-circuits.sh
, which is2^14
.
In such case, we refer to the official Circom documentation for instructions on how to run an appropriate Powers of Tau ceremony and Phase 2 in order to compile the desired circuit.
Additionally, whileM
sets an upper bound on the number of messages per epoch (2^M
), you can configure lower message limit for your use case, as long as it satisfiesuser_message_limit ≤ 2^M
.
Currently, therln
module comes with a pre-compiled RLN circuit with a Merkle tree of height20
and a bit size of16
, allowing up to2^20
registered members and a2^16
message limit per epoch.
Install circom compiler
You can follow the instructions below or refer to the installing Circom guide for more details, but make sure to use the specific version v2.1.0
.
# Clone the circom repository
# Checkout the specific version
&&
# Build the circom compiler
# Install the circom binary globally
# Check the circom version to ensure it's v2.1.0
Generate the zkey and verification key files example
# Clone the circom-rln repository
# Install dependencies
&&
# Build circuits
# Use the generated zkey file in subsequent steps
2. Generate Witness Calculation Graph
The execution graph file used for witness calculation can be compiled following instructions in the circom-witnesscalc repository.
As mentioned in step 1, we should use rln.circom
file from circom-rln
repository.
# Clone the circom-witnesscalc repository
# Load the submodules
&&
# Build the circom-witnesscalc tool
# Generate the witness calculation graph
The rln
module comes with pre-compiled execution graph files for the RLN circuit.
3. Generate Arkzkey Representation for zkey and verification key files
For faster loading, compile the zkey file into the arkzkey format using ark-zkey. This is fork of the original repository with the uncompressed zkey support.
# Clone the ark-zkey repository
# Build the ark-zkey tool
&&
# Generate the arkzkey representation for the zkey file
Currently, the rln
module comes with pre-compiled arkzkey keys for the RLN circuit.
Get involved
Zerokit RLN public and FFI APIs allow interaction with many more features than what briefly showcased above.
We invite you to check our API documentation by running
cargo doc --no-deps
and look at unit tests to have an hint on how to interface and use them.
Detailed Protocol Flow
- Identity Creation: Generate a secret key and commitment
- Rate Commitment: Add commitment to a Merkle tree
- External Nullifier Setup: Combine epoch and application identifier
- Proof Generation: Create a zkSNARK proof that:
- Proves membership in the Merkle tree
- Ensures rate-limiting constraints are satisfied
- Generates a nullifier to prevent double-usage
- Proof Verification: Verify the proof without revealing the prover's identity
Getting Involved
- Check the unit tests for more usage examples
- RFC specification for the Rate-Limiting Nullifier protocol
- GitHub repository for the latest updates