widen stored transactions to the consensus maximum size and skip larger ones fetched from the server
What changed, and why it matters
This commit makes Sparrow Wallet better handle unusually large Bitcoin transactions. It widens the database column that stores raw transaction bytes from 1 MB to 4 MB (the largest size Bitcoin consensus allows), and tells the wallet to skip any transaction fetched from an Electrum server that is larger than that maximum. It also avoids treating a special 'unfetchable' placeholder transaction as a real transaction when building wallet history. The changes appear defensive: they prevent the wallet from crashing or misbehaving when it encounters oversized transactions, and stop a malicious or buggy server from feeding a response larger than a valid Bitcoin transaction.
Treat as a defensive hardening patch. Review whether the 2*MAX_BLOCK_SIZE_VBYTES*WITNESS_SCALE_FACTOR bound is intended to cover hex-encoded size or raw bytes (the variable is named strRawTx and compared to a vbyte-based limit), and verify the SQL migration is applied cleanly for existing users. No immediate incident response is indicated, but users relying on older builds should upgrade to avoid possible crashes or mis-accounting when oversized transactions are encountered.
Security signals we found
Server response size bound added before transaction parsing
Sentinel/placeholder transaction excluded from history and input resolution
Database storage limit raised to consensus maximum transaction size
Potential denial-of-service vector from oversized transaction responses mitigated
Evidence from the diff
The patch does three things: (1) in ElectrumServer.java, it skips processing when a cached BlockTransaction is the sentinel UNFETCHABLE_BLOCK_TRANSACTION, both for top-level history entries and for input prevouts; (2) it adds a server-response size check against 2 * MAX_BLOCK_SIZE_VBYTES * WITNESS_SCALE_FACTOR before parsing a hex transaction, logging an error and continuing if the server returns something larger than the consensus maximum transaction size; (3) it updates the SQL migration to set blockTransaction.transaction to varbinary(4000000) (4 MB), matching the consensus maximum. TcpTransport.java only gets a comment update; its 256 MB response buffer is left unchanged. The commit is therefore a hardening fix rather than a feature addition.
Changed components
src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.javasrc/main/java/com/sparrowwallet/sparrow/net/TcpTransport.javasrc/main/resources/com/sparrowwallet/sparrow/sql/V11__TransactionMetadata.sqlInspect captured patch +11 / −3
### src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java
@@ -695,7 +695,7 @@ public Map<WalletNode, Set<BlockTransactionHash>> getHistory(Wallet wallet, Coll
Map<String, WalletNode> walletScriptHashes = getAllScriptHashes(wallet);
for(BlockTransactionHash reference : newReferences) {
BlockTransaction blockTransaction = wallet.getTransactions().get(reference.getHash());
- if(blockTransaction == null) {
+ if(blockTransaction == null || blockTransaction.equals(UNFETCHABLE_BLOCK_TRANSACTION)) {
continue;
}
@@ -708,7 +708,7 @@ public Map<WalletNode, Set<BlockTransactionHash>> getHistory(Wallet wallet, Coll
for(TransactionInput txInput : blockTransaction.getTransaction().getInputs()) {
BlockTransaction inputBlockTransaction = wallet.getTransactions().get(txInput.getOutpoint().getHash());
- if(inputBlockTransaction != null) {
+ if(inputBlockTransaction != null && !inputBlockTransaction.equals(UNFETCHABLE_BLOCK_TRANSACTION)) {
TransactionOutput txOutput = inputBlockTransaction.getTransaction().getOutputs().get((int)txInput.getOutpoint().getIndex());
WalletNode node = walletScriptHashes.get(getScriptHash(txOutput));
if(node != null && !historyNodes.contains(node)) {
@@ -2134,6 +2134,11 @@ public Map<Sha256Hash, BlockTransaction> getTransactions(Wallet wallet, Map<Bloc
continue;
}
+ if(strRawTx.length() > 2L * Transaction.MAX_BLOCK_SIZE_VBYTES * Transaction.WITNESS_SCALE_FACTOR) {
+ log.error("Server returned transaction " + hash + " larger than the maximum block size");
+ continue;
+ }
+
Transaction transaction;
try {
### src/main/java/com/sparrowwallet/sparrow/net/TcpTransport.java
@@ -40,7 +40,7 @@ public class TcpTransport implements CloseableTransport, TimeoutCounter {
private static final int[] SLOW_READ_TIMEOUT_SECS = {34, 68, 124, 208};
public static final long PER_REQUEST_READ_TIMEOUT_MILLIS = 50;
public static final int SOCKET_READ_TIMEOUT_MILLIS = 5000;
- private static final int MAX_RESPONSE_CHARS = 256 * 1024 * 1024; //Above a default page of transactions at the 1MB stored transaction limit, as hex
+ private static final int MAX_RESPONSE_CHARS = 256 * 1024 * 1024; //Above a default page of 1MB transactions as hex, and many times the largest valid transaction
private static final Pattern ID_PATTERN = Pattern.compile("\"id\"\\s*:\\s*(\\d+)");
private static final JsonFactory JSON_FACTORY = new JsonFactory();
### src/main/resources/com/sparrowwallet/sparrow/sql/V11__TransactionMetadata.sql
@@ -0,0 +1,3 @@
+create table externalOutputLabel (txid binary(32) not null, index bigint not null, label varchar(255) not null, primary key (txid, index));
+create table fiatRate (txid binary(32) not null, currency varchar(3) not null, rate varchar(40) not null, source integer not null, primary key (txid, currency));
+alter table blockTransaction alter column transaction set data type varbinary(4000000);
\ No newline at end of fileWhy 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.