Skip to content

platform-wallet: fence shielded host-key writes against wallet deletion #5936

Open

Description

@thepastaclaw

Problem

Wallet removal can race with a retained Arc<PlatformWallet> handle that is still persisting shielded viewing-key state. A bind or shielded_add_account operation can pass its shielded_detached check, be retained across wallet removal, and write a viewing-key row after teardown has deleted the wallet's host rows. The result is a host row for a wallet that no longer exists, and a later seedless restore can observe state that teardown intended to remove.

The relevant bind path is platform_wallet.rs:938-976; shielded_add_account is another viewing-key writer in the same file.

Requested fix

Add a wallet-lifecycle fence around shielded host-key writes and wallet deletion so that:

  • wallet removal waits for, or otherwise closes out, in-flight bind and shielded_add_account host writes;
  • a retained wallet handle cannot persist viewing-key rows after its wallet has been removed;
  • the ordering is explicit for both seed-backed and persisted/seedless bind paths; and
  • deterministic tests cover the race, including a delayed host persist released after wallet removal, and verify that no viewing-key row survives teardown.

The fence should cover the complete host-write operation rather than relying only on a point-in-time shielded_detached check. Its interaction with cancellation, host errors, and any coordinator unregistering should also be documented or tested so teardown cannot be followed by wallet re-registration through the retained handle.

Context

This predates and is intentionally deferred by PR #5934, which fixes the Clear boundary by making the shielded coordinator own Clear and moving the host wipe inside Clear. That PR does not change wallet removal or the bind persist/shielded_detached lifecycle described above.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions