Compare commits

...

9 Commits

Author SHA1 Message Date
Rahul Ghangas
936b7fc3cb test: add helper function to wrap init 2023-02-24 11:56:01 +05:30
Rahul Ghangas
cf7e2de380 test: call init and init_thread_pool before tests start 2023-02-24 11:55:46 +05:30
Rahul Ghangas
4fbb1525ea chore: use browser for testing, since node is not supported 2023-02-24 11:54:44 +05:30
Rahul Ghangas
a7f6d63060 chore: add new line at the end of rust-toolchain file 2023-02-02 01:07:08 +05:30
Rahul Ghangas
95f895c64c feat: target toolchain and add rustflags 2023-02-02 01:03:48 +05:30
Rahul Ghangas
228ccba90a chore: remove unused dependency in rln that's causing wasm issues 2023-02-02 01:02:16 +05:30
Rahul Ghangas
e04fa2c7a5 feat: rexport init_thread_pool 2023-02-02 01:01:50 +05:30
Rahul Ghangas
6539bb4d5e chore: enable parallel feature for rln 2023-02-02 00:59:32 +05:30
Rahul Ghangas
5394050c0b chore: add wasm rayon for threading 2023-02-02 00:58:46 +05:30
8 changed files with 31 additions and 9 deletions

5
rln-wasm/.cargo/config Normal file
View File

@@ -0,0 +1,5 @@
[target.wasm32-unknown-unknown]
rustflags = ["-C", "target-feature=+atomics,+bulk-memory,+mutable-globals"]
[unstable]
build-std = ["panic_abort", "std"]

View File

@@ -11,12 +11,13 @@ crate-type = ["cdylib", "rlib"]
default = ["console_error_panic_hook"]
[dependencies]
rln = { path = "../rln", default-features = false, features = ["wasm"] }
rln = { path = "../rln", default-features = false, features = ["wasm", "parallel"] }
num-bigint = { version = "0.4", default-features = false, features = ["rand", "serde"] }
wasmer = { version = "2.3", default-features = false, features = ["js", "std"] }
wasmer = { version = "3.1.1", default-features = false, features = ["js", "std"] }
web-sys = {version = "0.3", features=["console"]}
getrandom = { version = "0.2.7", default-features = false, features = ["js"] }
wasm-bindgen = "0.2.63"
wasm-bindgen-rayon = "1.0.3"
serde-wasm-bindgen = "0.4"
js-sys = "0.3.59"
serde_json = "1.0.85"

View File

@@ -14,7 +14,7 @@ dependencies = [
[tasks.test]
command = "wasm-pack"
args = ["test", "--release", "--node"]
args = ["test", "--release", "--firefox", "--headless"]
dependencies = ["build"]
[tasks.login]

1
rln-wasm/rust-toolchain Normal file
View File

@@ -0,0 +1 @@
nightly-2022-12-12

View File

@@ -8,6 +8,8 @@ use num_bigint::BigInt;
use rln::public::RLN;
use wasm_bindgen::prelude::*;
pub use wasm_bindgen_rayon::init_thread_pool;
#[wasm_bindgen]
pub fn init_panic_hook() {
console_error_panic_hook::set_once();

View File

@@ -1,4 +1,5 @@
const fs = require("fs");
const rln_wasm = require("/pkg/rln_wasm.js");
// Utils functions for loading circom witness calculator and reading files from test
@@ -7,8 +8,12 @@ module.exports = {
return fs.readFileSync(path);
},
calculateWitness: async function(circom_path, inputs){
const wc = require("resources/witness_calculator.js");
initWasm: async function() {
await rln_wasm();
},
calculateWitness: async function(circom_path, inputs) {
const wc = require("/resources/witness_calculator.js");
const wasmFile = fs.readFileSync(circom_path);
const wasmFileBuffer = wasmFile.slice(wasmFile.byteOffset, wasmFile.byteOffset + wasmFile.byteLength);
const witnessCalculator = await wc(wasmFileBuffer);

View File

@@ -8,18 +8,27 @@ mod tests {
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsValue;
use wasm_bindgen_test::wasm_bindgen_test;
use wasm_bindgen_rayon::init_thread_pool;
#[wasm_bindgen(module = "src/utils.js")]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
#[wasm_bindgen(module = "/src/utils.js")]
extern "C" {
#[wasm_bindgen(catch)]
fn read_file(path: &str) -> Result<Uint8Array, JsValue>;
#[wasm_bindgen(catch)]
async fn calculateWitness(circom_path: &str, input: Object) -> Result<JsValue, JsValue>;
async fn initWasm() -> Result<(), JsValue>;
#[wasm_bindgen(catch)]
async fn calculateWitness(circom_path: &str, inputs: Object) -> Result<JsValue, JsValue>;
}
#[wasm_bindgen_test]
pub async fn test_basic_flow() {
initWasm().await.unwrap();
wasm_bindgen_futures::JsFuture::from(init_thread_pool(4)).await.unwrap();
let tree_height = TEST_TREE_HEIGHT;
let circom_path = format!("../rln/resources/tree_height_{TEST_TREE_HEIGHT}/rln.wasm");
let zkey_path = format!("../rln/resources/tree_height_{TEST_TREE_HEIGHT}/rln_final.zkey");

View File

@@ -37,14 +37,13 @@ once_cell = "1.14.0"
rand = "0.8"
rand_chacha = "0.3.1"
tiny-keccak = { version = "2.0.2", features = ["keccak"] }
utils = { path = "../utils/", default-features = false }
utils = { path = "../utils", default-features = false }
# serialization
serde_json = "1.0.48"
[dev-dependencies]
pmtree = { git = "https://github.com/Rate-Limiting-Nullifier/pmtree" }
sled = "0.34.7"
[features]
default = ["parallel", "wasmer/sys-default"]