Skip to content

rs-platform-wallet: on_address_found overwrites the managed account balance before checking proof height #5760

Open

Description

@Claudius-Maginificent

TL;DR

When a Platform address balance sync arrives late, platform-wallet can briefly show an address balance older than one it already knows, for example one from before a spend. Features that read that balance, such as shielding, can then offer an amount the network refuses.

User story

As a wallet user, I want the balance my wallet uses for Platform address spends to never go backwards to an older value, so that the amounts I am offered are amounts the network will accept.

Scenario

Base flow

  1. A wallet has Platform address funds and runs periodic address balance syncs.
  2. The user spends from a Platform address; the spend result (height H2) is applied.
  3. A sync that started earlier (its proof at height H1 < H2) finishes after the spend.

Actual behavior

The late sync writes its older balance into key-wallet's managed Platform payment account. Shield and other readers of that account see the pre-spend figure until the next sync. The network later refuses an amount based on it. No funds are at risk.

Expected behavior

A balance proven at an older height than the one already held for that address is not written to the managed account.

Detailed discussion

  • packages/rs-platform-wallet/src/wallet/platform_addresses/provider.rs, PlatformPaymentAddressProvider::on_address_found calls account.set_address_credit_balance(p2pkh, funds.balance, ..) unconditionally (still present on v5.1-dev). The height-aware handling only happens later, when sync_finished flushes per_wallet_in_sync into per_wallet, so the managed account is mutated before any freshness check.
  • Suggested fix: compare funds.as_of_height with the height already held for that address (committed state or the account) and skip set_address_credit_balance when it is older; keep marking the address used / gap-limit generation as today.
  • Found while hardening dash-evo-tool's own mirrors against the same race (fix(wallet): send Platform address transfers and withdrawals through platform-wallet dash-evo-tool#1165); DET pins every mirror by proof height but cannot guard the managed account.

🤖 Co-authored by Claudius the Magnificent AI Agent

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