feat: support feature-specific binary generation and make arkzkey the default (#326)

- Integrated missing options for generating feature-specific binaries
[(tested)](https://github.com/vacp2p/zerokit/actions/runs/16408191766).
- Made arkzkey the default feature for improved consistency.
- Created a script to convert arkzkey from zkey.
- Updated nightly-release.yaml file.
- Updated documentation.
This commit is contained in:
Vinh Trịnh
2025-07-28 15:11:41 +07:00
committed by GitHub
parent c80569d518
commit 4473688efa
29 changed files with 203 additions and 3079 deletions

View File

@@ -10,6 +10,7 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
rln = { path = "../rln", version = "0.8.0", default-features = false, features = [
"stateless",
"fullmerkletree",
] }
zerokit_utils = { path = "../utils", version = "0.6.0", default-features = false }
num-bigint = { version = "0.4.6", default-features = false }
@@ -28,7 +29,7 @@ console_error_panic_hook = { version = "0.1.7", optional = true }
getrandom = { version = "0.2.16", features = ["js"] }
[dev-dependencies]
serde_json = "1.0"
serde_json = "1.0.141"
wasm-bindgen-test = "0.3.50"
wasm-bindgen-futures = "0.4.50"
@@ -38,7 +39,6 @@ features = ["Window", "Navigator"]
[features]
default = ["console_error_panic_hook"]
arkzkey = ["rln/arkzkey"]
parallel = ["rln/parallel", "wasm-bindgen-rayon"]
[package.metadata.docs.rs]

View File

@@ -2,10 +2,6 @@
clear = true
dependencies = ["pack_build", "pack_rename", "pack_resize"]
[tasks.build_arkzkey]
clear = true
dependencies = ["pack_build_arkzkey", "pack_rename", "pack_resize"]
[tasks.build_parallel]
clear = true
dependencies = [
@@ -15,32 +11,10 @@ dependencies = [
"pack_resize",
]
[tasks.build_parallel_arkzkey]
clear = true
dependencies = [
"pack_build_parallel_arkzkey",
"post_build_parallel",
"pack_rename",
"pack_resize",
]
[tasks.pack_build]
command = "wasm-pack"
args = ["build", "--release", "--target", "web", "--scope", "waku"]
[tasks.pack_build_arkzkey]
command = "wasm-pack"
args = [
"build",
"--release",
"--target",
"web",
"--scope",
"waku",
"--features",
"arkzkey",
]
[tasks.pack_build_parallel]
command = "env"
args = [
@@ -61,26 +35,6 @@ args = [
"build-std=panic_abort,std",
]
[tasks.pack_build_parallel_arkzkey]
command = "env"
args = [
"RUSTFLAGS=-C target-feature=+atomics,+bulk-memory,+mutable-globals",
"rustup",
"run",
"nightly",
"wasm-pack",
"build",
"--release",
"--target",
"web",
"--scope",
"waku",
"--features",
"parallel,arkzkey",
"-Z",
"build-std=panic_abort,std",
]
[tasks.post_build_parallel]
script = '''
wasm-bindgen --target web --split-linked-modules --out-dir ./pkg ./target/wasm32-unknown-unknown/release/rln_wasm.wasm && \
@@ -117,21 +71,6 @@ args = [
]
dependencies = ["build"]
[tasks.test_arkzkey]
command = "wasm-pack"
args = [
"test",
"--release",
"--node",
"--target",
"wasm32-unknown-unknown",
"--features",
"arkzkey",
"--",
"--nocapture",
]
dependencies = ["build_arkzkey"]
[tasks.test_browser]
command = "wasm-pack"
args = [
@@ -148,24 +87,6 @@ args = [
]
dependencies = ["build"]
[tasks.test_browser_arkzkey]
command = "wasm-pack"
args = [
"test",
"--release",
"--chrome",
# "--firefox",
# "--safari",
"--headless",
"--target",
"wasm32-unknown-unknown",
"--features",
"arkzkey",
"--",
"--nocapture",
]
dependencies = ["build_arkzkey"]
[tasks.test_parallel]
command = "env"
args = [
@@ -191,31 +112,6 @@ args = [
]
dependencies = ["build_parallel"]
[tasks.test_parallel_arkzkey]
command = "env"
args = [
"RUSTFLAGS=-C target-feature=+atomics,+bulk-memory,+mutable-globals",
"rustup",
"run",
"nightly",
"wasm-pack",
"test",
"--release",
"--chrome",
# "--firefox",
# "--safari",
"--headless",
"--target",
"wasm32-unknown-unknown",
"--features",
"parallel,arkzkey",
"-Z",
"build-std=panic_abort,std",
"--",
"--nocapture",
]
dependencies = ["build_parallel_arkzkey"]
[tasks.bench]
disabled = true

View File

@@ -72,29 +72,16 @@ Compile zerokit for `wasm32-unknown-unknown`:
cargo make build
```
Or compile with the **arkzkey** feature enabled
```bash
cargo make build_arkzkey
```
## Running tests and benchmarks
```bash
cargo make test
```
Or test with the **arkzkey** feature enabled
```bash
cargo make test_arkzkey
```
If you want to run the tests in browser headless mode, you can use the following command:
```bash
cargo make test_browser
cargo make test_browser_arkzkey
```
## Parallel computation
@@ -128,12 +115,6 @@ To enable parallel computation for WebAssembly threads, you can use the followin
cargo make build_parallel
```
Or with the **arkzkey** feature enabled:
```bash
cargo make build_parallel_arkzkey
```
### WebAssembly Threading Support
Most modern browsers support WebAssembly threads,

View File

@@ -64,11 +64,8 @@ mod tests {
const WITNESS_CALCULATOR_JS: &str = include_str!("../resources/witness_calculator_browser.js");
#[cfg(feature = "arkzkey")]
const ZKEY_BYTES: &[u8] =
const ARKZKEY_BYTES: &[u8] =
include_bytes!("../../rln/resources/tree_height_20/rln_final.arkzkey");
#[cfg(not(feature = "arkzkey"))]
const ZKEY_BYTES: &[u8] = include_bytes!("../../rln/resources/tree_height_20/rln_final.zkey");
const CIRCOM_BYTES: &[u8] = include_bytes!("../../rln/resources/tree_height_20/rln.wasm");
@@ -98,7 +95,7 @@ mod tests {
let mut results = String::from("\nbenchmarks:\n");
let iterations = 10;
let zkey = readFile(&ZKEY_BYTES).expect("Failed to read zkey file");
let zkey = readFile(&ARKZKEY_BYTES).expect("Failed to read zkey file");
// Benchmark wasm_new
let start_wasm_new = Date::now();

View File

@@ -51,10 +51,7 @@ mod tests {
async fn calculateWitness(circom_path: &str, input: Object) -> Result<JsValue, JsValue>;
}
#[cfg(feature = "arkzkey")]
const ZKEY_PATH: &str = "../rln/resources/tree_height_20/rln_final.arkzkey";
#[cfg(not(feature = "arkzkey"))]
const ZKEY_PATH: &str = "../rln/resources/tree_height_20/rln_final.zkey";
const ARKZKEY_PATH: &str = "../rln/resources/tree_height_20/rln_final.arkzkey";
const CIRCOM_PATH: &str = "../rln/resources/tree_height_20/rln.wasm";
@@ -63,7 +60,7 @@ mod tests {
let mut results = String::from("\nbenchmarks:\n");
let iterations = 10;
let zkey = readFile(&ZKEY_PATH).expect("Failed to read zkey file");
let zkey = readFile(&ARKZKEY_PATH).expect("Failed to read zkey file");
// Benchmark wasm_new
let start_wasm_new = Date::now();