discard a wallet discovery result where the words or passphrase were edited while it ran
What changed, and why it matters
This commit fixes a timing issue in Sparrow Wallet's wallet-import screen. If a user changed their seed words or passphrase while a background 'discover wallet' scan was still running, the app could previously show results from the old (or partially changed) words/passphrase. The patch now captures the words and passphrase at the start of the scan and discards the result if they changed before the scan finished, preventing the user from importing a wallet they did not intend to.
Review whether other async discovery/import flows in Sparrow also snapshot input state before comparing results. Consider adding UI feedback when a result is discarded due to input changes, so users know why discovery appeared to produce no result.
Security signals we found
stale-result race condition
user input mutation during async operation
UI state desynchronization
potential import of unintended wallet
Evidence from the diff
In MnemonicWalletKeystoreImportPane.discoverWallet(), the code now snapshots wordEntriesProperty and passphraseProperty before starting the WalletDiscoveryService. In the onSucceeded handler it compares the captured values to the current property values. If they differ, the discovered wallets are ignored and the discover button state is updated. This prevents stale discovery results from being presented or imported after the user edits the mnemonic or passphrase during the asynchronous scan.
Changed components
src/main/java/com/sparrowwallet/sparrow/control/MnemonicWalletKeystoreImportPane.javaWallet discovery import flowMnemonic/passphrase UI propertiesInspect captured patch +6 / −1
### src/main/java/com/sparrowwallet/sparrow/control/MnemonicWalletKeystoreImportPane.java
@@ -29,6 +29,7 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -107,6 +108,8 @@ private void discoverWallet() {
progressIndicator.getStyleClass().add("button-progress");
discoverButton.setGraphic(progressIndicator);
List<Wallet> wallets = new ArrayList<>();
+ List<String> words = List.copyOf(wordEntriesProperty.get());
+ String passphrase = passphraseProperty.get();
List<List<ChildNumber>> derivations = ScriptType.getScriptTypesForPolicyType(PolicyType.SINGLE_HD).stream().map(ScriptType::getDefaultDerivation).collect(Collectors.toList());
derivations.add(List.of(new ChildNumber(0, true)));
@@ -135,7 +138,9 @@ private void discoverWallet() {
walletDiscoveryService.setOnSucceeded(successEvent -> {
discoverButton.setGraphic(null);
Optional<List<Wallet>> optWallets = walletDiscoveryService.getValue();
- if(optWallets.isPresent()) {
+ if(!words.equals(wordEntriesProperty.get()) || !Objects.equals(passphrase, passphraseProperty.get())) {
+ discoverButton.setDisable(discoverButton.isDisable() && !words.equals(wordEntriesProperty.get()));
+ } else if(optWallets.isPresent()) {
List<Wallet> discoveredWallets = optWallets.get();
if(discoveredWallets.size() > 1) {
for(Wallet wallet : discoveredWallets) {Why this scored 43/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.