fix(toolkit): propagate DustWallet spend state update [PM-20016]#877
Open
fix(toolkit): propagate DustWallet spend state update [PM-20016]#877
Conversation
Contributor
be637f8 to
fb44f53
Compare
justinfrevert
approved these changes
Mar 6, 2026
ozgb
requested changes
Mar 10, 2026
Initial changeset for fix/PM-20016. Implementation to follow after planning phase completion. Made-with: Cursor
Initial changeset for fix/PM-20016. Implementation to follow after planning phase completion. Made-with: Cursor
Modify speculative_spend to return the updated DustLocalState alongside spends, and extend mark_spent to accept and assign the updated state to self.dust_local_state atomically with nullifier recording. Update gather_dust_spends and confirm_dust_spends in transaction.rs to thread per-wallet updated states from speculation through to commit. This ensures DustLocalState::spend's pending_until flags are propagated, preventing utxos() from returning already-spent outputs in consecutive spend operations. Addresses Least Authority audit finding Issue AO. Made-with: Cursor
Made-with: Cursor
Made-with: Cursor
Made-with: Cursor
Made-with: Cursor
…lexity lint Made-with: Cursor
Made-with: Cursor
95b390d to
489bc6e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.








Summary
Fix
DustWallet::speculative_spendto return the updatedDustLocalStatealongside spends, and extendmark_spentto commit the state atomically with nullifier recording. Prevents stale-state bugs where consecutive spends select already-spent outputs. This is Least Authority audit finding Issue AO (Medium impact / Low severity, pp. 56-57).🎫 Ticket 📐 Engineering
Motivation
DustWallet::speculative_spendclonesdust_local_state, appliesDustLocalState::spenditeratively (which setspending_untilon spent UTXOs to exclude them from futureutxos()calls), then discards the updated state. The companionmark_spentmethod records nullifiers inspent_utxosbut does not apply the state changes fromDustLocalState::spend.This means consecutive transaction constructions operate on stale state — spent UTXOs remain selectable, balances are overreported, and the ledger may reject transactions due to nullifier reuse. The issue persists until event replay rebuilds state from on-chain data.
Changes
wallet/dust.rs—speculative_spend— Return type changed fromResult<Vec<DustSpend>>toResult<(Vec<DustSpend>, Sp<DustLocalState>)>, returning the accumulated state alongside spendswallet/dust.rs—mark_spent— Extended to acceptupdated_state: Sp<DustLocalState>and assign it toself.dust_local_statebefore recording nullifierstransaction.rs—gather_dust_spends— Collects per-wallet updated states inHashMap<WalletSeed, Sp<DustLocalState>>alongside spendstransaction.rs—confirm_dust_spends— Consumes per-wallet updated states via.remove()and passes each tomark_spent📌 Submission Checklist
🔱 Fork Strategy
🗹 TODO before merging