From 942167287600f129e67643cc52889291314e504f Mon Sep 17 00:00:00 2001 From: Las Safin Date: Thu, 29 Jun 2023 23:34:04 +0000 Subject: [PATCH] Always call `console_error_panic_hook::set_once` and remove ad-hoc uses of it The WASM module now exports `console_error_panic_hook_set_once` which is an alias for `console_error_panic_hook::set_once` to be called from the JS side. It is always called when loading the module in the wrapper JS module. --- js/wrapper.js | 2 ++ kimchi/wasm/src/lib.rs | 5 +++++ kimchi/wasm/src/pasta_fp_plonk_index.rs | 1 - kimchi/wasm/src/pasta_fq_plonk_index.rs | 1 - kimchi/wasm/src/plonk_proof.rs | 1 - 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/js/wrapper.js b/js/wrapper.js index 50433a63..807490d0 100644 --- a/js/wrapper.js +++ b/js/wrapper.js @@ -5,6 +5,8 @@ export { getSnarky, getWasm, withThreadPool }; let getSnarky = () => snarky; +wasm.console_error_panic_hook_set_once(); + function getWasm() { return wasm; } diff --git a/kimchi/wasm/src/lib.rs b/kimchi/wasm/src/lib.rs index 93cb9387..6377ca2d 100644 --- a/kimchi/wasm/src/lib.rs +++ b/kimchi/wasm/src/lib.rs @@ -73,6 +73,11 @@ pub fn wait_until_non_zero(ptr: *const u32) -> u32 { unreachable!(); } +#[wasm_bindgen] +pub fn console_error_panic_hook_set_once() { + console_error_panic_hook::set_once(); +} + pub mod rayon; /// Arkworks types diff --git a/kimchi/wasm/src/pasta_fp_plonk_index.rs b/kimchi/wasm/src/pasta_fp_plonk_index.rs index 5b31ba33..13456061 100644 --- a/kimchi/wasm/src/pasta_fp_plonk_index.rs +++ b/kimchi/wasm/src/pasta_fp_plonk_index.rs @@ -33,7 +33,6 @@ pub fn caml_pasta_fp_plonk_index_create( prev_challenges: i32, srs: &WasmSrs, ) -> Result { - console_error_panic_hook::set_once(); let index = crate::rayon::run_in_pool(|| { // flatten the permutation information (because OCaml has a different way of keeping track of permutations) let gates: Vec<_> = gates diff --git a/kimchi/wasm/src/pasta_fq_plonk_index.rs b/kimchi/wasm/src/pasta_fq_plonk_index.rs index 0846a418..57cebe1b 100644 --- a/kimchi/wasm/src/pasta_fq_plonk_index.rs +++ b/kimchi/wasm/src/pasta_fq_plonk_index.rs @@ -33,7 +33,6 @@ pub fn caml_pasta_fq_plonk_index_create( prev_challenges: i32, srs: &WasmSrs, ) -> Result { - console_error_panic_hook::set_once(); let index = crate::rayon::run_in_pool(|| { // flatten the permutation information (because OCaml has a different way of keeping track of permutations) let gates: Vec<_> = gates diff --git a/kimchi/wasm/src/plonk_proof.rs b/kimchi/wasm/src/plonk_proof.rs index ee188918..6e1f4947 100644 --- a/kimchi/wasm/src/plonk_proof.rs +++ b/kimchi/wasm/src/plonk_proof.rs @@ -552,7 +552,6 @@ macro_rules! impl_proof { prev_challenges: WasmFlatVector<$WasmF>, prev_sgs: WasmVector<$WasmG>, ) -> Result { - console_error_panic_hook::set_once(); let (maybe_proof, public_input) = crate::rayon::run_in_pool(|| { { let ptr: &mut poly_commitment::srs::SRS<$G> =