Skip to content

swift-sdk/platform-wallet: hold native-op admission and the generation guard across shielded spends #5868

Open

Description

@romchornyi

Problem

The shielded spend wrappers on PlatformWalletManager (PlatformWalletManagerShieldedSync.swift) run their FFI call in a detached task without registering a native operation (admitNativeOp / finishNativeOp). Once such a call suspends, deleteWallet can pass ensureSyncNativeOpAllowed and shutdown() can finish its admission drain and destroy the native manager while the spend is still running.

The Rust side does not prevent it either: e.g. shielded_shield_from_identity_impl clones the identity and the viewing keys and then awaits transition construction without holding the wallet generation's lifecycle guard. A retained operation can continue after removal purges the coordinator state, recreate activity and recovery rows through save_activity / arm_redrive (both entry(id).or_default()), and broadcast the signed payment after deletion has completed.

Wrappers with the gap (Swift): shieldedTransfer, shieldedShield, shieldedShieldFromIdentity, shieldedShieldToRecipient, shieldedUnshield, shieldedIdentityTopUpFromPool, shieldedWithdraw, shieldedIdentityCreateFromPool. #5863 fixes shieldedShieldFromIdentityToRecipient only.

Fix direction

  • Swift: hold native-op admission through the detached task and the result delivery for every state-changing shielded call, as withWalletDrainNativeOperation does; a regression test per call that pauses it and checks that deletion is rejected and shutdown waits.
  • Rust: hold the generation lifecycle guard across transition construction, broadcast and the activity/recovery writes in the shielded spend paths, so a removed or recreated wallet is refused before anything is signed, the way the generation-guarded payment paths are.

Activity

  1. romchornyi commented on Nov 12, 2026

    @romchornyi
    ContributorAuthor

    Follow-up from #5863 review: the Swift side now rejects clearShielded() while any async native operation is admitted (for example the identity-to-recipient shielded spend), but that only protects Swift callers. Direct C callers of platform_wallet_manager_shielded_clear are still unprotected, so the authoritative exclusion belongs in rs-platform-wallet.

    Please make the coordinator's Clear exclude or drain admitted shielded spends, and have spends whose captured state Clear invalidated refuse before signing or broadcasting. Two regression cases are needed:

    1. Clear while proof construction is awaiting completion. Today Clear can return successfully and the spend then recreates activity and recovery rows through save_activity and arm_redrive.
    2. Clear after recovery arming while broadcast or confirmation is pending. Today FileShieldedStore::purge_all_subwallets deletes the signed transition from shielded_pending_spends.
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