give the transaction tab a copy of a wallet transaction, and leave locktimes and input sequences unchanged as the tab opens
What changed, and why it matters
This commit fixes a bug in the Sparrow Wallet desktop app where merely opening a transaction to view it could silently alter the wallet's stored copy of that transaction. Previously, the transaction tab shared the same in-memory object as the wallet, and the tab's user-interface setup code would overwrite locktime and input sequence values with defaults. The fix makes a defensive copy before opening the tab and only writes changes when the user actually interacts with the controls.
Users should upgrade to a Sparrow Wallet release that includes this commit. Until then, avoid opening the transaction tab for transactions whose locktime or sequence settings must remain unchanged, and verify transaction details before signing or broadcasting. Developers should audit other controllers for similar shared-object mutation patterns during view initialization.
Security signals we found
UI initialization code mutates shared transaction object before user interaction
Wallet transaction object and transaction-tab object were the same reference
Locktime and input sequence defaults could overwrite user/wallet-defined values on tab open
Defensive deep copy added to separate wallet state from UI state
Regression test added to enforce isolation between viewed and wallet transaction copies
Evidence from the diff
The patch addresses two related issues in the transaction viewing/editing flow. First, TransactionData now clones the wallet’s Transaction via bitcoinSerialize() when constructed from a BlockTransaction, preventing the UI from mutating the wallet’s canonical transaction object. Second, HeadersController and InputController now guard locktime and sequence-number writes so that initial control selection populates the view without calling setTransactionLocktime/setInputSequenceNumber; those mutators are only invoked when the user changes the toggle (old_toggle != null). A regression test verifies that the viewed transaction is a distinct object and that changing its locktime does not affect the wallet’s copy.
Changed components
Sparrow Wallet desktop applicationTransaction tab / transaction viewerHeadersController locktime UI handlingInputController sequence/locktime UI handlingTransactionData BlockTransaction constructorInspect captured patch +39 / −18
### src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java
@@ -319,14 +319,15 @@ private void initializeView() {
if(new_toggle == null) {
old_toggle.setSelected(true);
} else {
+ //The first selection shows the locktime the transaction already has, so neither it nor a PSBT's fallback locktime is written until the selection changes
String selection = locktimeToggleGroup.getSelectedToggle().getUserData().toString();
if(selection.equals("none")) {
locktimeFieldset.getChildren().remove(locktimeDateField);
locktimeFieldset.getChildren().remove(locktimeBlockField);
locktimeFieldset.getChildren().remove(locktimeNoneField);
locktimeFieldset.getChildren().add(locktimeNoneField);
- setTransactionLocktime(tx, 0);
if(old_toggle != null) {
+ setTransactionLocktime(tx, 0);
EventManager.get().post(new TransactionChangedEvent(tx));
}
} else if(selection.equals("block")) {
@@ -338,8 +339,8 @@ private void initializeView() {
if(block != null) {
locktimeCurrentHeight.setVisible(headersForm.isEditable() && AppServices.getCurrentBlockHeight() != null && block < AppServices.getCurrentBlockHeight());
futureBlockWarning.setVisible(AppServices.getCurrentBlockHeight() != null && block > AppServices.getCurrentBlockHeight());
- setTransactionLocktime(tx, block);
if(old_toggle != null) {
+ setTransactionLocktime(tx, block);
EventManager.get().post(new TransactionChangedEvent(tx));
}
}
@@ -352,8 +353,8 @@ private void initializeView() {
if(date != null) {
locktimeDate.setDateTimeValue(date);
futureDateWarning.setVisible(date.isAfter(LocalDateTime.now()));
- setTransactionLocktime(tx, date.atZone(ZoneId.systemDefault()).toEpochSecond());
if(old_toggle != null) {
+ setTransactionLocktime(tx, date.atZone(ZoneId.systemDefault()).toEpochSecond());
EventManager.get().post(new TransactionChangedEvent(tx));
}
}
### src/main/java/com/sparrowwallet/sparrow/transaction/InputController.java
@@ -391,13 +391,16 @@ private void initializeLocktimeFields(TransactionInput txInput) {
if(new_toggle == null) {
old_toggle.setSelected(true);
} else {
+ //The first selection shows the sequence the input already has, which is not written until the selection changes
String selection = locktimeToggleGroup.getSelectedToggle().getUserData().toString();
if(selection.equals("none")) {
locktimeFieldset.getChildren().removeAll(locktimeRelativeField, locktimeAbsoluteField);
locktimeFieldset.getChildren().add(locktimeAbsoluteField);
updateAbsoluteLocktimeField(transaction);
locktimeAbsoluteField.setDisable(true);
- setInputSequenceNumber(txInput, TransactionInput.SEQUENCE_LOCKTIME_DISABLED);
+ if(old_toggle != null) {
+ setInputSequenceNumber(txInput, TransactionInput.SEQUENCE_LOCKTIME_DISABLED);
+ }
rbf.setSelected(false);
if(old_toggle != null) {
EventManager.get().post(new TransactionChangedEvent(transaction));
@@ -407,22 +410,17 @@ private void initializeLocktimeFields(TransactionInput txInput) {
locktimeFieldset.getChildren().add(locktimeAbsoluteField);
updateAbsoluteLocktimeField(transaction);
locktimeAbsoluteField.setDisable(false);
- if(rbf.selectedProperty().getValue()) {
- setInputSequenceNumber(txInput, TransactionInput.SEQUENCE_RBF_ENABLED);
- } else {
- setInputSequenceNumber(txInput, TransactionInput.SEQUENCE_RBF_DISABLED);
- }
if(old_toggle != null) {
+ setInputSequenceNumber(txInput, rbf.selectedProperty().getValue() ? TransactionInput.SEQUENCE_RBF_ENABLED : TransactionInput.SEQUENCE_RBF_DISABLED);
EventManager.get().post(new TransactionChangedEvent(transaction));
}
} else {
locktimeFieldset.getChildren().removeAll(locktimeRelativeField, locktimeAbsoluteField);
locktimeFieldset.getChildren().add(locktimeRelativeField);
if(locktimeRelativeCombo.getValue() == null) {
locktimeRelativeCombo.getSelectionModel().select(0);
- } else {
- setRelativeLocktime(txInput, transaction, old_toggle != null);
}
+ setRelativeLocktime(txInput, transaction, old_toggle != null);
rbf.setSelected(true);
}
}
@@ -486,6 +484,10 @@ private void updateAbsoluteLocktimeField(Transaction transaction) {
}
private void setRelativeLocktime(TransactionInput txInput, Transaction transaction, boolean changed) {
+ if(!changed) {
+ return;
+ }
+
String relativeSelection = locktimeRelativeCombo.getValue();
if(relativeSelection.equals("blocks")) {
Integer value = locktimeRelativeBlocks.getValue();
@@ -494,9 +496,7 @@ private void setRelativeLocktime(TransactionInput txInput, Transaction transacti
long value = locktimeRelativeSeconds.getValue().toSeconds() / TransactionInput.RELATIVE_TIMELOCK_SECONDS_INCREMENT;
setInputSequenceNumber(txInput, (value & TransactionInput.RELATIVE_TIMELOCK_VALUE_MASK) | TransactionInput.RELATIVE_TIMELOCK_TYPE_FLAG);
}
- if(changed) {
- EventManager.get().post(new TransactionChangedEvent(transaction));
- }
+ EventManager.get().post(new TransactionChangedEvent(transaction));
}
public void setModel(InputForm form) {
### src/main/java/com/sparrowwallet/sparrow/transaction/TransactionData.java
@@ -38,7 +38,8 @@ public TransactionData(String name, PSBT psbt) {
}
public TransactionData(String name, BlockTransaction blockTransaction) {
- this(name, blockTransaction.getTransaction());
+ //Viewing a transaction must not be able to change the copy the wallet stores
+ this(name, blockTransaction.getTransaction() == null ? null : new Transaction(blockTransaction.getTransaction().bitcoinSerialize()));
this.blockTransaction = blockTransaction;
}
### src/test/java/com/sparrowwallet/sparrow/transaction/TransactionDataTest.java
@@ -1,5 +1,6 @@
package com.sparrowwallet.sparrow.transaction;
+import com.sparrowwallet.drongo.protocol.Script;
import com.sparrowwallet.drongo.protocol.Sha256Hash;
import com.sparrowwallet.drongo.protocol.Transaction;
import com.sparrowwallet.drongo.wallet.BlockTransaction;
@@ -15,27 +16,45 @@ public class TransactionDataTest {
private static final Sha256Hash TXID = Sha256Hash.wrap("1111111111111111111111111111111111111111111111111111111111111111");
private static final Sha256Hash BLOCK_HASH = Sha256Hash.wrap("2222222222222222222222222222222222222222222222222222222222222222");
+ private static Transaction getTransaction() {
+ Transaction transaction = new Transaction();
+ transaction.addInput(BLOCK_HASH, 0, new Script(new byte[0]));
+ transaction.addOutput(1000, new Script(new byte[] {0x51}));
+ return transaction;
+ }
+
@Test
public void unprovenHeightIsServerReported() {
- TransactionData txdata = new TransactionData("tx", new BlockTransaction(TXID, 100, null, null, new Transaction()));
+ TransactionData txdata = new TransactionData("tx", new BlockTransaction(TXID, 100, null, null, getTransaction()));
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));
+ TransactionData txdata = new TransactionData("tx", new BlockTransaction(TXID, 100, null, null, getTransaction(), BLOCK_HASH));
Assertions.assertFalse(txdata.isServerReported(Collections.emptySet()));
}
@Test
public void walletTransactionIsNotServerReported() {
- BlockTransaction blockTransaction = new BlockTransaction(TXID, 100, null, null, new Transaction());
+ BlockTransaction blockTransaction = new BlockTransaction(TXID, 100, null, null, getTransaction());
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 viewedTransactionIsNotTheWalletCopy() {
+ BlockTransaction blockTransaction = new BlockTransaction(TXID, 100, null, null, getTransaction());
+ TransactionData txdata = new TransactionData("tx", blockTransaction);
+ Assertions.assertNotSame(blockTransaction.getTransaction(), txdata.getTransaction());
+ Assertions.assertEquals(blockTransaction.getTransaction().getTxId(), txdata.getTransaction().getTxId());
+
+ txdata.getTransaction().setLocktime(500);
+ Assertions.assertEquals(0, blockTransaction.getTransaction().getLocktime());
+ }
+
@Test
public void noStatusIsNotServerReported() {
Assertions.assertFalse(new TransactionData("tx", new Transaction()).isServerReported(Collections.emptySet()));Why this scored 61/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.