mark a transaction tab height unverified when its proof cannot be obtained from a connected server, and fetch it again after the server changes
What changed, and why it matters
This commit fixes how Sparrow Wallet handles transaction block-height information that a connected Electrum server reports but cannot prove with a cryptographic Merkle proof. Previously, if the server returned an empty or invalid proof, the wallet might still treat the reported height as verified. After the change, an unproven height is marked as 'server reported only' and the wallet re-fetches the proof when the server connection changes, rather than silently trusting the old value. This reduces the chance that a user is misled about whether a transaction is confirmed.
Reviewers should confirm that all paths which set a transaction's block height from server data now pass through isServerReported() checks, and that no other controllers bypass the re-verification on server change. Consider adding an integration test where a server first reports a fake height and then a second server reports a different height, to ensure the UI updates correctly.
Security signals we found
Merkle proof verification now rejects null/empty proofs explicitly
Server-reported transaction heights are re-verified after server changes
UI no longer displays an unsubstantiated block height as verified
New unit tests for empty proof handling and server-reported status logic
Evidence from the diff
The patch hardens transaction height verification in the Electrum client. Key changes: (1) ElectrumServer.verifyMerkleProofs now treats a null proof as invalid, not just TransactionMerkleProof.ERROR_PROOF, so a server returning no proof cannot substantiate a height. (2) HeadersController records an unproven pair (verificationUnprovenPair) when verification fails while still connected, and clears server-reported state on a new ConnectionEvent so the new server is re-queried. (3) TransactionController resets the cached BlockTransaction and refetches when the status is server-reported-only after a new connection. (4) TransactionData adds isServerReported(), which returns true only when a blockTransaction exists, is not a PSBT, is not locally proven, and is not held by an open wallet. Tests cover null/empty proofs and the new isServerReported() logic.
Changed components
ElectrumServer.java - Merkle proof verificationHeadersController.java - transaction tab height verification UI flowTransactionController.java - transaction data refresh on server reconnectTransactionData.java - server-reported status classificationTransactionProofTest.java / TransactionDataTest.java - regression testsInspect captured patch +93 / −4
### src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java
@@ -1402,7 +1402,7 @@ private Map<BlockTransactionHash, BlockHeader> verifyMerkleProofs(Wallet wallet,
BlockTransactionHash reference = outstanding.get(entry.getKey());
TransactionMerkleProof proof = entry.getValue();
//An error, or a proof for some other block, leaves the pair outstanding: the server has not substantiated the height it reported
- if(reference != null && proof != TransactionMerkleProof.ERROR_PROOF && proof.block_height == reference.getHeight()) {
+ if(reference != null && proof != null && proof != TransactionMerkleProof.ERROR_PROOF && proof.block_height == reference.getHeight()) {
outstanding.remove(entry.getKey());
BlockHeader header = getVerifiedHeader(reference.getHeight());
if(header == null) {
### src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java
@@ -1011,11 +1011,18 @@ private void verifyBlockTransaction(BlockTransaction blockTransaction) {
}
});
transactionVerificationService.setOnFailed(workerStateEvent -> {
- log.debug("Could not reach the server to verify transaction " + blockTransaction.getHashAsString(), workerStateEvent.getSource().getException());
+ log.debug("Could not verify transaction " + blockTransaction.getHashAsString(), workerStateEvent.getSource().getException());
//Only the request still outstanding releases the pair: one a reconnect has already replaced is asking about the same pair, so the pair
//cannot tell them apart, and letting the older failure release it would put a third request behind the one in flight
if(verificationService == transactionVerificationService) {
- verificationRequestedPair = null;
+ //A server still connected has not substantiated the height it reported, whatever the reason, and is not asked again until a reconnect
+ if(AppServices.isConnected() && ElectrumServer.isVerifyingTransactions() && headersForm.getTransaction().getTxId().equals(blockTransaction.getHash())) {
+ verificationUnprovenPair = pair;
+ BlockTransaction shown = headersForm.getBlockTransaction() == null ? blockTransaction : headersForm.getBlockTransaction();
+ updateBlockchainForm(shown, AppServices.getCurrentBlockHeight());
+ } else {
+ verificationRequestedPair = null;
+ }
}
});
transactionVerificationService.start();
@@ -2075,8 +2082,15 @@ public void chainReorg(ChainReorgEvent event) {
@Subscribe
public void connection(ConnectionEvent event) {
broadcastProgressBar.setDisable(false);
- if(headersForm.getBlockTransaction() != null) {
+ boolean serverReported = headersForm.getTransactionData().isServerReported(AppServices.get().getOpenWallets().keySet());
+ if(headersForm.getBlockTransaction() != null && !serverReported) {
updateBlockchainForm(headersForm.getBlockTransaction(), event.getBlockHeight());
+ } else if(headersForm.getPsbt() == null) {
+ //What an earlier server reported is fetched again from this one, so nothing is shown until it answers
+ verificationRequestedPair = null;
+ verificationUnprovenPair = null;
+ verificationService = null;
+ blockchainForm.setVisible(false);
}
}
### src/main/java/com/sparrowwallet/sparrow/transaction/TransactionController.java
@@ -760,6 +760,12 @@ public void transactionTabsClosed(TransactionTabsClosedEvent event) {
@Subscribe
public void newConnection(ConnectionEvent event) {
+ //The server now connected need not be the one that reported the status, so it is asked again
+ if(txdata.isServerReported(AppServices.get().getOpenWallets().keySet())) {
+ txdata.setBlockTransaction(null);
+ transactionsFetched = false;
+ }
+
if(!transactionsFetched) {
fetchTransactions();
}
### src/main/java/com/sparrowwallet/sparrow/transaction/TransactionData.java
@@ -7,6 +7,7 @@
import com.sparrowwallet.drongo.silentpayments.SilentPaymentAddress;
import com.sparrowwallet.drongo.wallet.*;
import com.sparrowwallet.sparrow.io.Storage;
+import com.sparrowwallet.sparrow.net.ElectrumServer;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableMap;
@@ -70,6 +71,18 @@ public void setBlockTransaction(BlockTransaction blockTransaction) {
this.blockTransaction = blockTransaction;
}
+ /**
+ * Whether the status held for this transaction rests only on the word of the server that reported it: not proven to be in a block, not held by an
+ * open wallet, which keeps its own copy current, and not that of a PSBT, which is never asked of a server.
+ */
+ public boolean isServerReported(Collection<Wallet> openWallets) {
+ if(blockTransaction == null || psbt != null || ElectrumServer.isProven(blockTransaction)) {
+ return false;
+ }
+
+ return openWallets.stream().noneMatch(wallet -> blockTransaction.equals(wallet.getWalletTransaction(blockTransaction.getHash())));
+ }
+
public Map<Sha256Hash, BlockTransaction> getInputTransactions() {
return inputTransactions;
}
### src/test/java/com/sparrowwallet/sparrow/net/TransactionProofTest.java
@@ -238,6 +238,15 @@ public void doesNotProveATransactionTheServerWillNotSubstantiate() throws Except
assertEquals(Set.of(reference(transaction, PROVEN_HEIGHT)), listener.getFailed());
}
+ @Test
+ public void doesNotProveATransactionWithAnEmptyProof() throws Exception {
+ Transaction transaction = blockTransactions.getFirst();
+ server.serveEmptyProof(transaction, PROVEN_HEIGHT);
+
+ assertNull(new ElectrumServer().getProvenHeader(transaction.getTxId(), PROVEN_HEIGHT));
+ assertEquals(Set.of(reference(transaction, PROVEN_HEIGHT)), listener.getRefused());
+ }
+
/**
* A server that refuses once and proves on a retry is one momentarily unable to answer rather than one contradicting itself. The tab spends the
* retry budget a wallet pass spends, so what recovers within it is never put to the user at all.
@@ -1636,6 +1645,10 @@ public TransactionMerkleProof serveProof(Transaction transaction, int height, in
return proof;
}
+ public void serveEmptyProof(Transaction transaction, int height) {
+ proofs.put(transaction.getTxId() + ":" + height, null);
+ }
+
/**
* Rewinds the header store while the next proof is in flight, which is a reorg landing between a proof being verified and being remembered.
*/
### src/test/java/com/sparrowwallet/sparrow/transaction/TransactionDataTest.java
@@ -0,0 +1,43 @@
+package com.sparrowwallet.sparrow.transaction;
+
+import com.sparrowwallet.drongo.protocol.Sha256Hash;
+import com.sparrowwallet.drongo.protocol.Transaction;
+import com.sparrowwallet.drongo.wallet.BlockTransaction;
+import com.sparrowwallet.drongo.wallet.Wallet;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+public class TransactionDataTest {
+ private static final Sha256Hash TXID = Sha256Hash.wrap("1111111111111111111111111111111111111111111111111111111111111111");
+ private static final Sha256Hash BLOCK_HASH = Sha256Hash.wrap("2222222222222222222222222222222222222222222222222222222222222222");
+
+ @Test
+ public void unprovenHeightIsServerReported() {
+ TransactionData txdata = new TransactionData("tx", new BlockTransaction(TXID, 100, null, null, new Transaction()));
+ Assertions.assertTrue(txdata.isServerReported(Collections.emptySet()));
+ }
+
+ @Test
+ public void provenHeightIsNotServerReported() {
+ TransactionData txdata = new TransactionData("tx", new BlockTransaction(TXID, 100, null, null, new Transaction(), BLOCK_HASH));
+ Assertions.assertFalse(txdata.isServerReported(Collections.emptySet()));
+ }
+
+ @Test
+ public void walletTransactionIsNotServerReported() {
+ BlockTransaction blockTransaction = new BlockTransaction(TXID, 100, null, null, new Transaction());
+ Wallet wallet = new Wallet();
+ wallet.updateTransactions(Map.of(TXID, blockTransaction));
+ TransactionData txdata = new TransactionData("tx", blockTransaction);
+ Assertions.assertFalse(txdata.isServerReported(List.of(wallet)));
+ }
+
+ @Test
+ public void noStatusIsNotServerReported() {
+ Assertions.assertFalse(new TransactionData("tx", new Transaction()).isServerReported(Collections.emptySet()));
+ }
+}Why this scored 49/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.