Skip to content

Wallet drain: let the host cap the swept balance at what the user confirmed #5607

Open

Description

@llbartekll

Problem

shielded_fund_from_wallet_drain (Swift shieldedFundFromWalletDrain(walletId:operationId:fundingAccountIndex:recipientRaw43:)) selects its inputs when it builds the asset lock: every eligible UTXO at that moment. The host can only show the user a read-only shielded_wallet_drain_preview beforehand. AssetLockFunding::DrainWalletBalance carries minimum_lock_duffs but no upper bound and no input snapshot.

For a drain to the wallet's own Orchard address that is harmless. For an external recipient (dashpay/dashwallet-ios#1251) a UTXO that becomes eligible between the confirmation and the build is swept to the third party — money the user never saw on the confirm screen. dashwallet-ios re-reads the preview after authorization and refuses when the candidate balance grew, which narrows the window to the time between that preview and input selection, but cannot close it.

Proposal

Add an optional bound the build enforces on the inputs it actually selects, e.g. maximum_candidate_balance_duffs: Option<u64> on DrainWalletBalance (and a matching FFI / Swift parameter): if the selected candidate balance exceeds it, fail with a typed notSent error before signing or broadcasting, so the host can show a fresh estimate. Alternatively accept the exact outpoint set from the preview, but a balance cap is simpler and enough for "never send more than confirmed".

Found by review of dashpay/dashwallet-ios#1251.

🤖 Generated with Claude Code

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