decide whether a border wallets grid is hex from all of its cells rather than the selected ones
What changed, and why it matters
This commit fixes a bug in Sparrow Wallet's 'Border Wallets' feature. Previously, the app guessed whether a grid of seed-word abbreviations was hexadecimal (base-16) by looking only at the cells the user selected. If a user happened to pick cells that looked like ordinary decimal numbers, the app treated the whole grid as decimal and looked up the wrong BIP39 words, which could produce an incorrect wallet/seed. The fix now decides the grid type by examining all filled cells, so a hex grid is correctly recognized even when the selected cells contain only decimal-looking digits. This is a correctness/reliability fix with possible security implications for wallet recovery accuracy, but it is not an obvious remote-exploitable vulnerability.
Review the Border Wallets import flow for additional edge cases in grid type detection and selection-to-word mapping. Consider adding unit tests covering hex grids whose selected cells are purely decimal, mixed-case hex, and empty cells. No urgent patch deployment appears required unless wallet recovery failures are reported.
Security signals we found
Incorrect input classification leading to wrong BIP39 word derivation
Wallet seed/recovery correctness issue
UI dialog parsing bug in mnemonic grid import
Evidence from the diff
In MnemonicGridDialog.getSelectedWords(), the code previously classified the grid as integer or hex based only on the selected abbreviations. A hex grid whose selected cells happened to be all decimal digits (e.g., 1-9 only) was misclassified as decimal. The patch reclassifies using all non-empty grid cells: isHex is true only if every populated cell matches Utils.isHex and at least one cell is not a pure decimal number. The integer branch is then gated on !isHex. This prevents mis-lookup of BIP39 word indices when a hex grid’s selection lacks a-f characters.
Changed components
src/main/java/com/sparrowwallet/sparrow/control/MnemonicGridDialog.javaBorder Wallets grid import featureBIP39 mnemonic word lookupInspect captured patch +9 / −6
### src/main/java/com/sparrowwallet/sparrow/control/MnemonicGridDialog.java
@@ -172,21 +172,24 @@ private List<String> getSelectedWords() {
List<String> abbreviations = selectedCells.stream()
.map(position -> (String)spreadsheetView.getGrid().getRows().get(position.getRow()).get(position.getColumn()).getItem()).collect(Collectors.toList());
- boolean isInteger = abbreviations.stream().allMatch(Utils::isNumber);
- boolean isHex = abbreviations.stream().allMatch(Utils::isHex);
+ //Decided from the whole grid, as a selection from a hex grid can contain only decimal digits
+ List<String> gridCells = spreadsheetView.getGrid().getRows().stream().flatMap(List::stream).map(cell -> (String)cell.getItem())
+ .filter(cell -> cell != null && !cell.isEmpty()).toList();
+ boolean isHex = !gridCells.isEmpty() && gridCells.stream().allMatch(Utils::isHex) && gridCells.stream().anyMatch(cell -> !Utils.isNumber(cell));
+ boolean isInteger = !isHex && abbreviations.stream().allMatch(Utils::isNumber);
List<String> words = new ArrayList<>();
for(String abbreviation : abbreviations) {
- if(isInteger) {
+ if(isHex) {
try {
- int index = Integer.parseInt(abbreviation);
+ int index = Integer.parseInt(abbreviation, 16);
words.add(Bip39MnemonicCode.INSTANCE.getWordList().get(index - 1));
} catch(NumberFormatException e) {
//ignore
}
- } else if(isHex) {
+ } else if(isInteger) {
try {
- int index = Integer.parseInt(abbreviation, 16);
+ int index = Integer.parseInt(abbreviation);
words.add(Bip39MnemonicCode.INSTANCE.getWordList().get(index - 1));
} catch(NumberFormatException e) {
//ignoreWhy this scored 33/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.