Skip to content

Commit

Permalink
feat: add unit tests for halo2-wasm (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
rpalakkal authored Nov 8, 2023
1 parent b7914db commit 5f67a3b
Show file tree
Hide file tree
Showing 14 changed files with 678 additions and 9 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/halo2-wasm-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: halo2-wasm Tests

on:
push:
paths:
- "halo2-wasm/**"

defaults:
run:
working-directory: halo2-wasm

jobs:
halo2-wasm-tests:
runs-on: ubuntu-latest-64core-256ram
steps:
- uses: actions/checkout@v3
- name: Build
run: |
rustup toolchain install nightly-2023-08-12-x86_64-unknown-linux-gnu
rustup component add rust-src --toolchain nightly-2023-08-12-x86_64-unknown-linux-gnu
cargo build --target=x86_64-unknown-linux-gnu --verbose
- name: Test
run: cargo test --target=x86_64-unknown-linux-gnu
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
target
Cargo.lock
Cargo.lock
.DS_Store
31 changes: 30 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
[workspace]
members = ["halo2-wasm"]
resolver = "2"
resolver = "2"

[profile.dev]
opt-level = 3
debug = 2 # change to 0 or 2 for more or less debug info
overflow-checks = true
incremental = true

# Local "release" mode, more optimized than dev but faster to compile than release
[profile.local]
inherits = "dev"
opt-level = 3
# Set this to 1 or 2 to get more useful backtraces
debug = 1
debug-assertions = false
panic = 'unwind'
# better recompile times
incremental = true
lto = "thin"
codegen-units = 16

[profile.release]
opt-level = 3
debug = false
debug-assertions = false
lto = "fat"
# `codegen-units = 1` can lead to WORSE performance - always bench to find best profile for your machine!
# codegen-units = 1
panic = "unwind"
incremental = false
2 changes: 1 addition & 1 deletion halo2-wasm/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ rustflags = ["-C", "target-feature=+atomics,+bulk-memory,+mutable-globals", "-C"
build-std = ["panic_abort", "std"]

[build]
target = "wasm32-unknown-unknown"
target = "aarch64-apple-darwin"
1 change: 1 addition & 0 deletions halo2-wasm/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ pkg
dist
.vscode
node_modules
*.bin
1 change: 1 addition & 0 deletions halo2-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ tsify = "0.4.5"
num-bigint = "0.4"
num-traits = "0.2"
num-integer = "0.1.45"
paste = "1.0.14"

[target.'cfg(target_family = "wasm")'.dependencies]
wasm-bindgen-rayon = { version = "1.0" }
Expand Down
Binary file added halo2-wasm/params/kzg_bn254_10.srs
Binary file not shown.
2 changes: 1 addition & 1 deletion halo2-wasm/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ Coming soon!

## Acknowledgements

This work would not be possible without [Nalin's](https://twitter.com/nibnalin) guide on using raw halo2 in WASM. Check out his guide [here](https://zcash.github.io/halo2/user/wasm-port.html).
This work would not be possible without [Nalin's](https://twitter.com/nibnalin) guide on using raw halo2 in WASM. Check out his guide [here](https://zcash.github.io/halo2/user/wasm-port.html).
10 changes: 5 additions & 5 deletions halo2-wasm/src/halo2lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ use crate::Halo2Wasm;

pub mod ecc;

const T: usize = 3;
const RATE: usize = 2;
const R_F: usize = 8;
const R_P: usize = 57;
const SECURE_MDS: usize = 0;
pub const T: usize = 3;
pub const RATE: usize = 2;
pub const R_F: usize = 8;
pub const R_P: usize = 57;
pub const SECURE_MDS: usize = 0;
type Fr = ecc::Bn254Fr;
// TODO: use wasm_bindgen to sync with js CircuitValue type
type JsCircuitValue = usize;
Expand Down
3 changes: 3 additions & 0 deletions halo2-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ pub use wasm_bindgen_rayon::init_thread_pool;
pub mod halo2lib;
mod vkey;

#[cfg(test)]
pub mod tests;

use vkey::{write_partial_vkey, PartialVerifyingKey};

#[wasm_bindgen]
Expand Down
Loading

0 comments on commit 5f67a3b

Please sign in to comment.