You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
4
11
5
12
## Install Dependencies
6
13
7
14
> [!NOTE]
8
15
> This project requires the following tools:
9
16
>
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
13
20
>
14
21
> Ensure all dependencies are installed before proceeding.
15
22
@@ -29,7 +36,8 @@ cargo install cargo-make
29
36
30
37
#### Install `Node.js`
31
38
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).
33
41
34
42
After installing `nvm`, install and use Node.js `v22.14.0`:
35
43
@@ -39,7 +47,8 @@ nvm use 22.14.0
39
47
nvm alias default 22.14.0
40
48
```
41
49
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.
43
52
44
53
### Or install everything
45
54
@@ -90,7 +99,8 @@ cargo make test_browser_arkzkey
90
99
91
100
## Parallel computation
92
101
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.
94
104
95
105
> [!NOTE]
96
106
> Parallel support is not enabled by default due to WebAssembly and browser limitations. \
@@ -126,7 +136,8 @@ cargo make build_multithread_arkzkey
126
136
127
137
### WebAssembly Threading Support
128
138
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:
130
141
131
142
- Cross-Origin-Opener-Policy: same-origin
132
143
- Cross-Origin-Embedder-Policy: require-corp
@@ -135,9 +146,12 @@ Without these, the application will fall back to single-threaded mode.
135
146
136
147
## Feature detection
137
148
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.
139
152
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.
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:
6
10
7
11
- Generate and verify RLN proofs
8
12
- Work with Merkle trees for commitment storage
@@ -11,7 +15,8 @@ The Zerokit RLN Module provides a Rust implementation for working with Rate-Limi
11
15
## Quick Start
12
16
13
17
> [!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.
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:
28
33
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.
// 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`.
// We verify the zk-proof against the provided proof values
@@ -113,16 +128,22 @@ fn main() {
113
128
The `external nullifier` includes two parameters.
114
129
115
130
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.
117
133
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.
119
136
120
137
### Features
121
138
122
139
-**Multiple Backend Support**: Choose between different zkey formats with feature flags
123
140
-`arkzkey`: Use the optimized Arkworks-compatible zkey format (faster loading)
124
141
-`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
126
147
127
148
## Building and Testing
128
149
@@ -150,13 +171,16 @@ cargo make test_stateless # For stateless feature
150
171
151
172
## Advanced: Custom Circuit Compilation
152
173
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.
154
176
If you want to compile your own RLN circuit, you can follow the instructions below.
155
177
156
178
### 1. Compile ZK Circuits for getting the zkey and verification key files
157
179
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.
160
184
This graph file is generated by the `circom-witnesscalc` tool in [step 2](#2-generate-witness-calculation-graph).
161
185
162
186
To customize the circuit parameters, modify `circom-rln/circuits/rln.circom`:
@@ -169,19 +193,27 @@ component main { public [x, externalNullifier] } = RLN(N, M);
169
193
170
194
Where:
171
195
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).
173
197
174
198
-`M`: Bit size for range checks, setting an upper bound for the number of messages per epoch (2^M messages).
175
199
176
200
> [!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`.
> 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.
181
211
182
212
#### Install circom compiler
183
213
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`.
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.
222
255
As mentioned in step 1, we should use `rln.circom` file from `circom-rln` repository.
223
256
224
257
```sh
@@ -235,11 +268,14 @@ cargo build
235
268
cargo run --package circom_witnesscalc --bin build-circuit ../circom-rln/circuits/rln.circom <path_to_graph.bin>
236
269
```
237
270
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.
239
273
240
274
### 3. Generate Arkzkey Representation for zkey and verification key files
241
275
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
0 commit comments