From fbdd11abc940ed71620174d895a4d6b18b220865 Mon Sep 17 00:00:00 2001 From: Daniel Gorgonha Date: Mon, 9 Nov 2026 18:28:09 -0300 Subject: [PATCH 1/6] build: make multicore opt-in per crate instead of forced by the workspace zcash_primitives, zcash_proofs and zcash_client_memory pulled `multicore` (rayon) through their default features or a hard-set feature, so no crate could switch it off. Take them without it at the workspace level and add a `multicore` feature to webzjs-common and webzjs-keys (default on). webzjs-requests and `just build-keys` ask for it explicitly, so those builds resolve the same third-party features as before. Assisted-by: Claude Code --- Cargo.toml | 8 +++++--- crates/webzjs-common/Cargo.toml | 4 ++++ crates/webzjs-keys/Cargo.toml | 6 +++++- crates/webzjs-requests/Cargo.toml | 2 +- justfile | 2 +- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 291f784..591b89a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,11 +38,13 @@ tokio_with_wasm = { version = "0.7.1", features = ["rt", "rt-multi-thread", "syn ## `cargo update` can't silently move it. For local store work, swap it to `{ path = "../zcash_client_memory" }`. zcash_keys = { version = "=0.17.0", features = ["transparent-inputs", "orchard", "sapling", "unstable"] } zcash_client_backend = { version = "=0.25.0", default-features = false, features = ["sync", "lightwalletd-tonic", "orchard", "zeroize"] } -zcash_client_memory = { git = "https://github.com/red-dev-inc/zcash_client_memory", rev = "b4c8f0d33c65c5bab4155ddeba4f201ea2d28c43", features = ["orchard", "transparent-inputs"] } -zcash_primitives = { version = "=0.31.0" } +zcash_client_memory = { git = "https://github.com/red-dev-inc/zcash_client_memory", rev = "b4c8f0d33c65c5bab4155ddeba4f201ea2d28c43", default-features = false, features = ["orchard", "transparent-inputs"] } +## `multicore` (rayon) is off here and switched on per crate through each crate's own `multicore` feature, +## so a `no-threads` build does not get it back through feature unification. +zcash_primitives = { version = "=0.31.0", default-features = false, features = ["std", "circuits"] } zcash_transparent = { version = "=0.11.0", default-features = false } zcash_address = { version = "=0.14.0" } -zcash_proofs = { version = "=0.31.0", default-features = false, features = ["bundled-prover", "multicore"] } +zcash_proofs = { version = "=0.31.0", default-features = false, features = ["bundled-prover"] } zip321 = { version = "=0.10.0" } zip32 = { version = "0.3" } zcash_protocol = { version = "=0.11.0", default-features = false } diff --git a/crates/webzjs-common/Cargo.toml b/crates/webzjs-common/Cargo.toml index bf9a370..0f784b1 100644 --- a/crates/webzjs-common/Cargo.toml +++ b/crates/webzjs-common/Cargo.toml @@ -18,6 +18,10 @@ js-sys.workspace = true pczt = { workspace = true, default-features = false, features = ["orchard", "sapling", "transparent"] } serde-wasm-bindgen.workspace = true +[features] +default = ["multicore"] +# rayon-backed proving/scanning in zcash_primitives. Off in the `no-threads` wallet build. +multicore = ["zcash_primitives/multicore"] [lints] workspace = true \ No newline at end of file diff --git a/crates/webzjs-keys/Cargo.toml b/crates/webzjs-keys/Cargo.toml index 25e0add..95ba4d3 100644 --- a/crates/webzjs-keys/Cargo.toml +++ b/crates/webzjs-keys/Cargo.toml @@ -14,7 +14,7 @@ crate-type = ["cdylib", "rlib"] wasm-opt = ["-O4", "-O4"] [dependencies] -webzjs-common = { path = "../webzjs-common" } +webzjs-common = { path = "../webzjs-common", default-features = false } js-sys.workspace = true thiserror.workspace = true @@ -50,6 +50,10 @@ getrandom04.workspace = true rand10.workspace = true [features] +default = ["multicore"] +# rayon-backed proving/scanning in zcash_primitives. Off in the `no-threads` wallet build. +multicore = ["zcash_primitives/multicore", "webzjs-common/multicore"] + # Exposes `build_owned_demo_pczts` (src/demo_pczt.rs) — used only by the PoC demo # to construct per-pool sample PCZTs attributable to a given UFVK. Pulls the # transaction builders (`pczt/zcp-builder`) into the wasm build. diff --git a/crates/webzjs-requests/Cargo.toml b/crates/webzjs-requests/Cargo.toml index ec6eaa2..5ad1c0f 100644 --- a/crates/webzjs-requests/Cargo.toml +++ b/crates/webzjs-requests/Cargo.toml @@ -18,7 +18,7 @@ wasm-bindgen.workspace = true js-sys.workspace = true zcash_protocol.workspace = true zcash_address.workspace = true -zcash_primitives.workspace = true +zcash_primitives = { workspace = true, features = ["multicore"] } zip321.workspace = true thiserror.workspace = true serde-wasm-bindgen.workspace = true diff --git a/justfile b/justfile index d972dcb..6a92587 100644 --- a/justfile +++ b/justfile @@ -11,7 +11,7 @@ build-wallet *features: ./add-worker-module.sh build-keys *features: - cd crates/webzjs-keys && wasm-pack build -t web --release --scope zcashcommunitygrants --out-dir ../../packages/webzjs-keys --no-default-features --features="{{features}}" -Z build-std="panic_abort,std" + cd crates/webzjs-keys && wasm-pack build -t web --release --scope zcashcommunitygrants --out-dir ../../packages/webzjs-keys --no-default-features --features="multicore {{features}}" -Z build-std="panic_abort,std" build-requests *features: cd crates/webzjs-requests && wasm-pack build -t web --release --scope zcashcommunitygrants --out-dir ../../packages/webzjs-requests --no-default-features --features="{{features}}" -Z build-std="panic_abort,std" From 8f738d3de1921e7bfe2abc171c301b766396693f Mon Sep 17 00:00:00 2001 From: Daniel Gorgonha Date: Mon, 9 Nov 2026 18:28:23 -0300 Subject: [PATCH 2/6] feat(wallet): add an opt-in `no-threads` feature `no-threads` builds the wasm wallet without wasm_thread, the rayon pool and wasm-bindgen-rayon, so it needs no SharedArrayBuffer. `sync` and `create_proposed_transactions` then run in the caller's context instead of a spawned worker. The `wasm-parallel` build keeps the same code path as before. - `multicore` now forwards to webzjs-keys and webzjs-common, and no longer rides on the zcash_proofs dependency line. - `wasm_thread` and `rayon` are optional and enabled by `wasm-parallel` only. - `no-threads` and `wasm-parallel` together fail with `compile_error!`. Assisted-by: Claude Code --- crates/webzjs-wallet/Cargo.toml | 25 ++++++--- crates/webzjs-wallet/src/bindgen/wallet.rs | 61 ++++++++++++++++++++++ crates/webzjs-wallet/src/lib.rs | 3 ++ 3 files changed, 81 insertions(+), 8 deletions(-) diff --git a/crates/webzjs-wallet/Cargo.toml b/crates/webzjs-wallet/Cargo.toml index fdec6b6..ceb90ff 100644 --- a/crates/webzjs-wallet/Cargo.toml +++ b/crates/webzjs-wallet/Cargo.toml @@ -16,19 +16,28 @@ wasm-opt = ["-O4", "-O4"] [features] default = ["native", "multicore"] -multicore = ["zcash_proofs/multicore", "zcash_primitives/multicore", "zcash_client_memory/multicore"] +multicore = [ + "zcash_proofs/multicore", + "zcash_primitives/multicore", + "zcash_client_memory/multicore", + "webzjs-keys/multicore", + "webzjs-common/multicore", +] # WASM specific features wasm = ["console_error_panic_hook", "dep:tracing-web"] -wasm-parallel = ["wasm", "wasm-bindgen-rayon", "multicore"] +wasm-parallel = ["wasm", "wasm-bindgen-rayon", "dep:wasm_thread", "dep:rayon", "multicore"] +# Single-threaded wasm build: no SharedArrayBuffer, no wasm_thread, no rayon pool, so the page needs no +# COOP/COEP headers. Build with `just build-wallet-single`. Mutually exclusive with `wasm-parallel`. +no-threads = ["wasm"] native = ["tonic/channel", "tonic/gzip", "tonic/tls-webpki-roots", "tokio/macros", "tokio/rt", "tokio/rt-multi-thread"] sqlite-db = ["dep:zcash_client_sqlite"] console_error_panic_hook = ["dep:console_error_panic_hook"] -no-bundler = ["wasm-bindgen-rayon?/no-bundler", "wasm_thread/no-bundler"] +no-bundler = ["wasm-bindgen-rayon?/no-bundler", "wasm_thread?/no-bundler"] [dependencies] -webzjs-common = { path = "../webzjs-common" } -webzjs-keys = { path = "../webzjs-keys" } +webzjs-common = { path = "../webzjs-common", default-features = false } +webzjs-keys = { path = "../webzjs-keys", default-features = false } ## Web dependencies wasm-bindgen.workspace = true js-sys.workspace = true @@ -60,7 +69,7 @@ zcash_client_memory = { workspace = true, features = ["orchard", "transparent-in zcash_primitives = { workspace = true } zcash_address = { workspace = true } zcash_protocol = { workspace = true, default-features = false } -zcash_proofs = { workspace = true, default-features = false, features = ["bundled-prover", "multicore"] } +zcash_proofs = { workspace = true, default-features = false, features = ["bundled-prover"] } zip321 = { workspace = true } zip32 = { workspace = true } pczt = { workspace = true, default-features = false, features = ["orchard", "sapling", "transparent"] } @@ -89,12 +98,12 @@ nonempty = "0.11" hex = "0.4.3" tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } tracing = "0.1.40" -rayon = { version = "1.8", features = ["web_spin_lock"] } +rayon = { version = "1.8", features = ["web_spin_lock"], optional = true } subtle = "2.6.1" wasm_thread = { git = "https://github.com/ec2/wasm_thread", rev = "9e432077948d927d49373d1d039c23447d3648df", default-features = false, features = [ "keep_worker_alive", "es_modules", -] } +], optional = true } wasm_sync = "0.1.2" http = { version = "1.1.0", default-features = false } diff --git a/crates/webzjs-wallet/src/bindgen/wallet.rs b/crates/webzjs-wallet/src/bindgen/wallet.rs index 599dd8a..ade49f6 100644 --- a/crates/webzjs-wallet/src/bindgen/wallet.rs +++ b/crates/webzjs-wallet/src/bindgen/wallet.rs @@ -11,6 +11,7 @@ use crate::validation::validate_confirmations_policy; use crate::wallet::usk_from_seed_str; use crate::{bindgen::proposal::Proposal, Wallet, PRUNING_DEPTH}; use futures_util::TryStreamExt; +#[cfg(feature = "wasm-parallel")] use wasm_thread as thread; use webzjs_common::{Network, Pczt}; use webzjs_keys::{ProofGenerationKey, SeedFingerprint}; @@ -265,12 +266,29 @@ impl WebWallet { .map(|id| *id) } + /// + /// Start a background sync task which will fetch and scan blocks from the connected lighwalletd server + /// + /// IMPORTANT: This build has no threads, so no worker is spawned: the sync runs in the context of the caller + /// until it completes. Host the `WebWallet` in your own dedicated Worker to keep the page responsive. + /// Certain wallet methods may temporarily block while the wallet is being written to during the sync. + /// + #[cfg(not(feature = "wasm-parallel"))] + pub async fn sync(&self) -> Result<(), Error> { + self.inner.clone().sync().await.map_err(|e| { + let err_string = e.to_string(); + tracing::warn!("Sync error (will be retried by caller): {}", err_string); + Error::Sync(err_string) + }) + } + /// /// Start a background sync task which will fetch and scan blocks from the connected lighwalletd server /// /// IMPORTANT: This will spawn a new webworker which will handle the sync task. The sync task will continue to run in the background until the sync process is complete. /// During this time the main thread will not block but certain wallet methods may temporarily block while the wallet is being written to during the sync. /// + #[cfg(feature = "wasm-parallel")] pub async fn sync(&self) -> Result<(), Error> { assert!(!thread::is_web_worker_thread()); @@ -345,6 +363,48 @@ impl WebWallet { Ok(proposal.into()) } + /// Generate a valid Zcash transaction from a given proposal + /// + /// IMPORTANT: This build has no threads, so no worker is spawned: the proving task runs in the context of the caller and may take 10s of seconds. + /// Host the `WebWallet` in your own dedicated Worker to keep the page responsive. + /// + /// # Arguments + /// + /// * `proposal` - A proposal object generated by `propose_transfer` + /// * `seed_phrase` - 24 word mnemonic seed phrase. This MUST correspond to the accountID used when creating the proposal. + /// * `account_hd_index` - [ZIP32](https://zips.z.cash/zip-0032) hierarchical deterministic index of the account. This MUST correspond to the accountID used when creating the proposal. + /// + /// # Returns + /// + /// A list of transaction IDs which can be used to track the status of the transaction on the network. + /// It is returned in a flattened form where each ID is 32 bytes. + /// The transactions themselves are stored within the wallet. + /// + /// # Examples + /// + /// ```javascript + /// const proposal = await wallet.propose_transfer(1, "u18rakpts0de589sx9dkamcjms3apruqqax9k2s6e7zjxx9vv5kc67pks2trg9d3nrgd5acu8w8arzjjuepakjx38dyxl6ahd948w0mhdt9jxqsntan6px3ysz80s04a87pheg2mqvlzpehrgup7568nfd6ez23xd69ley7802dfvplnfn7c07vlyumcnfjul4pvv630ac336rjhjyak5", 100000000); + /// const authorized_txns = await wallet.create_proposed_transactions(proposal, "...", 1); + /// ``` + #[cfg(not(feature = "wasm-parallel"))] + pub async fn create_proposed_transactions( + &self, + proposal: Proposal, + seed_phrase: &str, + account_hd_index: u32, + ) -> Result, Error> { + let (usk, _) = usk_from_seed_str(seed_phrase, account_hd_index, &self.inner.network)?; + let db = self.inner.clone(); + + let txids = db + .create_proposed_transactions(proposal.into(), &usk) + .await + .unwrap_throw(); + + let flattened_txid_bytes = txids.iter().flat_map(|&x| x.as_ref().clone()).collect(); + Ok(flattened_txid_bytes) + } + /// Generate a valid Zcash transaction from a given proposal /// /// IMPORTANT: This will spawn a new webworker which will handle the proving task which may take 10s of seconds @@ -367,6 +427,7 @@ impl WebWallet { /// const proposal = await wallet.propose_transfer(1, "u18rakpts0de589sx9dkamcjms3apruqqax9k2s6e7zjxx9vv5kc67pks2trg9d3nrgd5acu8w8arzjjuepakjx38dyxl6ahd948w0mhdt9jxqsntan6px3ysz80s04a87pheg2mqvlzpehrgup7568nfd6ez23xd69ley7802dfvplnfn7c07vlyumcnfjul4pvv630ac336rjhjyak5", 100000000); /// const authorized_txns = await wallet.create_proposed_transactions(proposal, "...", 1); /// ``` + #[cfg(feature = "wasm-parallel")] pub async fn create_proposed_transactions( &self, proposal: Proposal, diff --git a/crates/webzjs-wallet/src/lib.rs b/crates/webzjs-wallet/src/lib.rs index f07a35c..b7c5604 100644 --- a/crates/webzjs-wallet/src/lib.rs +++ b/crates/webzjs-wallet/src/lib.rs @@ -3,6 +3,9 @@ //! This is the top level documentation! +#[cfg(all(feature = "no-threads", feature = "wasm-parallel"))] +compile_error!("features `no-threads` and `wasm-parallel` are mutually exclusive"); + #[cfg(feature = "wasm")] pub mod bindgen; From 92b91d407962735395639320c372c9af4f83e47c Mon Sep 17 00:00:00 2001 From: Daniel Gorgonha Date: Mon, 9 Nov 2026 18:28:23 -0300 Subject: [PATCH 3/6] build: add `just build-wallet-single` and a no-threads check `build-wallet-single` builds the `no-threads` flavour with RUSTFLAGS="" (so the atomics flags in .cargo/config.toml are not applied), without -Z build-std and without add-worker-module.sh. `scripts/check-no-threads.sh` fails if the no-threads graph has wasm_thread, wasm-bindgen-rayon or any multicore/threads feature, and, given a built .wasm, if it has shared memory or atomics. CI runs the graph part. Assisted-by: Claude Code --- .github/workflows/rust-checks.yml | 12 +++++++++++ README.md | 8 +++++++ justfile | 10 +++++++++ scripts/check-no-threads.sh | 36 +++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100755 scripts/check-no-threads.sh diff --git a/.github/workflows/rust-checks.yml b/.github/workflows/rust-checks.yml index 0e08f51..fc04471 100644 --- a/.github/workflows/rust-checks.yml +++ b/.github/workflows/rust-checks.yml @@ -37,3 +37,15 @@ jobs: with: command: clippy args: --all --lib -- -D warnings -A deprecated -A unused-variables -A unused-imports + + no-threads: + runs-on: ubuntu-24.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install Rust toolchain + uses: ./.github/actions/install-rust-toolchain + + - name: Check the no-threads feature graph + run: ./scripts/check-no-threads.sh diff --git a/README.md b/README.md index 38a2a20..f1ac32e 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,14 @@ This just script uses wasm-pack to build a web-ready copy of `webzjs-wallet` and just build ``` +#### Building without threads + +`just build-wallet-single` builds `webzjs-wallet` into `packages/webzjs-wallet-single` with the `no-threads` feature. That build needs no +`SharedArrayBuffer`, so the page does not need the `Cross-Origin-Opener-Policy` / `Cross-Origin-Embedder-Policy` headers. `sync` and +`create_proposed_transactions` then run in the caller's context instead of a spawned worker, so host the `WebWallet` in your own dedicated +Worker to keep the page responsive. `just check-no-threads [file.wasm]` checks the feature graph and, given a built `.wasm`, that it has +no shared memory and no atomics. The default `just build` is unchanged. + #### Prerequisites [Install yarn](https://yarnpkg.com/getting-started/install) diff --git a/justfile b/justfile index 6a92587..e3fe47e 100644 --- a/justfile +++ b/justfile @@ -10,6 +10,16 @@ build-wallet *features: cd crates/webzjs-wallet && wasm-pack build -t web --release --scope zcashcommunitygrants --out-dir ../../packages/webzjs-wallet --no-default-features --features="wasm wasm-parallel {{features}}" -Z build-std="panic_abort,std" ./add-worker-module.sh +# Single-threaded wallet: no SharedArrayBuffer, so the page needs no COOP/COEP headers. +# RUSTFLAGS="" overrides the atomics flags of .cargo/config.toml; no -Z build-std is needed. +# add-worker-module.sh is not run: there is no wasm_thread snippet in this flavour. +build-wallet-single *features: + cd crates/webzjs-wallet && RUSTFLAGS="" wasm-pack build -t web --release --scope zcashcommunitygrants --out-dir ../../packages/webzjs-wallet-single --no-default-features --features="wasm no-threads {{features}}" + +# Checks the no-threads feature graph; pass a built .wasm to also check for shared memory and atomics. +check-no-threads *wasm: + ./scripts/check-no-threads.sh {{wasm}} + build-keys *features: cd crates/webzjs-keys && wasm-pack build -t web --release --scope zcashcommunitygrants --out-dir ../../packages/webzjs-keys --no-default-features --features="multicore {{features}}" -Z build-std="panic_abort,std" diff --git a/scripts/check-no-threads.sh b/scripts/check-no-threads.sh new file mode 100755 index 0000000..5164200 --- /dev/null +++ b/scripts/check-no-threads.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +# Checks that the `no-threads` flavour of webzjs-wallet needs no threads. +# +# scripts/check-no-threads.sh feature graph only (no build needed) +# scripts/check-no-threads.sh also inspects a built wasm (needs `wasm-tools`) +# +# Graph: with `wasm no-threads`, wasm_thread and wasm-bindgen-rayon are not in the dependency graph and no +# crate enables a thread-pool feature (multicore, threads, web_spin_lock, rayon). +# (The rayon crate itself stays: zcash_client_backend depends on it unconditionally.) +# Wasm: no shared memory and no atomic instructions, so the module needs no SharedArrayBuffer. +set -euo pipefail + +wasm="" +[ "$#" -ge 1 ] && wasm=$(realpath "$1") +cd "$(dirname "$0")/../crates/webzjs-wallet" +fail=0 +tree() { cargo tree ${CARGO_TREE_FLAGS:-} --target wasm32-unknown-unknown --no-default-features --features "${FEATURES:-wasm no-threads}" -e features "$@"; } + +tree >/dev/null || { echo "FAIL: cannot resolve the graph with features 'wasm no-threads'"; exit 1; } + +for pkg in wasm_thread wasm-bindgen-rayon; do + if tree -i "$pkg" >/dev/null 2>&1; then echo "FAIL: $pkg is in the no-threads graph"; fail=1; fi +done +# No crate may switch on a thread-pool feature (multicore, maybe-rayon/threads, rayon/web_spin_lock, ...). +bad=$(tree --prefix none | grep -E ' feature "(multicore|threads|web_spin_lock|rayon)"' | sort -u || true) +if [ -n "$bad" ]; then echo "FAIL: thread features enabled:"; echo "$bad"; fail=1; fi + +if [ "$#" -ge 1 ]; then + command -v wasm-tools >/dev/null || { echo "FAIL: wasm-tools not installed"; exit 1; } + text=$(wasm-tools print "$wasm") + if grep -Eq '\(memory .* shared\)' <<<"$text"; then echo "FAIL: shared memory in $wasm"; fail=1; fi + if grep -Eq '(^|[[:space:]])(memory\.atomic\.|[a-z0-9]+\.atomic\.)' <<<"$text"; then echo "FAIL: atomic instructions in $wasm"; fail=1; fi +fi + +[ "$fail" -eq 0 ] && echo "OK: no-threads checks passed" +exit "$fail" From f13bccb0f18cef65023b4d981dcb6adc7cd4e476 Mon Sep 17 00:00:00 2001 From: Daniel Gorgonha Date: Mon, 9 Nov 2026 23:03:54 -0300 Subject: [PATCH 4/6] fix(wallet): return create_proposed_transactions errors in the no-threads build The no-threads path used unwrap_throw, so a failure became a raw JS throw that skips destructors and loses the error. Use `?` like the rest of the file, so the caller gets the same Err as in the threaded build. Also say in the WebWallet and sync docs that the no-threads build runs in the caller's context and cannot report a panic as an Error. Assisted-by: Claude Code --- crates/webzjs-wallet/src/bindgen/wallet.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/webzjs-wallet/src/bindgen/wallet.rs b/crates/webzjs-wallet/src/bindgen/wallet.rs index ade49f6..c19b0ac 100644 --- a/crates/webzjs-wallet/src/bindgen/wallet.rs +++ b/crates/webzjs-wallet/src/bindgen/wallet.rs @@ -65,7 +65,7 @@ pub type NoteRef = as InputSource>::NoteRef; /// The wallet can be synchronized with the blockchain by calling the `sync` method. This will fetch compact blocks from the connected lightwalletd instance and scan them for transactions. /// The sync method uses a built-in strategy to determine which blocks is needs to download and scan in order to gain full knowledge of the balances for all accounts that are managed. /// -/// Syncing is a long running process and so is delegated to a WebWorker to prevent from blocking the main thread. It is safe to call other methods on the wallet during syncing although they may take +/// Syncing is a long running process. In the `wasm-parallel` build it is delegated to a WebWorker to prevent from blocking the main thread; in the `no-threads` build it runs in the caller's context, so host the wallet in your own Worker. It is safe to call other methods on the wallet during syncing although they may take /// longer than usual while they wait for a write-lock to be released. /// /// ```javascript @@ -272,6 +272,7 @@ impl WebWallet { /// IMPORTANT: This build has no threads, so no worker is spawned: the sync runs in the context of the caller /// until it completes. Host the `WebWallet` in your own dedicated Worker to keep the page responsive. /// Certain wallet methods may temporarily block while the wallet is being written to during the sync. + /// A panic during the sync cannot be caught as an `Error` in this build (the wasm module aborts); in the threaded build it is reported as `Error::Sync`. /// #[cfg(not(feature = "wasm-parallel"))] pub async fn sync(&self) -> Result<(), Error> { @@ -398,8 +399,7 @@ impl WebWallet { let txids = db .create_proposed_transactions(proposal.into(), &usk) - .await - .unwrap_throw(); + .await?; let flattened_txid_bytes = txids.iter().flat_map(|&x| x.as_ref().clone()).collect(); Ok(flattened_txid_bytes) From ae6d00d6cb79881ff6e8a559fa2fb3b99215119f Mon Sep 17 00:00:00 2001 From: Daniel Gorgonha Date: Mon, 9 Nov 2026 23:03:54 -0300 Subject: [PATCH 5/6] fix(build): name the single-threaded package webzjs-wallet-single wasm-pack names both packages after the crate, and yarn refuses two workspaces with the same name, which broke every yarn command once the single build had run. Rename the generated package.json in `build-wallet-single`. Assisted-by: Claude Code --- justfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/justfile b/justfile index e3fe47e..f7e834a 100644 --- a/justfile +++ b/justfile @@ -13,8 +13,11 @@ build-wallet *features: # Single-threaded wallet: no SharedArrayBuffer, so the page needs no COOP/COEP headers. # RUSTFLAGS="" overrides the atomics flags of .cargo/config.toml; no -Z build-std is needed. # add-worker-module.sh is not run: there is no wasm_thread snippet in this flavour. +# The generated package is renamed to @zcashcommunitygrants/webzjs-wallet-single. build-wallet-single *features: cd crates/webzjs-wallet && RUSTFLAGS="" wasm-pack build -t web --release --scope zcashcommunitygrants --out-dir ../../packages/webzjs-wallet-single --no-default-features --features="wasm no-threads {{features}}" + # same crate name as the threaded package; yarn refuses two workspaces with one name + node -e "const f='packages/webzjs-wallet-single/package.json',p=JSON.parse(require('fs').readFileSync(f));p.name=p.name.replace(/(-single)?$/,'-single');require('fs').writeFileSync(f,JSON.stringify(p,null,2))" # Checks the no-threads feature graph; pass a built .wasm to also check for shared memory and atomics. check-no-threads *wasm: From 1a9c3ac5883e70bd5411852d593b61774b0e54a6 Mon Sep 17 00:00:00 2001 From: Daniel Gorgonha Date: Mon, 9 Nov 2026 23:03:54 -0300 Subject: [PATCH 6/6] ci: type-check the no-threads flavour, validate the .wasm without the threads proposal - CI job `no-threads` also runs `cargo check` of the wasm32 no-threads build. - check-no-threads.sh uses `wasm-tools validate --features=-threads`, which also rejects atomic.fence and no longer loads the whole module as text; the failure message shows the overridden FEATURES. - README: say that `wasm` without `wasm-parallel` now behaves like no-threads, and name the single package. Assisted-by: Claude Code --- .github/workflows/rust-checks.yml | 4 ++++ README.md | 2 +- scripts/check-no-threads.sh | 12 +++++++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/rust-checks.yml b/.github/workflows/rust-checks.yml index fc04471..c11644f 100644 --- a/.github/workflows/rust-checks.yml +++ b/.github/workflows/rust-checks.yml @@ -49,3 +49,7 @@ jobs: - name: Check the no-threads feature graph run: ./scripts/check-no-threads.sh + + - name: Type-check the no-threads flavour for wasm32 + working-directory: crates/webzjs-wallet + run: RUSTFLAGS="" cargo check --lib --target wasm32-unknown-unknown --no-default-features --features "wasm no-threads" diff --git a/README.md b/README.md index f1ac32e..82c7d67 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ just build `SharedArrayBuffer`, so the page does not need the `Cross-Origin-Opener-Policy` / `Cross-Origin-Embedder-Policy` headers. `sync` and `create_proposed_transactions` then run in the caller's context instead of a spawned worker, so host the `WebWallet` in your own dedicated Worker to keep the page responsive. `just check-no-threads [file.wasm]` checks the feature graph and, given a built `.wasm`, that it has -no shared memory and no atomics. The default `just build` is unchanged. +no shared memory and no atomics. The default `just build` (`wasm wasm-parallel`) is unchanged. Note that `wasm` without `wasm-parallel` now behaves like `no-threads`: no `wasm_thread`, no `multicore`, and `sync` / `create_proposed_transactions` run in the caller's context (before, `wasm` alone still spawned `wasm_thread` workers). The generated package is named `@zcashcommunitygrants/webzjs-wallet-single` so both packages can live in the yarn workspace. #### Prerequisites diff --git a/scripts/check-no-threads.sh b/scripts/check-no-threads.sh index 5164200..06b7d45 100755 --- a/scripts/check-no-threads.sh +++ b/scripts/check-no-threads.sh @@ -7,7 +7,8 @@ # Graph: with `wasm no-threads`, wasm_thread and wasm-bindgen-rayon are not in the dependency graph and no # crate enables a thread-pool feature (multicore, threads, web_spin_lock, rayon). # (The rayon crate itself stays: zcash_client_backend depends on it unconditionally.) -# Wasm: no shared memory and no atomic instructions, so the module needs no SharedArrayBuffer. +# Wasm: validates with the threads proposal off (no shared memory, no atomic instructions), so the module +# needs no SharedArrayBuffer. set -euo pipefail wasm="" @@ -16,7 +17,7 @@ cd "$(dirname "$0")/../crates/webzjs-wallet" fail=0 tree() { cargo tree ${CARGO_TREE_FLAGS:-} --target wasm32-unknown-unknown --no-default-features --features "${FEATURES:-wasm no-threads}" -e features "$@"; } -tree >/dev/null || { echo "FAIL: cannot resolve the graph with features 'wasm no-threads'"; exit 1; } +tree >/dev/null || { echo "FAIL: cannot resolve the graph with features '${FEATURES:-wasm no-threads}'"; exit 1; } for pkg in wasm_thread wasm-bindgen-rayon; do if tree -i "$pkg" >/dev/null 2>&1; then echo "FAIL: $pkg is in the no-threads graph"; fail=1; fi @@ -27,9 +28,10 @@ if [ -n "$bad" ]; then echo "FAIL: thread features enabled:"; echo "$bad"; fail= if [ "$#" -ge 1 ]; then command -v wasm-tools >/dev/null || { echo "FAIL: wasm-tools not installed"; exit 1; } - text=$(wasm-tools print "$wasm") - if grep -Eq '\(memory .* shared\)' <<<"$text"; then echo "FAIL: shared memory in $wasm"; fail=1; fi - if grep -Eq '(^|[[:space:]])(memory\.atomic\.|[a-z0-9]+\.atomic\.)' <<<"$text"; then echo "FAIL: atomic instructions in $wasm"; fail=1; fi + # With the threads proposal off, validation rejects shared memory and every atomic instruction (incl. atomic.fence). + if ! err=$(wasm-tools validate --features=-threads "$wasm" 2>&1); then + echo "FAIL: $wasm needs the wasm threads proposal (shared memory or atomics): $(head -n 3 <<<"$err" | tr '\n' ' ')"; fail=1 + fi fi [ "$fail" -eq 0 ] && echo "OK: no-threads checks passed"