Merge pull request #11154 from spesmilo/make_unsigned_tx_with_base_tx
What changed, and why it matters
This commit changes how Electrum creates unsigned Bitcoin transactions when an existing 'base transaction' is provided. Previously, the wallet wrongly demanded spendable coins even when the caller supplied a base transaction that already contained inputs. The fix removes that requirement and adds a safety check to ensure the final transaction still has at least one input. In plain terms: it stops the wallet from refusing to build certain valid transactions and makes sure it cannot accidentally build a transaction with no inputs, which the Bitcoin network would reject anyway.
Review callers of make_unsigned_transaction() that pass base_tx to confirm they cannot reach the PartialTransaction constructor with tx_inputs empty, and verify the new assertion cannot be triggered through any code path. No urgent patch is indicated, but treat as a hardening change worth including in release notes.
Security signals we found
Relaxation of input-source precondition
Addition of consensus-level invariant assertion (at least one input)
Addition of empty-input guard before PartialTransaction construction
Potential for previously thrown NotEnoughFunds to be bypassed when base_tx is present
Evidence from the diff
In electrum/wallet.py’s make_unsigned_transaction(), the guard ‘if not inputs and not coins’ is extended to ‘if not inputs and not coins and not base_tx’, so a base_tx can satisfy the input requirement. A new ‘if not tx_inputs: raise NotEnoughFunds()’ is added before constructing the PartialTransaction, and an assertion ‘len(tx.inputs()) > 0’ is inserted alongside the existing outputs assertion. The change is defensive: it relaxes an overly strict precondition while preserving the consensus invariant that every transaction must have at least one input.
Changed components
electrum/wallet.pymake_unsigned_transaction()PartialTransaction construction pathInspect captured patch +4 / −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!")
@@ -2220,8 +2220,11 @@ def distribute_amount(amount):
fee = fee_estimator(tx.estimated_size())
distribute_amount(to_distribute - fee)
+ if not tx_inputs:
+ raise NotEnoughFunds()
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 40/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.