Files
zerokit/rln-cli
Vinh Trịnh 9d4198c205 feat(rln-wasm): bring back wasm support for zerokit
# Bring Back WebAssembly Support for ZeroKit

- Update minor versions of all dependencies.
- Update documentation to reflect these changes.
- ~~Vendor `wasmer` v4.4.0 in [my git
repository](https://github.com/vinhtc27/wasmer) for `ark-circom`
v0.5.0.~~
- Resolve `wasm-pack` build failures (`os error 2`) caused by a Node.js
version mismatch.
- Restore the previous CI pipeline for the `rln-wasm` feature and update
to the stable toolchain.
- ~~Use `ark-circom` with the `wasm` feature for WebAssembly
compatibility and the `rln.wasm` file for witness calculation.~~
- ~~Fix dependency issues related to `ark-circom` v0.5.0, which
currently uses `wasmer` v4.4.0 and is affected by this
[issue](https://github.com/rust-lang/rust/issues/91632#issuecomment-1477914703).~~
- Install WABT with `brew` and `apt-get` instead of cloning to fix
`wasm-strip not found` issue in the CI workflow.
- Install `wasm-pack` with `curl` instead of using `wasm-pack-action` to
fix parse exception error in the CI workflow.
- Use the `.wasm` file with JS bindings for witness calculation, which
is generated from [`iden3/circom`](https://github.com/iden3/circom)
during circuit compilation. This allows witness computation outside RLN
instance.
- Refactor the `rln` module by moving circuit-related files to the
`src/circuit` folder for better organization.
- Remove `ark-circom` and `wasmer` by cloning the
[CircomReduction](3c95ed98e2/src/circom/qap.rs (L12))
struct and the
[read_zkey](3c95ed98e2/src/zkey.rs (L53))
function into the `rln` module, which reduces the repository's build
size and speeds up compilation time and the CI workflow duration.
- These change also address
[#282](https://github.com/vacp2p/zerokit/issues/282) by removing
`wasmer` and `wasmer-wasix`, which lack x32 system support.
- Benchmark `rln-wasm` with `wasm_bindgen_test`, covering RLN instance
creation, key generation, witness calculation, proving, and
verification. Also, add them to `v0.6.1` in
[benchmark-v0.6.1](https://github.com/vacp2p/zerokit/tree/benchmark-v0.6.1)
for comparison.
- Add `arkzkey` feature for rln-wasm, including tests, benchmarks, CI
workflow updates, and related documentation.
- Benchmark rln-wasm in the browser using HTML, covering initialization,
RLN instance creation, proving, and verification; fork to the
`benchmark-v0.7.0` branch for later use
[here](https://github.com/vacp2p/zerokit/tree/benchmark-v0.7.0).
- Fix clippy error: "this `repeat().take()` can be written more
concisely" on CI workflow for `utils` module.
([error](https://github.com/vacp2p/zerokit/actions/runs/14258579070/job/39965568013))
- Update Makefile.toml to be able to run `make build`, `make test`, and
`make bench` from root and inside each modules.
2025-04-08 13:37:18 +07:00
..

Zerokit RLN-CLI

The Zerokit RLN-CLI provides a command-line interface for interacting with the public API of the Zerokit RLN Module.

It also contain:

  • Relay Example to demonstrate the use of the RLN module for spam prevention.
  • Stateless Example to demonstrate the use of the RLN module for stateless features.

Configuration

The CLI can be configured using a JSON configuration file (see the example).

You can specify the configuration file path using the RLN_CONFIG_PATH environment variable:

export RLN_CONFIG_PATH=example.config.json

Alternatively, you can provide the configuration file path as an argument for each command:

RLN_CONFIG_PATH=example.config.json cargo run -- <SUBCOMMAND> [OPTIONS]

If the configuration file is empty, default settings will be used, but the tree data folder will be temporary and not saved to the preconfigured path.

We recommend using the example config, as all commands (except new and create-with-params) require an initialized RLN instance.

Feature Flags

The CLI supports optional features. To enable the arkzkey feature, run:

cargo run --features arkzkey -- <SUBCOMMAND> [OPTIONS]

For more details, refer to the Zerokit RLN Module documentation.

Relay Example

The following Example demonstrates how RLN enables spam prevention in anonymous environments for multple users.

You can run the example using the following command:

cargo run --example relay

or with the arkzkey feature flag:

cargo run --example relay --features arkzkey

You can also change MESSAGE_LIMIT and TREEE_HEIGHT in the relay.rs file to see how the RLN instance behaves with different parameters.

The customize TREEE_HEIGHT constant differs from the default value of 20 should follow Custom Circuit Compilation instructions.

Stateless Example

The following Example demonstrates how RLN can be used for stateless features by creating the Merkle tree outside of RLN instance.

This example function similarly to the Relay Example but uses a stateless RLN and seperate Merkle tree.

You can run the example using the following command:

cargo run --example stateless --features stateless

or with the arkzkey feature flag:

cargo run --example stateless --features stateless,arkzkey

CLI Commands

Instance Management

To initialize a new RLN instance:

cargo run new --tree-height <HEIGHT>

To initialize an RLN instance with custom parameters:

cargo run new-with-params --resources-path <PATH> --tree-height <HEIGHT>

To update the Merkle tree height:

cargo run set-tree --tree-height <HEIGHT>

Leaf Operations

To set a single leaf:

cargo run set-leaf --index <INDEX> --input <INPUT_PATH>

To set multiple leaves:

cargo run set-multiple-leaves --index <START_INDEX> --input <INPUT_PATH>

To reset multiple leaves:

cargo run reset-multiple-leaves --input <INPUT_PATH>

To set the next available leaf:

cargo run set-next-leaf --input <INPUT_PATH>

To delete a specific leaf:

cargo run delete-leaf --index <INDEX>

Proof Operations

To generate a proof:

cargo run prove --input <INPUT_PATH>

To generate an RLN proof:

cargo run generate-proof --input <INPUT_PATH>

To verify a proof:

cargo run verify --input <PROOF_PATH>

To verify a proof with multiple Merkle roots:

cargo run verify-with-roots --input <INPUT_PATH> --roots <ROOTS_PATH>

Tree Information

To retrieve the current Merkle root:

cargo run get-root

To obtain a Merkle proof for a specific index:

cargo run get-proof --index <INDEX>