Repository navigation
Description
The birthday of an imported account reaches the server at import, and the first sync sends it again. I ran this at the head of #27 (9ad0a58) and read the same code on main (317d790).
How I ran it. A native harness calls the inner Rust Wallet methods that the wasm bindings wrap, over native tonic, against a public mainnet lightwalletd, at #27's head (it pins zcash_client_backend 0.25.0; main requires 0.24.0-rc.1). The key is a throwaway view key that holds no funds. The bindings and the browser transport were not exercised. The program and its output are in https://github.com/deegalabs/WebZjs/tree/409ce5a294db0a196a24e446f7687621bc9f3677/repro/birthday-lock-stall. Notes 2, 3 and 5 are read from the code. The rounding check in the last paragraph calls AccountBirthday::from_treestate, the in-memory store and sync::run directly, not Wallet.
-
import_account_ufvkasks the server for the tree state atbirthday - 1(wallet.rs:245-254). The code comment already says what that does.// Fetch the tree state corresponding to the last block prior to the wallet's // birthday height. NOTE: THIS APPROACH LEAKS THE BIRTHDAY TO THE SERVER!
-
All three import paths use it, so a seed account, a spending UFVK account and a view-only UFVK account all send the birthday (create_account, create_account_ufvk, create_account_view_ufvk).
-
The request reaches the operator of the gRPC-web endpoint passed to the
WebWalletconstructor, with the client's IP address and the time. For a new account it says only that one is being created now. For a restore it gives the height the wallet was created at, which is the earliest block any of its notes can be in. -
Sync sends the same height again, so removing the import request alone hides nothing.
- The historic scan range starts at the account birthday (wallet_write.rs:211).
sync::runasks for the tree state at the start of each range minus 1 (sync.rs:201), so the first historic batch sendsbirthday - 1. utxo_query_heightreturns the account birthday (wallet_read.rs:965-971).refresh_utxosruns on every sync and sends it asstart_heightnext to the account's transparent receivers (sync.rs:511-519). It skips an account with no transparent receivers, such as an Orchard-only UFVK (sync.rs:522).
These links point to the revisions Feat/nu7 portable keys #27 pins (
zcash_client_memoryb4c8f0d, librustzcash 0.25.0).mainpins older revisions with the same code. - The historic scan range starts at the account birthday (wallet_write.rs:211).
-
The same comment and request are in
zcash-devtool'simport_ufvk(import_ufvk.rs:68-86). -
The request log matches notes 1 and 4. With a birthday B, import sends
GetTreeStateat B-1. The first sync sendsGetBlockRangefrom B andGetTreeStateat B-1 again. For a UFVK with transparent receivers, every sync sendsGetAddressUtxosStreamwithstart_heightB, the second sync included. For an Orchard-only UFVK that request is absent, the first sync still sends the other two with B, and the second sync sends onlyGetSubtreeRootsandGetLatestBlock. In the run B was 3,605,725 at a tip of 3,617,725. Import sentGetTreeStateat 3,605,724, and the first sync sentGetBlockRangefrom 3,605,725 andGetTreeStateat 3,605,724 again. For the UFVK with transparent receivers, both syncs sentGetAddressUtxosStreamwithstart_height3,605,725.
Fix to consider. Round the birthday down before the AccountBirthday is built and stored, for example to a multiple of BATCH_SIZE (wallet.rs:63, 10,000 blocks), and not below the Sapling activation height of the network (WebZjs hardcodes the mainnet one at bindgen/wallet.rs:637). Every later request would then carry the rounded height. The server would still learn a window of 10,000 blocks. The cost would be at most one extra batch of scanning.
I checked that zcash_client_backend 0.25.0 accepts a rounded birthday. AccountBirthday::from_treestate accepts the tree state at 3,609,999 (a birthday of 3,610,000) and at 3,419,999 (3,420,000, below NU6.3, where the Ironwood frontier is empty). A view-only account with no notes, imported at 3,420,000, synced 197,734 blocks to the tip across the Ironwood activation, and sync::run returned Ok in 215.13 s. I did not write the rounding into WebZjs, and I did not test a wallet that holds notes.
🤖 Generated with Claude Code
Activity