order block transaction references consistently for any height
What changed, and why it matters
This commit changes how Sparrow Wallet sorts wallet transactions by block height. It replaces a manual subtraction-based height comparison with a dedicated comparison method. The change is likely intended to fix subtle sorting bugs—especially when heights are very large or negative—by avoiding integer overflow and inconsistent ordering. There is no direct evidence this is a security vulnerability, but inconsistent transaction ordering could theoretically confuse users or downstream logic.
Review the drongo submodule diff at commit `0656034362e7aa6b184ea73d51d08a8f9dfcf6cf` to confirm how `compareHeight()` handles edge cases such as unconfirmed transactions, negative heights, and overflow. Consider whether the old subtraction could have led to incorrect transaction ordering that affects balance display or coin selection. No urgent action is indicated from this diff alone.
Security signals we found
Integer subtraction used for comparison can overflow if heights differ widely or use sentinel values, producing incorrect sort order
Inconsistent ordering between `TransactionEntry` and `WalletTransactionsEntry` could break balance calculations or UI consistency
Submodule bump suggests the real fix lives in an external dependency and is not visible in this diff
Evidence from the diff
The patch updates four Java files and a git submodule (drongo). In each Java file, integer subtraction comparisons of block heights (e.g., getComparisonHeight() - other.getComparisonHeight()) are replaced by calls to a new compareHeight() method. The submodule bump likely contains the implementation of compareHeight() in the drongo library. The change makes transaction ordering consistent across ElectrumServer, HashIndexEntry, TransactionEntry, and WalletTransactionsEntry. The commit message frames this as a consistency fix for ordering at any block height.
Changed components
drongo submodulesrc/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.javasrc/main/java/com/sparrowwallet/sparrow/wallet/HashIndexEntry.javasrc/main/java/com/sparrowwallet/sparrow/wallet/TransactionEntry.javasrc/main/java/com/sparrowwallet/sparrow/wallet/WalletTransactionsEntry.javaInspect captured patch +5 / −11
### drongo
@@ -1 +1 @@
-Subproject commit 5c065732eb19838d4e63c2e3dfe2d3e093bd05df
+Subproject commit 0656034362e7aa6b184ea73d51d08a8f9dfcf6cf
### src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java
@@ -372,7 +372,7 @@ private static List<ScriptHashTx> getScriptHashes(String scriptHash, WalletNode
txos.removeIf(ref -> !unique.add(ref.getHash()));
txos.sort((txo1, txo2) -> {
if(txo1.getHeight() != txo2.getHeight()) {
- return txo1.getComparisonHeight() - txo2.getComparisonHeight();
+ return txo1.compareHeight(txo2);
}
if(txo1.isSpent() && txo1.getSpentBy().equals(txo2)) {
### src/main/java/com/sparrowwallet/sparrow/wallet/HashIndexEntry.java
@@ -106,7 +106,7 @@ public int compareTo(HashIndexEntry o) {
}
if(getHashIndex().getHeight() != o.getHashIndex().getHeight()) {
- return o.getHashIndex().getComparisonHeight() - getHashIndex().getComparisonHeight();
+ return o.getHashIndex().compareHeight(getHashIndex());
}
return Long.compare(o.getHashIndex().getIndex(), (int)getHashIndex().getIndex());
### src/main/java/com/sparrowwallet/sparrow/wallet/TransactionEntry.java
@@ -180,10 +180,7 @@ public int hashCode() {
public int compareTo(TransactionEntry other) {
//This comparison must be identical to that of WalletTransactionsEntry.WalletTransaction
if(blockTransaction.getHeight() != other.blockTransaction.getHeight()) {
- int blockOrder = blockTransaction.getComparisonHeight() - other.blockTransaction.getComparisonHeight();
- if(blockOrder != 0) {
- return blockOrder;
- }
+ return blockTransaction.compareHeight(other.blockTransaction);
}
int valueOrder = Long.compare(other.getValue(), getValue());
### src/main/java/com/sparrowwallet/sparrow/wallet/WalletTransactionsEntry.java
@@ -285,10 +285,7 @@ public long getValue() {
public int compareTo(WalletTransactionsEntry.WalletTransaction other) {
//This comparison must be identical to that of TransactionEntry so we can avoid a resort calculating balances when creating WalletTransactionsEntry
if(blockTransaction.getHeight() != other.blockTransaction.getHeight()) {
- int blockOrder = blockTransaction.getComparisonHeight() - other.blockTransaction.getComparisonHeight();
- if(blockOrder != 0) {
- return blockOrder;
- }
+ return blockTransaction.compareHeight(other.blockTransaction);
}
int valueOrder = Long.compare(other.getValue(), getValue());Why this scored 21/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.