From 0c9fc07cfe0567e144dbc27bfb4b7ad0263048e4 Mon Sep 17 00:00:00 2001 From: Arseniy Klempner Date: Fri, 29 Mar 2024 11:58:51 -0700 Subject: [PATCH] add debug statements that appear in js console --- Cargo.lock | 30 ++++++++++++++++-------------- Cargo.toml | 1 + rln/Cargo.toml | 3 +++ rln/src/protocol.rs | 21 +++++++++++++++++++++ rln/src/public.rs | 4 ++++ 5 files changed, 45 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b45a23f..49ae890 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1919,9 +1919,9 @@ checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" [[package]] name = "js-sys" -version = "0.3.62" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68c16e1bfd491478ab155fd8b4896b86f9ede344949b641e61501e07c2b8b4d5" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" dependencies = [ "wasm-bindgen", ] @@ -2707,6 +2707,7 @@ dependencies = [ "ark-std 0.4.0", "cfg-if", "color-eyre 0.6.2", + "console_error_panic_hook", "criterion 0.4.0", "include_dir", "num-bigint", @@ -2720,6 +2721,7 @@ dependencies = [ "thiserror", "tiny-keccak", "wasmer", + "web-sys", "zerokit_utils", ] @@ -3543,9 +3545,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.85" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b6cb788c4e39112fbe1822277ef6fb3c55cd86b95cb3d3c4c1c9597e4ac74b4" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -3553,9 +3555,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.85" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35e522ed4105a9d626d885b35d62501b30d9666283a5c8be12c14a8bdafe7822" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" dependencies = [ "bumpalo", "log", @@ -3580,9 +3582,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.85" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "358a79a0cb89d21db8120cbfb91392335913e4890665b1a7981d9e956903b434" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3590,9 +3592,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.85" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4783ce29f09b9d93134d41297aded3a712b7b979e9c6f28c32cb88c973a94869" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", @@ -3603,9 +3605,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.85" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a901d592cafaa4d711bc324edfaff879ac700b19c3dfd60058d2b445be2691eb" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "wasm-bindgen-test" @@ -3995,9 +3997,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.62" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16b5f940c7edfdc6d12126d98c9ef4d1b3d470011c47c76a6581df47ad9ba721" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/Cargo.toml b/Cargo.toml index d056920..2f4846f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ opt-level = 3 [profile.release.package."rln-wasm"] # Tell `rustc` to optimize for small code size. opt-level = "s" +debug = true [profile.release.package."semaphore"] codegen-units = 1 diff --git a/rln/Cargo.toml b/rln/Cargo.toml index 378d596..b6ce22d 100644 --- a/rln/Cargo.toml +++ b/rln/Cargo.toml @@ -49,6 +49,9 @@ serde_json = "=1.0.96" serde = { version = "=1.0.163", features = ["derive"] } include_dir = "=0.7.3" +console_error_panic_hook = "0.1.7" +web-sys = { version = "0.3.69", features = ["console"] } + [dev-dependencies] sled = "=0.34.7" diff --git a/rln/src/protocol.rs b/rln/src/protocol.rs index f460fad..1fc1def 100644 --- a/rln/src/protocol.rs +++ b/rln/src/protocol.rs @@ -103,29 +103,50 @@ pub fn serialize_witness(rln_witness: &RLNWitnessInput) -> Result> { Ok(serialized) } +extern crate web_sys; + pub fn deserialize_witness(serialized: &[u8]) -> Result<(RLNWitnessInput, usize)> { let mut all_read: usize = 0; let (identity_secret, read) = bytes_le_to_fr(&serialized[all_read..]); all_read += read; + web_sys::console::log_1(&"Read identity secret".into()); + web_sys::console::log_1(&identity_secret.to_string().into()); + web_sys::console::log_1(&all_read.to_string().into()); let (path_elements, read) = bytes_le_to_vec_fr(&serialized[all_read..])?; all_read += read; + web_sys::console::log_1(&"Read path elements".into()); + web_sys::console::log_1(&format!("{:?}", path_elements).into()); + web_sys::console::log_1(&all_read.to_string().into()); let (identity_path_index, read) = bytes_le_to_vec_u8(&serialized[all_read..])?; all_read += read; + web_sys::console::log_1(&"Read identity path index".into()); + web_sys::console::log_1(&format!("{:?}", identity_path_index).into()); + web_sys::console::log_1(&all_read.to_string().into()); let (x, read) = bytes_le_to_fr(&serialized[all_read..]); all_read += read; + web_sys::console::log_1(&"Read x".into()); + web_sys::console::log_1(&x.to_string().into()); + web_sys::console::log_1(&all_read.to_string().into()); let (epoch, read) = bytes_le_to_fr(&serialized[all_read..]); all_read += read; + web_sys::console::log_1(&"Read epoch".into()); + web_sys::console::log_1(&epoch.to_string().into()); + web_sys::console::log_1(&all_read.to_string().into()); let (rln_identifier, read) = bytes_le_to_fr(&serialized[all_read..]); all_read += read; + web_sys::console::log_1(&"Read rln identifier".into()); + web_sys::console::log_1(&rln_identifier.to_string().into()); + web_sys::console::log_1(&all_read.to_string().into()); // TODO: check rln_identifier against public::RLN_IDENTIFIER if serialized.len() != all_read { + web_sys::console::log_1(&"serialized length is not equal to all_read".into()); return Err(Report::msg("serialized length is not equal to all_read")); } diff --git a/rln/src/public.rs b/rln/src/public.rs index 99a5b98..a38e6f2 100644 --- a/rln/src/public.rs +++ b/rln/src/public.rs @@ -14,6 +14,9 @@ use color_eyre::{Report, Result}; use num_bigint::BigInt; use std::io::Cursor; use utils::{ZerokitMerkleProof, ZerokitMerkleTree}; +extern crate console_error_panic_hook; +use std::panic; + cfg_if! { if #[cfg(not(target_arch = "wasm32"))] { @@ -1191,6 +1194,7 @@ impl RLN<'_> { /// /// The function returns the corresponding JSON encoding of the input [`RLNWitnessInput`](crate::protocol::RLNWitnessInput) object. pub fn get_rln_witness_json(&mut self, serialized_witness: &[u8]) -> Result { + panic::set_hook(Box::new(console_error_panic_hook::hook)); let (rln_witness, _) = deserialize_witness(serialized_witness)?; get_json_inputs(&rln_witness) }