Skip to content

platform-wallet: save external-payment intent with the asset lock so recovery cannot refund it to the sender #5824

Open

Description

@HashEngineering

Problem

fund_from_asset_lock_external builds and broadcasts a Core asset lock meant to pay third-party Platform addresses. If the Platform submission then fails, or the app restarts before it completes, the saved lock has nothing that says who it was for:

  • TrackedAssetLock / AssetLockEntry store no recipients and no "external" flag.
  • The funding type is AssetLockAddressTopUp (set in fund_from_asset_lock_inner), identical to an owned top-up.

As a result, recovery treats the lock as owned:

  • Generic recovery (KotlinExampleApp ResumableTopUps.resumeRouteFor → FundFromAssetLockScreen, and the SwiftExampleApp equivalent) resumes it through owned funding with a fresh wallet address as the remainder.
  • Rust's recipient validation accepts that, because it has no record of the original intent.
  • The lock is consumed and the money goes back to the sender's wallet. The intended payee is never paid, yet the UI reports success.

Today hosts have to record the outpoint → recipients link themselves in the on_asset_lock_built callback. That isn't reliable:

  • The callback can't fail. The JNI trampoline clears a thrown exception and funding carries on to broadcast.
  • Recovery paths that can't see the host's record ignore it anyway.

Platform-address funding (owned and external) calls broadcast_funded_asset_lock_with_funding, which passes no AssetLockOperationContext. Only the shielded wallet-drain flow uses that durable checkpoint today.

Scope: rs-platform-wallet, then the FFI, Swift and Kotlin

  1. Store the payment intent (recipient map, remainder recipient, ownership scope: owned or external) on the tracked lock in rs-platform-wallet. Make it durable before broadcast, either with the existing AssetLockOperationContext checkpoint or something equivalent.
  2. Give external locks a distinct funding type or an explicit flag so they never look like AssetLockAddressTopUp.
  3. When resuming an external lock, restore or verify the saved recipients. Refuse an owned resume that would replace them.
  4. Expose the intent through persistence (onPersistAssetLockUpsert / AssetLockEntity, and the Swift equivalent) so hosts can show it. Route example-app recovery by the saved intent, and remove the host-side association requirement from the fundFromAssetLockExternal docs in both SDKs.

Acceptance criteria

  • External lock with a failed Platform submit, then restart: recovery pays the original recipients, or refuses. It never refunds to the wallet.
  • A throwing on_asset_lock_built callback no longer affects whether the lock can be recovered.
  • Rust tests cover resuming an external lock through the owned path, which must be rejected.

References

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