make_unsigned_transaction: do not require coins if there is a base_tx
What changed, and why it matters
This commit relaxes a wallet check when creating a new Bitcoin transaction. Previously, Electrum refused to create a transaction if the user had no spendable coins and no explicit inputs. The change allows creation to continue if a 'base transaction' is provided, because the new transaction can re-use the inputs from that base transaction (for example, to create a replacement transaction or bump the fee). The commit also adds a safety check that the final transaction still has at least one input. It appears to be a bug fix for a legitimate wallet workflow rather than a security vulnerability.
No immediate security action required. Reviewers should verify that all code paths constructing a transaction from base_tx correctly populate tx_inputs from base_tx.inputs() and that the new assertion cannot be bypassed. Consider whether any caller can reach the assertion with zero inputs due to an empty base_tx, which would raise an AssertionError rather than the previous NotEnoughFunds exception.
Security signals we found
Relaxation of input/coin availability guard
Addition of post-construction input count assertion
Potential workflow: Replace-By-Fee (RBF) or transaction bumping using base_tx inputs
Evidence from the diff
In electrum/wallet.py’s make_unsigned_transaction(), the guard ‘if not inputs and not coins: raise NotEnoughFunds()’ is changed to ‘if not inputs and not coins and not base_tx: raise NotEnoughFunds()’. This permits the method to proceed when base_tx is supplied, since tx_inputs can be derived from base_tx.inputs() later in the function. An assertion ‘assert len(tx.inputs()) > 0’ is added after the transaction is constructed to enforce the consensus rule that every transaction must have at least one input. The change fixes a false-positive NotEnoughFunds error for RBF/fee-bump workflows that supply a base_tx but no new coins.
Changed components
electrum/wallet.pymake_unsigned_transaction()Inspect captured patch +2 / −1
### electrum/wallet.py
@@ -2059,7 +2059,7 @@ def make_unsigned_transaction(
if coins is None:
coins = self.get_spendable_coins()
- if not inputs and not coins: # any bitcoin tx must have at least 1 input by consensus
+ if not inputs and not coins and not base_tx: # any bitcoin tx must have at least 1 input by consensus
raise NotEnoughFunds()
if any([c.already_has_some_signatures() for c in coins]):
raise Exception("Some inputs already contain signatures!")
@@ -2222,6 +2222,7 @@ def distribute_amount(amount):
tx = PartialTransaction.from_io(list(tx_inputs), list(outputs))
+ assert len(tx.inputs()) > 0, "any bitcoin tx must have at least 1 input by consensus"
assert len(tx.outputs()) > 0, "any bitcoin tx must have at least 1 output by consensus"
if locktime is None:
# Timelock tx to current height.Why this scored 29/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.