diff --git a/Cargo.lock b/Cargo.lock index 65c4a0562e..d7412d3b9e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2857,6 +2857,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-test", "wasm-types", + "web-sys", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 87a9dd71ae..3bb70e4db1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,6 +56,7 @@ hex = { version = "0.4", features = ["serde"] } iai = "0.1" itertools = "0.12.1" js-sys = "=0.3.64" +web-sys = { version = "0.3.64", features = ["DedicatedWorkerGlobalScope", "console","MessageEvent"] } libc = "=0.2.169" libflate = "2" log = "0.4.20" diff --git a/plonk-wasm/Cargo.toml b/plonk-wasm/Cargo.toml index 79bfc2b225..34b830ed8c 100644 --- a/plonk-wasm/Cargo.toml +++ b/plonk-wasm/Cargo.toml @@ -18,6 +18,7 @@ base64.workspace = true console_error_panic_hook.workspace = true getrandom = { workspace = true, features = ["js"] } js-sys.workspace = true +web-sys.workspace = true libc.workspace = true num-bigint.workspace = true once_cell.workspace = true diff --git a/plonk-wasm/src/lib.rs b/plonk-wasm/src/lib.rs index e62068ba94..763349a05c 100644 --- a/plonk-wasm/src/lib.rs +++ b/plonk-wasm/src/lib.rs @@ -11,6 +11,25 @@ use wasm_bindgen::prelude::*; mod wasm_vector; +use wasm_bindgen::JsValue; + +use wasm_bindgen::JsCast; +use web_sys; + +fn send_message_from_worker(msg: &JsValue) { + // TODO: Use a more structured approach and msg format + // also TODO: ideally use worker communication - look into how web_sys does it + // right now this looks to the console right away, which is cool, but having actual worker comms is more useful + web_sys::console::log_1(msg); + postMessageToMain(msg); +} + +#[wasm_bindgen] +extern "C" { + #[wasm_bindgen(js_name = postMessage)] + fn postMessageToMain(data: &JsValue); +} + #[wasm_bindgen] extern "C" { pub fn alert(s: &str); diff --git a/plonk-wasm/src/pasta_fp_plonk_index.rs b/plonk-wasm/src/pasta_fp_plonk_index.rs index b56347c23f..af2b33b019 100644 --- a/plonk-wasm/src/pasta_fp_plonk_index.rs +++ b/plonk-wasm/src/pasta_fp_plonk_index.rs @@ -111,7 +111,16 @@ pub fn caml_pasta_fp_plonk_index_create( lazy_mode: bool, ) -> Result { console_error_panic_hook::set_once(); - let index = crate::rayon::run_in_pool(|| { + super::send_message_from_worker(&JsValue::from_str("hello from Rayon thread!")); + let index: Result< + ProverIndex< + ark_ec::short_weierstrass::Affine, + OpeningProof>, + >, + &str, + > = crate::rayon::run_in_pool(|| { + super::send_message_from_worker(&JsValue::from_str("hello from Rayon worker!")); + // flatten the permutation information (because OCaml has a different way of keeping track of permutations) let gates: Vec<_> = gates .0 @@ -123,6 +132,12 @@ pub fn caml_pasta_fp_plonk_index_create( }) .collect(); + super::send_message_from_worker(&JsValue::from_str("hello from Rayon again!")); + super::send_message_from_worker(&JsValue::from_str(&format!( + "logging something from rayon {:?}", + gates[0].typ + ))); + let rust_runtime_table_cfgs: Vec> = runtime_table_cfgs.into_iter().map(Into::into).collect(); @@ -160,6 +175,7 @@ pub fn caml_pasta_fp_plonk_index_create( srs.0.clone(), lazy_mode, ); + // Compute and cache the verifier index digest index.compute_verifier_index_digest::>(); Ok(index)