Total verified_input_amount in _verify_input_amounts()
What changed, and why it matters
This commit renames and strengthens how SeedSigner totals the amount of bitcoin coming into a transaction. Previously, the wallet summed input amounts in a later step after a separate verification step. The change makes the verified total the only value used for display, so a malicious or buggy coordinator cannot trick the user into thinking a transaction has different inputs or fees than it really does. It is a defensive hardening patch, not a fix for a known active exploit.
Review as a security-hardening improvement. Ensure the removed 'continue' does not break legitimate PSBTs that previously parsed successfully. Consider whether the change warrants a changelog note for users relying on coordinator software that omits non_witness_utxo for non-segwit inputs.
Security signals we found
Defensive hardening against coordinator-supplied false input amounts (miner-fee attack)
Single source of truth for displayed input total now derived only after per-input verification
Removal of 'continue' in _verify_input_amounts() changes skip behavior to fail-closed for unverifiable non-segwit inputs
UI now consumes verified_input_amount instead of input_amount
No CVE, advisory, or vendor security disclosure referenced in commit
Evidence from the diff
The patch moves input-amount summing from _parse_inputs() into _verify_input_amounts() and renames the field from input_amount to verified_input_amount. The total is now only assigned after every input has passed verification, and the UI now displays verified_input_amount. A subtle logic change removes a ‘continue’ after the uncommitted-amount-script-type check, so non-segwit inputs without a non_witness_utxo now raise PSBTInputAmountVerificationError instead of being silently skipped. Tests are updated to assert the new field name and behavior.
Changed components
src/seedsigner/models/psbt_parser.pysrc/seedsigner/views/psbt_views.pytests/test_decodepsbtqr.pytests/test_psbt_parser.pyInspect captured patch +35 / −34
### src/seedsigner/models/psbt_parser.py
@@ -181,7 +181,7 @@ def __init__(self, p: PSBT, seed: Seed, network: str = SettingsConstants.MAINNET
self.change_amount = 0
self.change_data = []
self.fee_amount = 0
- self.input_amount = 0
+ self.verified_input_amount = 0
self.num_inputs = 0
self.destination_addresses = []
self.destination_amounts = []
@@ -246,11 +246,10 @@ def parse(self):
inputs can be signed by the seed. A mismatch rather than an attack, caught
here so the flow can say so before showing a transaction.
- 4. _verify_input_amounts: raises PSBTInputAmountVerificationError when an input's
- claimed amount cannot be verified against a non_witness_utxo. Runs after the
- ownership checks so a psbt this seed cannot sign is reported as a mismatch
- rather than as a suspicious transaction, but before _parse_inputs, which is
- where amounts are first summed.
+ 4. _verify_input_amounts: verifies each input's claimed amount, then totals them
+ as verified_input_amount. Raises PSBTInputAmountVerificationError if an amount
+ cannot be verified. Runs after the ownership checks so a psbt this seed cannot
+ sign is reported as a mismatch rather than as a suspicious transaction.
5. _parse_inputs: every input must resolve to the same policy otherwise a
RuntimeError is raised. TODO: make this a PSBTVerificationError subclass so
@@ -316,7 +315,7 @@ def parse(self):
self._verify_claimed_derivation_paths(child_key_derivation_cache)
self._reject_if_seed_cannot_sign()
- # Single source of truth for input amounts; raises before any amount is summed
+ # Single source of truth for input amounts: each is verified before it is totaled
self._verify_input_amounts()
rt = self._parse_inputs(child_key_derivation_cache)
@@ -335,7 +334,7 @@ def parse(self):
def _verify_input_amounts(self):
"""
- Verify each input's declared amount before any of them is summed. Since seedsigner is
+ Verify each input's declared amount before it is added to the total. Since seedsigner is
airgapped, we can't look up what an input is actually worth. We're relying on what the
coordinator declared. Unchecked, a compromised coordinator could declare false amounts
and have us display any fee it liked. See the miner fee attack described in embit's
@@ -361,6 +360,7 @@ def _verify_input_amounts(self):
on it would therefore fire on nearly every ordinary multi-input segwit spend and only
teach users to click through warnings.
"""
+ verified_input_amount = 0
for i, inp in enumerate(self.psbt.inputs):
# Make sure inp.vout, the output this input claims to spend, actually exists in the
# non_witness_utxo. Otherwise the lookups below raise an IndexError instead of
@@ -382,7 +382,6 @@ def _verify_input_amounts(self):
script_type = PSBTParser._get_script_type(inp, inp.script_pubkey)
if script_type in PSBTParser.UNCOMMITTED_AMOUNT_SCRIPT_TYPES:
raise PSBTInputAmountVerificationError(f"Input {i}: {script_type} input has no non_witness_utxo to verify against")
- continue
# verify() hashes the non_witness_utxo but never looks at the witness_utxo that may
# sit alongside it. embit's PSBT.utxo()/fee() prefer witness_utxo, so a witness_utxo
@@ -394,17 +393,19 @@ def _verify_input_amounts(self):
if prevout.value != inp.witness_utxo.value or prevout.script_pubkey.data != inp.witness_utxo.script_pubkey.data:
raise PSBTInputAmountVerificationError(f"Input {i}: witness_utxo doesn't match verified non_witness_utxo")
+ verified_input_amount += inp.utxo.value
+
+ # Only assigned once every input has passed, so a rejected psbt leaves no partial total
+ self.verified_input_amount = verified_input_amount
+
def _parse_inputs(self, child_key_derivation_cache: dict):
"""
- Totals the input amounts and determines the wallet policy. Every input must
- resolve to the same policy, otherwise a RuntimeError is raised.
+ Determines the wallet policy. Every input must resolve to the same policy,
+ otherwise a RuntimeError is raised.
"""
- self.input_amount = 0
self.num_inputs = len(self.psbt.inputs)
for inp in self.psbt.inputs:
- # Amounts were verified in _verify_input_amounts()
- self.input_amount += inp.utxo.value
script_pubkey = inp.script_pubkey
inp_policy = PSBTParser._get_policy(inp, script_pubkey, self.psbt.xpubs, child_key_derivation_cache)
### src/seedsigner/views/psbt_views.py
@@ -302,7 +302,7 @@ def run(self):
selected_menu_num = self.run_screen(
PSBTMathScreen,
- input_amount=psbt_parser.input_amount,
+ input_amount=psbt_parser.verified_input_amount,
num_inputs=psbt_parser.num_inputs,
spend_amount=psbt_parser.spend_amount,
num_recipients=psbt_parser.num_destinations,
### tests/test_decodepsbtqr.py
@@ -144,7 +144,7 @@ def test_base64_2_input_p2wsh():
assert tx.inputs[1].witness_utxo.value == 10000000 # input amount 2 in psbt
- assert pp.input_amount == 20000000
+ assert pp.verified_input_amount == 20000000
assert (pp.spend_amount + pp.change_amount + pp.fee_amount) == 20000000
@@ -169,7 +169,7 @@ def test_base64_1_input_p2sh_p2wsh():
assert tx.inputs[0].witness_utxo.value == 100000000 # input amount 1 in psbt
- assert pp.input_amount == 100000000
+ assert pp.verified_input_amount == 100000000
assert (pp.spend_amount + pp.change_amount + pp.fee_amount) == 100000000
@@ -201,7 +201,7 @@ def test_specter_multisig_animated_qr():
mnemonic = "zone zone zone zone zone abandon ability able abandon ability able abstract".split()
pp = PSBTParser(p=tx, seed=Seed(mnemonic), network=SettingsConstants.TESTNET)
- assert pp.input_amount == 1052818
+ assert pp.verified_input_amount == 1052818
assert pp.change_amount == 0
@@ -239,7 +239,7 @@ def test_specter_multisig_animated_qr():
mnemonic2 = "able bacon cable able bacon cable abandon abandon abandon abandon abandon access".split()
pp2 = PSBTParser(p=tx2, seed=Seed(mnemonic2), network=SettingsConstants.TESTNET)
- assert pp2.input_amount == 1052818
+ assert pp2.verified_input_amount == 1052818
assert pp2.change_amount == 0
### tests/test_psbt_parser.py
@@ -54,13 +54,13 @@ def run_basic_test(self, psbt_base64: str, change_data: str, self_transfer_data:
assert len(psbt.outputs) == 2
psbt_parser = PSBTParser(p=psbt, seed=self.seed, network=SettingsConstants.REGTEST)
assert psbt_parser.num_inputs == len(psbt.inputs)
- assert psbt_parser.input_amount == input_amount
+ assert psbt_parser.verified_input_amount == input_amount
assert psbt_parser.num_destinations == 1
assert psbt_parser.num_change_outputs == 1
assert psbt_parser.spend_amount == recipient_amount
assert psbt_parser.change_amount == input_amount - recipient_amount - fee_amount
assert psbt_parser.fee_amount == fee_amount
- assert psbt_parser.input_amount == psbt_parser.spend_amount + psbt_parser.change_amount + psbt_parser.fee_amount
+ assert psbt_parser.verified_input_amount == psbt_parser.spend_amount + psbt_parser.change_amount + psbt_parser.fee_amount
# No self-transfer here, so all change is true change
assert psbt_parser.get_total_output_value() == psbt_parser.spend_amount
@@ -73,13 +73,13 @@ def run_basic_test(self, psbt_base64: str, change_data: str, self_transfer_data:
assert len(psbt.outputs) == 1
psbt_parser = PSBTParser(p=psbt, seed=self.seed, network=SettingsConstants.REGTEST)
assert psbt_parser.num_inputs == len(psbt.inputs)
- assert psbt_parser.input_amount == input_amount
+ assert psbt_parser.verified_input_amount == input_amount
assert psbt_parser.num_destinations == 0 # No external recipients == no destinations
assert psbt_parser.num_change_outputs == 1 # PSBTParser considers self-transfers == change
assert psbt_parser.spend_amount == 0 # No external recipients == nothing spent (ignores fee)
assert psbt_parser.change_amount == input_amount - fee_amount # PSBTParser considers self-transfers == change
assert psbt_parser.fee_amount == fee_amount
- assert psbt_parser.input_amount == psbt_parser.spend_amount + psbt_parser.change_amount + psbt_parser.fee_amount
+ assert psbt_parser.verified_input_amount == psbt_parser.spend_amount + psbt_parser.change_amount + psbt_parser.fee_amount
# Only self-transfer, and no "true" change, so `change_amount` is included in total output
# Both calls should return the same value
@@ -97,13 +97,13 @@ def run_basic_test(self, psbt_base64: str, change_data: str, self_transfer_data:
assert len(psbt.outputs) == 1
psbt_parser = PSBTParser(p=psbt, seed=self.seed, network=SettingsConstants.REGTEST)
assert psbt_parser.num_inputs == len(psbt.inputs)
- assert psbt_parser.input_amount == input_amount
+ assert psbt_parser.verified_input_amount == input_amount
assert psbt_parser.num_destinations == 1
assert psbt_parser.num_change_outputs == 0
assert psbt_parser.spend_amount == recipient_amount
assert psbt_parser.change_amount == 0
assert psbt_parser.fee_amount == fee_amount
- assert psbt_parser.input_amount == psbt_parser.spend_amount + psbt_parser.change_amount + psbt_parser.fee_amount
+ assert psbt_parser.verified_input_amount == psbt_parser.spend_amount + psbt_parser.change_amount + psbt_parser.fee_amount
# No self-transfer here, so all change is true change
assert psbt_parser.get_total_output_value() == psbt_parser.spend_amount
@@ -123,13 +123,13 @@ def run_basic_test(self, psbt_base64: str, change_data: str, self_transfer_data:
assert len(psbt.outputs) == len(PSBTTestData.ALL_EXTERNAL_OUTPUTS) + 1
psbt_parser = PSBTParser(p=psbt, seed=self.seed, network=SettingsConstants.REGTEST)
assert psbt_parser.num_inputs == len(psbt.inputs)
- assert psbt_parser.input_amount == input_amount
+ assert psbt_parser.verified_input_amount == input_amount
assert psbt_parser.num_destinations == len(PSBTTestData.ALL_EXTERNAL_OUTPUTS)
assert psbt_parser.num_change_outputs == 1
assert psbt_parser.spend_amount == input_amount - change_amount - fee_amount
assert psbt_parser.change_amount == change_amount
assert psbt_parser.fee_amount == fee_amount
- assert psbt_parser.input_amount == psbt_parser.spend_amount + psbt_parser.change_amount + psbt_parser.fee_amount
+ assert psbt_parser.verified_input_amount == psbt_parser.spend_amount + psbt_parser.change_amount + psbt_parser.fee_amount
# No self-transfer here, so all change is true change
assert psbt_parser.get_total_output_value() == psbt_parser.spend_amount
@@ -519,17 +519,17 @@ def test_untampered_psbts_verify(self, psbt_base64: str):
is_verified is the assertion that carries the weight here. It is only set by embit's
InputScope.verify(), so it is the one flag that distinguishes "we hashed the previous
- tx ourselves" from "we took the coordinator's word for it". input_amount alone would
- hold with or without _verify_input_amounts(), since _parse_inputs() sums inp.utxo.value
- either way.
+ tx ourselves" from "we took the coordinator's word for it". verified_input_amount
+ alone can't tell those apart: it is totaled the same way for a segwit input that was
+ accepted with no non_witness_utxo to hash.
"""
psbt = self.build_psbt(psbt_base64)
assert all(inp.is_verified == False for inp in psbt.inputs) # not verified until we do it
psbt_parser = self.parse(psbt)
assert all(inp.is_verified for inp in psbt.inputs)
- assert psbt_parser.input_amount == sum([inp.utxo.value for inp in psbt.inputs])
+ assert psbt_parser.verified_input_amount == sum([inp.utxo.value for inp in psbt.inputs])
@pytest.mark.parametrize("psbt_base64", PSBTTestData.ALL_INPUTS)
@@ -636,7 +636,7 @@ def test_segwit_input_without_non_witness_utxo_is_allowed(self, psbt_base64: str
psbt = self.build_psbt(psbt_base64)
psbt.inputs[0].non_witness_utxo = None
- assert self.parse(psbt).input_amount == psbt.inputs[0].witness_utxo.value
+ assert self.parse(psbt).verified_input_amount == psbt.inputs[0].witness_utxo.value
def test_input_with_no_utxo_data_raises(self):
@@ -689,7 +689,7 @@ def test_every_input_is_checked_not_just_the_first(self):
# Untampered, both inputs verify and their amounts are summed
psbt_parser = PSBTParser(p=psbt, seed=PSBTTestData.two_input_seed, network=SettingsConstants.REGTEST)
assert psbt_parser.num_inputs == 2
- assert psbt_parser.input_amount == 56_522_834 + 1_990_245_069
+ assert psbt_parser.verified_input_amount == 56_522_834 + 1_990_245_069
psbt.inputs[1].non_witness_utxo.vout[0].value += 100_000
@@ -903,7 +903,7 @@ def assert_same_parse_result(self, parser_a: PSBTParser, parser_b: PSBTParser):
psbt is compared too, not just the parser's own attributes.
"""
assert parser_a.policy == parser_b.policy
- assert parser_a.input_amount == parser_b.input_amount
+ assert parser_a.verified_input_amount == parser_b.verified_input_amount
assert parser_a.spend_amount == parser_b.spend_amount
assert parser_a.change_amount == parser_b.change_amount
assert parser_a.fee_amount == parser_b.fee_amountWhy this scored 59/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.