Skip to content

Commit dc0b317

Browse files
authored
release v0.8.0 (#315)
1 parent 36013bf commit dc0b317

File tree

9 files changed

+160
-83
lines changed

9 files changed

+160
-83
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rln-wasm/Cargo.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rln-wasm"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
edition = "2021"
55
license = "MIT or Apache2"
66

@@ -9,7 +9,9 @@ crate-type = ["cdylib", "rlib"]
99
required-features = ["stateless"]
1010

1111
[dependencies]
12-
rln = { path = "../rln", default-features = false }
12+
rln = { path = "../rln", version = "0.8.0", default-features = false }
13+
zerokit_utils = { path = "../utils", version = "0.6.0" }
14+
1315
num-bigint = { version = "0.4.6", default-features = false }
1416
js-sys = "0.3.77"
1517
wasm-bindgen = "0.2.100"
@@ -21,7 +23,6 @@ wasm-bindgen-rayon = { version = "1.2.0", optional = true }
2123
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
2224
# code size when deploying.
2325
console_error_panic_hook = { version = "0.1.7", optional = true }
24-
zerokit_utils = { path = "../utils" }
2526

2627
[target.'cfg(target_arch = "wasm32")'.dependencies]
2728
getrandom = { version = "0.2.16", features = ["js"] }
@@ -40,3 +41,6 @@ default = ["console_error_panic_hook"]
4041
stateless = ["rln/stateless"]
4142
arkzkey = ["rln/arkzkey"]
4243
multithread = ["wasm-bindgen-rayon"]
44+
45+
[package.metadata.docs.rs]
46+
all-features = true

rln-wasm/README.md

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
# RLN for WASM
22

3-
This library is used in [waku-org/js-rln](https://github.com/waku-org/js-rln/)
3+
[![npm version](https://badge.fury.io/js/@waku%2Fzerokit-rln-wasm.svg)](https://badge.fury.io/js/@waku%2Fzerokit-rln-wasm)
4+
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5+
[![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
6+
7+
The Zerokit RLN WASM Module provides WebAssembly bindings for working with
8+
Rate-Limiting Nullifier [RLN](https://rfc.vac.dev/spec/32/) zkSNARK proofs and primitives.
9+
This module is used by [waku-org/js-rln](https://github.com/waku-org/js-rln/) to enable
10+
RLN functionality in JavaScript/TypeScript applications.
411

512
## Install Dependencies
613

714
> [!NOTE]
815
> This project requires the following tools:
916
>
10-
> - `wasm-pack` (for compiling Rust to WebAssembly)
11-
> - `cargo-make` (for running build commands)
12-
> - `nvm` (to install and manage Node.js)
17+
> - `wasm-pack` - for compiling Rust to WebAssembly
18+
> - `cargo-make` - for running build commands
19+
> - `nvm` - to install and manage Node.js
1320
>
1421
> Ensure all dependencies are installed before proceeding.
1522
@@ -29,7 +36,8 @@ cargo install cargo-make
2936

3037
#### Install `Node.js`
3138

32-
If you don't have `nvm` (Node Version Manager), install it by following the [installation instructions](https://github.com/nvm-sh/nvm?tab=readme-ov-file#install--update-script).
39+
If you don't have `nvm` (Node Version Manager), install it by following
40+
the [installation instructions](https://github.com/nvm-sh/nvm?tab=readme-ov-file#install--update-script).
3341

3442
After installing `nvm`, install and use Node.js `v22.14.0`:
3543

@@ -39,7 +47,8 @@ nvm use 22.14.0
3947
nvm alias default 22.14.0
4048
```
4149

42-
If you already have Node.js installed, check your version with `node -v` command — the version must be strictly greater than 22.
50+
If you already have Node.js installed,
51+
check your version with `node -v` command — the version must be strictly greater than 22.
4352

4453
### Or install everything
4554

@@ -90,7 +99,8 @@ cargo make test_browser_arkzkey
9099

91100
## Parallel computation
92101

93-
The library supports parallel computation using the `wasm-bindgen-rayon` crate, enabling multi-threaded execution in the browser.
102+
The library supports parallel computation using the `wasm-bindgen-rayon` crate,
103+
enabling multi-threaded execution in the browser.
94104

95105
> [!NOTE]
96106
> Parallel support is not enabled by default due to WebAssembly and browser limitations. \
@@ -126,7 +136,8 @@ cargo make build_multithread_arkzkey
126136

127137
### WebAssembly Threading Support
128138

129-
Most modern browsers support WebAssembly threads, but they require the following headers to enable `SharedArrayBuffer`, which is necessary for multithreading:
139+
Most modern browsers support WebAssembly threads,
140+
but they require the following headers to enable `SharedArrayBuffer`, which is necessary for multithreading:
130141

131142
- Cross-Origin-Opener-Policy: same-origin
132143
- Cross-Origin-Embedder-Policy: require-corp
@@ -135,9 +146,12 @@ Without these, the application will fall back to single-threaded mode.
135146

136147
## Feature detection
137148

138-
If you're targeting [older browser versions that didn't support WebAssembly threads yet](https://webassembly.org/roadmap/), you'll likely want to create two builds - one with thread support and one without - and use feature detection to choose the right one on the JavaScript side.
149+
If you're targeting [older browser versions that didn't support WebAssembly threads yet](https://webassembly.org/roadmap/),
150+
you'll likely want to create two builds - one with thread support and one without -
151+
and use feature detection to choose the right one on the JavaScript side.
139152

140-
You can use [wasm-feature-detect](https://github.com/GoogleChromeLabs/wasm-feature-detect) library for this purpose. For example, your code might look like this:
153+
You can use [wasm-feature-detect](https://github.com/GoogleChromeLabs/wasm-feature-detect)library for this purpose.
154+
For example, your code might look like this:
141155

142156
```js
143157
import { threads } from 'wasm-feature-detect';

rln/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rln"
3-
version = "0.7.0"
3+
version = "0.8.0"
44
edition = "2021"
55
license = "MIT OR Apache-2.0"
66
description = "APIs to manage, compute and verify zkSNARK proofs and RLN primitives"
@@ -53,7 +53,7 @@ rand = "0.8.5"
5353
rand_chacha = "0.3.1"
5454
ruint = { version = "1.15.0", features = ["rand", "serde", "ark-ff-04"] }
5555
tiny-keccak = { version = "2.0.2", features = ["keccak"] }
56-
utils = { package = "zerokit_utils", version = "0.5.2", path = "../utils", default-features = false }
56+
utils = { package = "zerokit_utils", version = "0.6.0", path = "../utils", default-features = false }
5757

5858
# serialization
5959
prost = "0.13.5"

rln/README.md

Lines changed: 60 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Zerokit RLN Module
22

33
[![Crates.io](https://img.shields.io/crates/v/rln.svg)](https://crates.io/crates/rln)
4+
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5+
[![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
46

5-
The Zerokit RLN Module provides a Rust implementation for working with Rate-Limiting Nullifier [RLN](https://rfc.vac.dev/spec/32/) zkSNARK proofs and primitives. This module allows you to:
7+
The Zerokit RLN Module provides a Rust implementation for working with
8+
Rate-Limiting Nullifier [RLN](https://rfc.vac.dev/spec/32/) zkSNARK proofs and primitives.
9+
This module allows you to:
610

711
- Generate and verify RLN proofs
812
- Work with Merkle trees for commitment storage
@@ -11,7 +15,8 @@ The Zerokit RLN Module provides a Rust implementation for working with Rate-Limi
1115
## Quick Start
1216

1317
> [!IMPORTANT]
14-
> 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.
18+
> Version 0.7.0 is the only version that does not support WASM and x32 architecture.
19+
> WASM support is available in version 0.8.0 and above.
1520
1621
### Add RLN as dependency
1722

@@ -24,9 +29,16 @@ rln = { git = "https://github.com/vacp2p/zerokit" }
2429

2530
## Basic Usage Example
2631

27-
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.
32+
The RLN object constructor requires the following files:
2833

29-
In the following we will use [cursors](https://doc.rust-lang.org/std/io/struct.Cursor.html) as readers/writers for interfacing with RLN public APIs.
34+
- `graph.bin`: The graph file built for the input tree size
35+
- `rln_final.zkey` or `rln_final_uncompr.arkzkey`: The proving key
36+
- `verification_key.arkvkey`: The verification key (optional)
37+
38+
Additionally, `rln.wasm` is used for testing in the rln-wasm module.
39+
40+
In the following we will use [cursors](https://doc.rust-lang.org/std/io/struct.Cursor.html)
41+
as readers/writers for interfacing with RLN public APIs.
3042

3143
```rust
3244
use std::io::Cursor;
@@ -74,7 +86,8 @@ fn main() {
7486
let signal = b"RLN is awesome";
7587

7688
// 6. Prepare input for generate_rln_proof API
77-
// input_data is [ identity_secret<32> | id_index<8> | external_nullifier<32> | user_message_limit<32> | message_id<32> | signal_len<8> | signal<var> ]
89+
// input_data is [ identity_secret<32> | id_index<8> | external_nullifier<32>
90+
// | user_message_limit<32> | message_id<32> | signal_len<8> | signal<var> ]
7891
let prove_input = prepare_prove_input(
7992
identity_secret_hash,
8093
id_index,
@@ -92,11 +105,13 @@ fn main() {
92105
.unwrap();
93106

94107
// We get the public outputs returned by the circuit evaluation
95-
// The byte vector `proof_data` is serialized as `[ zk-proof | tree_root | external_nullifier | share_x | share_y | nullifier ]`.
108+
// The byte vector `proof_data` is serialized as
109+
// `[ zk-proof | tree_root | external_nullifier | share_x | share_y | nullifier ]`.
96110
let proof_data = output_buffer.into_inner();
97111

98112
// 8. Verify a RLN proof
99-
// Input buffer is serialized as `[proof_data | signal_len | signal ]`, where `proof_data` is (computed as) the output obtained by `generate_rln_proof`.
113+
// Input buffer is serialized as `[proof_data | signal_len | signal ]`,
114+
// where `proof_data` is (computed as) the output obtained by `generate_rln_proof`.
100115
let verify_data = prepare_verify_input(proof_data, signal);
101116

102117
// We verify the zk-proof against the provided proof values
@@ -113,16 +128,22 @@ fn main() {
113128
The `external nullifier` includes two parameters.
114129

115130
The first one is `epoch` and it's used to identify messages received in a certain time frame.
116-
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.
131+
It usually corresponds to the current UNIX time but can also be set to a random value or generated by a seed,
132+
provided that it corresponds to a field element.
117133

118-
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.
134+
The second one is `rln_identifier` and it's used to prevent a RLN ZK proof generated
135+
for one application to be re-used in another one.
119136

120137
### Features
121138

122139
- **Multiple Backend Support**: Choose between different zkey formats with feature flags
123140
- `arkzkey`: Use the optimized Arkworks-compatible zkey format (faster loading)
124141
- `stateless`: For stateless proof verification
125-
- **Pre-compiled Circuits**: Ready-to-use circuits with Merkle tree height of 20
142+
- **Pre-compiled Circuits**: Ready-to-use circuits with Merkle tree depth of 20
143+
- **Wasm Support**: WebAssembly bindings via rln-wasm crate with features like:
144+
- Browser and Node.js compatibility
145+
- Optional multi-threading support using wasm-bindgen-rayon
146+
- Headless browser testing capabilities
126147

127148
## Building and Testing
128149

@@ -150,13 +171,16 @@ cargo make test_stateless # For stateless feature
150171

151172
## Advanced: Custom Circuit Compilation
152173

153-
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.
174+
The `rln` (<https://github.com/rate-limiting-nullifier/circom-rln>) repository,
175+
which contains the RLN circuit implementation is using for pre-compiled RLN circuit for zerokit RLN.
154176
If you want to compile your own RLN circuit, you can follow the instructions below.
155177

156178
### 1. Compile ZK Circuits for getting the zkey and verification key files
157179

158-
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.
159-
However, the wasm file is not needed for the `rln` module, because current implementation uses the iden3 graph file for witness calculation.
180+
This script actually generates not only the zkey and verification key files for the RLN circuit,
181+
but also the execution wasm file used for witness calculation.
182+
However, the wasm file is not needed for the `rln` module,
183+
because current implementation uses the iden3 graph file for witness calculation.
160184
This graph file is generated by the `circom-witnesscalc` tool in [step 2](#2-generate-witness-calculation-graph).
161185

162186
To customize the circuit parameters, modify `circom-rln/circuits/rln.circom`:
@@ -169,19 +193,27 @@ component main { public [x, externalNullifier] } = RLN(N, M);
169193

170194
Where:
171195

172-
- `N`: Merkle tree height, determining the maximum membership capacity (2^N members).
196+
- `N`: Merkle tree depth, determining the maximum membership capacity (2^N members).
173197

174198
- `M`: Bit size for range checks, setting an upper bound for the number of messages per epoch (2^M messages).
175199

176200
> [!NOTE]
177-
> 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 is `2^14`. \
178-
> In such case, we refer to the official [Circom documentation](https://docs.circom.io/getting-started/proving-circuits/#powers-of-tau) for instructions on how to run an appropriate Powers of Tau ceremony and Phase 2 in order to compile the desired circuit. \
179-
> Additionally, while `M` 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 satisfies `user_message_limit ≤ 2^M`. \
180-
> Currently, the `rln` module comes with a [pre-compiled](https://github.com/vacp2p/zerokit/tree/master/rln/resources) RLN circuit with a Merkle tree of height `20` and a bit size of `16`, allowing up to `2^20` registered members and a `2^16` message limit per epoch.
201+
> However, if `N` is too big, this might require a larger Powers of Tau ceremony
202+
> than the one hardcoded in `./scripts/build-circuits.sh`, which is `2^14`.
203+
> In such case, we refer to the official
204+
> [Circom documentation](https://docs.circom.io/getting-started/proving-circuits/#powers-of-tau)
205+
> for instructions on how to run an appropriate Powers of Tau ceremony and Phase 2 in order to compile the desired circuit. \
206+
> Additionally, while `M` sets an upper bound on the number of messages per epoch (`2^M`),
207+
> you can configure lower message limit for your use case, as long as it satisfies `user_message_limit ≤ 2^M`. \
208+
> Currently, the `rln` module comes with a [pre-compiled](https://github.com/vacp2p/zerokit/tree/master/rln/resources)
209+
> RLN circuit with a Merkle tree of depth `20` and a bit size of `16`,
210+
> allowing up to `2^20` registered members and a `2^16` message limit per epoch.
181211
182212
#### Install circom compiler
183213

184-
You can follow the instructions below or refer to the [installing Circom](https://docs.circom.io/getting-started/installation/#installing-circom) guide for more details, but make sure to use the specific version `v2.1.0`.
214+
You can follow the instructions below or refer to the
215+
[installing Circom](https://docs.circom.io/getting-started/installation/#installing-circom) guide for more details,
216+
but make sure to use the specific version `v2.1.0`.
185217

186218
```sh
187219
# Clone the circom repository
@@ -218,7 +250,8 @@ cp zkeyFiles/rln/final.zkey <path_to_rln_final.zkey>
218250

219251
### 2. Generate Witness Calculation Graph
220252

221-
The execution graph file used for witness calculation can be compiled following instructions in the [circom-witnesscalc](https://github.com/iden3/circom-witnesscalc) repository.
253+
The execution graph file used for witness calculation can be compiled following instructions
254+
in the [circom-witnesscalc](https://github.com/iden3/circom-witnesscalc) repository.
222255
As mentioned in step 1, we should use `rln.circom` file from `circom-rln` repository.
223256

224257
```sh
@@ -235,11 +268,14 @@ cargo build
235268
cargo run --package circom_witnesscalc --bin build-circuit ../circom-rln/circuits/rln.circom <path_to_graph.bin>
236269
```
237270

238-
The `rln` module comes with [pre-compiled](https://github.com/vacp2p/zerokit/tree/master/rln/resources) execution graph files for the RLN circuit.
271+
The `rln` module comes with [pre-compiled](https://github.com/vacp2p/zerokit/tree/master/rln/resources)
272+
execution graph files for the RLN circuit.
239273

240274
### 3. Generate Arkzkey Representation for zkey and verification key files
241275

242-
For faster loading, compile the zkey file into the arkzkey format using [ark-zkey](https://github.com/seemenkina/ark-zkey). This is fork of the [original](https://github.com/zkmopro/ark-zkey) repository with the uncompressed zkey support.
276+
For faster loading, compile the zkey file into the arkzkey format using
277+
[ark-zkey](https://github.com/seemenkina/ark-zkey).
278+
This is fork of the [original](https://github.com/zkmopro/ark-zkey) repository with the uncompressed zkey support.
243279

244280
```sh
245281
# Clone the ark-zkey repository
@@ -252,7 +288,8 @@ cd ark-zkey && cargo build
252288
cargo run --bin arkzkey-util <path_to_rln_final.zkey>
253289
```
254290

255-
Currently, the `rln` module comes with [pre-compiled](https://github.com/vacp2p/zerokit/tree/master/rln/resources) arkzkey keys for the RLN circuit.
291+
Currently, the `rln` module comes with
292+
[pre-compiled](https://github.com/vacp2p/zerokit/tree/master/rln/resources) arkzkey keys for the RLN circuit.
256293

257294
## Get involved
258295

rln/src/protocol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub fn deserialize_identity_tuple(serialized: Vec<u8>) -> (Fr, Fr, Fr, Fr) {
100100
/// # Errors
101101
///
102102
/// Returns an error if `rln_witness.message_id` is not within `rln_witness.user_message_limit`.
103-
/// input data is [ identity_secret<32> | user_message_limit<32> | message_id<32> | path_elements[<32>] | identity_path_index<8> | x<32> | external_nullifier<32> ]
103+
/// input data is [ identity_secret<32> | user_message_limit<32> | message_id<32> | path_elements<32> | identity_path_index<8> | x<32> | external_nullifier<32> ]
104104
pub fn serialize_witness(rln_witness: &RLNWitnessInput) -> Result<Vec<u8>, ProtocolError> {
105105
// Check if message_id is within user_message_limit
106106
message_id_range_check(&rln_witness.message_id, &rln_witness.user_message_limit)?;

rln/src/public.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ impl RLN {
117117
/// // We create a new RLN instance
118118
/// let mut rln = RLN::new();
119119
/// ```
120-
#[cfg_attr(docsrs, doc(cfg(feature = "stateless")))]
121120
#[cfg(all(not(target_arch = "wasm32"), feature = "stateless"))]
122121
pub fn new() -> Result<RLN, RLNError> {
123122
let proving_key = zkey_from_folder().to_owned();

utils/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "zerokit_utils"
3-
version = "0.5.2"
3+
version = "0.6.0"
44
edition = "2021"
55
license = "MIT OR Apache-2.0"
66
description = "Various utilities for Zerokit"
@@ -42,3 +42,6 @@ harness = false
4242
[[bench]]
4343
name = "poseidon_benchmark"
4444
harness = false
45+
46+
[package.metadata.docs.rs]
47+
all-features = true

0 commit comments

Comments
 (0)