Skip to content

Every account import sends the wallet birthday to the gRPC-web endpoint, and sync repeats it #35

Backlog

Description

@danielgorgonha

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.

  1. import_account_ufvk asks the server for the tree state at birthday - 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!
  2. 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).

  3. The request reaches the operator of the gRPC-web endpoint passed to the WebWallet constructor, 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.

  4. 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::run asks for the tree state at the start of each range minus 1 (sync.rs:201), so the first historic batch sends birthday - 1.
    • utxo_query_height returns the account birthday (wallet_read.rs:965-971). refresh_utxos runs on every sync and sends it as start_height next 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_memory b4c8f0d, librustzcash 0.25.0). main pins older revisions with the same code.

  5. The same comment and request are in zcash-devtool's import_ufvk (import_ufvk.rs:68-86).

  6. The request log matches notes 1 and 4. With a birthday B, import sends GetTreeState at B-1. The first sync sends GetBlockRange from B and GetTreeState at B-1 again. For a UFVK with transparent receivers, every sync sends GetAddressUtxosStream with start_height B, 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 only GetSubtreeRoots and GetLatestBlock. In the run B was 3,605,725 at a tip of 3,617,725. Import sent GetTreeState at 3,605,724, and the first sync sent GetBlockRange from 3,605,725 and GetTreeState at 3,605,724 again. For the UFVK with transparent receivers, both syncs sent GetAddressUtxosStream with start_height 3,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

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