Skip to content

fix(sp): mark silent payment coins spent elsewhere as spent - #184

Open
thevaibhav-dixit wants to merge 1 commit into
CypherCommons:masterfrom
thevaibhav-dixit:fix/sp-restore-spent-coins
Open

thevaibhav-dixit wants to merge 1 commit into
CypherCommons:masterfrom
thevaibhav-dixit:fix/sp-restore-spent-coins

Conversation

@thevaibhav-dixit

Copy link
Copy Markdown
Contributor

Problem

Shroud only learns that a silent payment coin was spent when this device broadcasts the spending transaction. The indexer scan finds incoming SP coins, but once a coin is found it is never re-checked.

So when a wallet is restored on a new device, or a coin is spent from another device, Shroud keeps treating those coins as unspent:

  • the balance is too high
  • coin selection picks coins that no longer exist, and sending fails

Fix

Every SP coin lives at its own taproot address. After each scan, Shroud asks Electrum about the addresses of the SP coins it believes are unspent:

  • if Electrum has seen the coin's funding transaction but no longer lists the coin as unspent, the coin has been spent, so it's marked spent
  • if Electrum hasn't seen the funding transaction yet, or the request fails, nothing changes

This is a temporary fix inside the app. It doesn't change the indexer or anything the app requests from it.

Testing

  • New tests/unit/sp-spent-check.test.ts: marks only coins Electrum knows about but no longer lists as unspent, and changes nothing when Electrum fails
  • Existing SP suites pass (bip352, scan-by-txid, sp-builder, birth-height)
  • tsc --noEmit and eslint clean

🤖 Generated with Claude Code

A restored wallet, or one whose coins were spent from another device, kept
counting those silent payment coins as unspent: the wallet only learned about
spends it broadcast itself. After each scan, check each unspent SP coin's
address on Electrum and mark it spent when Electrum knows the funding
transaction but no longer lists the coin as unspent.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.

1 participant