What changed, and why it matters
This commit fixes a bug in the FROST Bitcoin wallet's coin-selection retry logic. Previously, when the first attempt to build a transaction didn't have enough funds, the code tried to add extra UTXOs but used a Set (which ignores duplicates and has no guaranteed order) and also accidentally included the current UTXO again instead of only the remaining ones. The fix switches to an ordered List and correctly picks/removes the next UTXO. This could have caused transaction building to fail, loop incorrectly, or select the wrong inputs.
Review the full FROST transaction flow for similar Set/List misuse and off-by-one errors, and add unit tests covering insufficient-funds retry paths to ensure the correct UTXOs are selected and no UTXO is double-spent or skipped.
Security signals we found
FROST threshold-signature wallet input selection bug
Potential transaction build failure / incorrect UTXO selection
Set-vs-List ordering/deduplication issue in coin selection
Off-by-one inclusion of already-selected UTXO in remaining set
No removal of consumed UTXO during retry loop
Evidence from the diff
In lib/wallets/wallet/impl/bitcoin_frost_wallet.dart the coin-selection retry path is corrected in three ways: (1) utxosRemaining is changed from Set
Changed components
lib/wallets/wallet/impl/bitcoin_frost_wallet.dartFROST Bitcoin wallet transaction constructionUTXO selection / coin-control retry logicInspect captured patch +4 / −4
diff --git a/lib/wallets/wallet/impl/bitcoin_frost_wallet.dart b/lib/wallets/wallet/impl/bitcoin_frost_wallet.dart
index aa34ffa..c108ddc 100644
--- a/lib/wallets/wallet/impl/bitcoin_frost_wallet.dart
+++ b/lib/wallets/wallet/impl/bitcoin_frost_wallet.dart
@@ -154,7 +154,7 @@ class BitcoinFrostWallet<T extends FrostCurrency> extends Wallet<T>
fractionDigits: cryptoCurrency.fractionDigits,
);
final Set<UTXO> utxosToUse = {};
- final Set<UTXO> utxosRemaining = {};
+ final List<UTXO> utxosRemaining = [];
for (int i = 0; i < utxos.length; i++) {
final utxo = utxos[i];
sum += Amount(
@@ -164,7 +164,7 @@ class BitcoinFrostWallet<T extends FrostCurrency> extends Wallet<T>
utxosToUse.add(utxo);
if (sum > total) {
if (i + 1 < utxos.length) {
- utxosRemaining.addAll(utxos.sublist(i));
+ utxosRemaining.addAll(utxos.sublist(i + 1));
}
break;
}
@@ -214,7 +214,7 @@ class BitcoinFrostWallet<T extends FrostCurrency> extends Wallet<T>
} on FrostInsufficientFundsException catch (_) {
if (utxosRemaining.isNotEmpty) {
// add extra utxo
- final utxo = utxosRemaining.take(1).first;
+ final utxo = utxosRemaining.removeAt(0);
final dData = await getDerivationData(utxo.address);
final publicKey = cryptoCurrency.addressToPubkey(
address: utxo.address!,
@@ -232,7 +232,7 @@ class BitcoinFrostWallet<T extends FrostCurrency> extends Wallet<T>
return txData.copyWith(
frostMSConfig: config,
- utxos: utxosToUse.map((e) => StandardInput(e)).toSet(),
+ utxos: inputs.map((e) => StandardInput(e.utxo)).toSet(),
);
} catch (_) {
rethrow;
Why this scored 31/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.