Skip to content

pczt_send / pczt_shield / pczt_create check chain_height(), the reported tip, not the scanned height #29

Open

Description

@danielgorgonha

pczt_send checks that the wallet is synced before broadcasting, but the value it compares with the server's tip is chain_height(), not the scanned height:

let fully_scanned = db_read.chain_height()?;

(wallet.rs:897 at 9ad0a58, the head of #27.) WalletRead::chain_height is "the height of the chain as known to the wallet as of the most recent call to update_chain_tip", and sync::run calls update_chain_tip at the start, before scanning. So once a sync has started, chain_height() is the tip whether or not the blocks below it were scanned, and the "blocks behind" check passes.

The same value decides whether to sync first in pczt_shield (

let wallet_height = self.db.read().await.chain_height()?;
), pczt_create (
let wallet_height = self.db.read().await.chain_height()?;
) and, in #27, pczt_sweep. The web wallet relies on these checks (usePCZT.ts: "Rust's pczt_shield/pczt_send handle sync validation internally ... so no JS-layer pre-check required"). #18 changes how sync runs but keeps this check as it is.

When this matters: any sync() that stops partway. Two cases, run natively against the crates #27 pins (zcash_client_backend 0.25.0, zcash_client_memory b4c8f0d) with a fake lightwalletd, birthday 3,500,000, tip 3,524,999:

  • GetBlockRange fails partway through the second range (sync() returns an error): chain_height 3,524,999, fully_scanned_height 3,509,999.
  • The server ends the first range early with an OK status (sync() returns Ok): chain_height 3,524,999, fully_scanned_height 3,500,499.

In both, a check against chain_height() sees 0 blocks behind, while the fully scanned height is 15,000 and 24,500 blocks below the tip (in the second case 9,500 blocks are unscanned, in a gap below blocks that were scanned). On main the pins differ (zcash_client_backend 0.24.0-rc.1 at librustzcash 0a2c6d1), but chain_height and update_chain_tip read the same there; I ran only the #27 pins. I did not run WebZjs itself; that the check passes is read from the code plus the values above. What I expect it to cause, also not tested: the sync these functions promise is skipped, so a transaction is built from a partly scanned wallet.

Suggestion: compare against the fully scanned height instead, for example db.block_fully_scanned()?.map(|m| m.block_height()), or fully_scanned_height() from get_wallet_summary, in all four places. Until then, a caller can check fully_scanned_height < chain_tip_height from get_wallet_summary() itself. Happy to send a small PR if you agree with the approach.

🤖 Generated with Claude Code

Activity

  1. danielgorgonha commented on Nov 24, 2026

    @danielgorgonha
    Author

    The program behind the two cases above: https://github.com/deegalabs/WebZjs/tree/a8ca70f8260975094b3a2006706a74da12b4d831/repro/chain-height-check

    Native, no browser, no network. It runs sync::run against a fake lightwalletd (an in-process tower service), with the crates and heights from the issue and empty blocks. Each case runs a second sync against an honest server after the first.

    1. git clone https://github.com/deegalabs/WebZjs && cd WebZjs && git checkout a8ca70f8260975094b3a2006706a74da12b4d831 && cd repro/chain-height-check
    2. cargo run --release --locked -- B: the first GetBlockRange ends after 500 of 10,000 blocks with an OK status. Under sync #1: run() -> Ok(()), then chain_height Some(BlockHeight(3524999)) block_fully_scanned Some(BlockHeight(3500499)).
    3. cargo run --release --locked -- E: the second GetBlockRange sends 300 blocks, then grpc-status 11. Under sync #1: run() -> Err(...) ending in out of range, then chain_height Some(BlockHeight(3524999)) block_fully_scanned Some(BlockHeight(3509999)).

    So the wallet is 24,500 (B) and 15,000 (E) blocks behind, and a check against chain_height(), like the one in pczt_send, pczt_shield and pczt_create, sees 0. In both cases sync #2 fills the gap.

    🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions