Skip to content

FIX: detect external SP spends to prevent phantom balances - #159

Open
abhayguptas wants to merge 1 commit into
CypherCommons:masterfrom
abhayguptas:fix/detect-external-spends
Open

abhayguptas wants to merge 1 commit into
CypherCommons:masterfrom
abhayguptas:fix/detect-external-spends

Conversation

@abhayguptas

Copy link
Copy Markdown

Problem

HDSilentPaymentsWallet.fetchUtxo() does not detect when a Silent Payment (SP) UTXO is spent externally.

The wallet refreshes regular UTXOs through Electrum, but does not query the tweaked Taproot addresses belonging to its SP UTXOs.

As a result, an SP UTXO can remain marked as unspent after being spent from another device or wallet. This can cause the wallet to show an incorrect balance and attempt to spend an already-spent output.

Fix

During fetchUtxo(), query the tweaked Taproot addresses of currently unspent SP UTXOs using the existing Electrum interface.

  • Keep isSpent as false when the outpoint is present.
  • Set isSpent to true when the request succeeds but the outpoint is missing.
  • Keep the existing isSpent state unchanged if the Electrum request fails.
  • Keep spent SP UTXOs in _utxo so transaction history is preserved.

Tests

Added deterministic regression tests covering:

  • externally spent SP UTXOs
  • still-unspent SP UTXOs
  • Electrum/network failure
  • multiple SP UTXOs
  • preserving spent SP UTXOs for transaction history
  • existing parent fetchUtxo() behavior

Verification

  • TypeScript compilation: passed
  • ESLint: passed
  • Focused tests: 6/6 passed
  • Full unit test suite: 274/274 passed

fixes #158

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Detect externally spent Silent Payment UTXOs

1 participant