From a4e79c8b6aa54fcd9eb3863918f3aa678e1d1bf5 Mon Sep 17 00:00:00 2001 From: 3rd Iteration Date: Fri, 18 Sep 2026 08:22:02 -0400 Subject: [PATCH 1/4] test+fix: resync psbt_faker corpus and close the gaps it exposes Re-vendor the regenerated psbt_faker corpus (97 vectors, fixed BIP-371 taproot encoding) and cover every vector in psbt_suite_util. Parser fixes for vectors that previously parsed: - FORGED_OUTPUT_OWNERSHIP also when a genuine key of ours annotates an output whose script does not pay it (TX-21.claims_us_pays_other, TX-21.ms_repointed_*, TX-22.ms_decoy_*). - MISLABELED_OUTPUT_OWNERSHIP: an output paying our key but attributed to a foreign fingerprint (TX-21.pays_us_claims_other, taproot_claims_other, ms_fp_relabeled). - SURPLUS_DERIVATIONS / MIXED_DERIVATION_MAPS for contradictory claims (TX-22.surplus_paths, taproot_surplus_internal_key, mixed_path_maps*). - SCRIPT_TIMELOCK warning for CLTV/CSV in an output's committed script (TX-20.cltv_time). - verify_multisig_output checks every derivation entry instead of embit's first-match Descriptor.owns (decoy-last used to verify as ours). TX-20.cltv_height/csv_relative are vacuous upstream (scriptPubKey is still p2wpkh) and marked so. Co-Authored-By: Claude Opus 5 --- src/seedsigner/models/psbt_parser.py | 298 ++++++++++++- src/seedsigner/views/psbt_views.py | 31 ++ .../data/psbt_test_suite/NORMAL-1_p2wpkh.psbt | Bin 329 -> 329 bytes .../psbt_test_suite/NORMAL-1_p2wpkh_V2.psbt | Bin 363 -> 363 bytes .../psbt_test_suite/NORMAL-2_wrapped.psbt | Bin 358 -> 358 bytes .../psbt_test_suite/NORMAL-2_wrapped_V2.psbt | Bin 392 -> 392 bytes .../data/psbt_test_suite/NORMAL-3_legacy.psbt | Bin 339 -> 339 bytes .../psbt_test_suite/NORMAL-3_legacy_V2.psbt | Bin 373 -> 373 bytes .../psbt_test_suite/NORMAL-4_multi_input.psbt | Bin 601 -> 601 bytes .../NORMAL-4_multi_input_V2.psbt | Bin 651 -> 651 bytes tests/data/psbt_test_suite/PROVENANCE.md | 23 + tests/data/psbt_test_suite/TX-01.psbt | Bin 333 -> 333 bytes tests/data/psbt_test_suite/TX-02.psbt | Bin 360 -> 360 bytes tests/data/psbt_test_suite/TX-03.bare.psbt | Bin 329 -> 329 bytes .../psbt_test_suite/TX-03.fee_inflate.psbt | Bin 336 -> 336 bytes .../psbt_test_suite/TX-03.fee_inflate_V2.psbt | Bin 363 -> 363 bytes tests/data/psbt_test_suite/TX-04.psbt | Bin 0 -> 1377 bytes tests/data/psbt_test_suite/TX-05.psbt | Bin 0 -> 1149 bytes .../data/psbt_test_suite/TX-06.branch127.psbt | Bin 329 -> 329 bytes tests/data/psbt_test_suite/TX-06.depth6.psbt | Bin 333 -> 333 bytes .../psbt_test_suite/TX-08.ANYONECANPAY.psbt | Bin 283 -> 283 bytes tests/data/psbt_test_suite/TX-08.NONE.psbt | Bin 283 -> 283 bytes .../data/psbt_test_suite/TX-08.NONE_ACP.psbt | Bin 283 -> 283 bytes tests/data/psbt_test_suite/TX-08.SINGLE.psbt | Bin 283 -> 283 bytes .../psbt_test_suite/TX-08.SINGLE_ACP.psbt | Bin 283 -> 283 bytes .../TX-09.attacker_internal_key.psbt | Bin 322 -> 346 bytes .../psbt_test_suite/TX-09.hidden_taptree.psbt | Bin 408 -> 406 bytes tests/data/psbt_test_suite/TX-10.psbt | Bin 336 -> 336 bytes .../psbt_test_suite/TX-11.v0_bech32m.psbt | Bin 444 -> 444 bytes .../data/psbt_test_suite/TX-11.v1_bech32.psbt | Bin 506 -> 507 bytes tests/data/psbt_test_suite/TX-12.psbt | Bin 367 -> 367 bytes .../data/psbt_test_suite/TX-13.duplicate.psbt | Bin 0 -> 1021 bytes tests/data/psbt_test_suite/TX-13.reorder.psbt | Bin 0 -> 1149 bytes .../psbt_test_suite/TX-13.substitute.psbt | Bin 0 -> 1149 bytes .../data/psbt_test_suite/TX-13.threshold.psbt | Bin 0 -> 1149 bytes .../data/psbt_test_suite/TX-14.cross_net.psbt | Bin 329 -> 336 bytes .../data/psbt_test_suite/TX-15.mismatch.psbt | Bin 329 -> 329 bytes .../TX-16.foreign_fingerprint.psbt | Bin 384 -> 384 bytes .../TX-16.global_xpub_injected.psbt | Bin 445 -> 445 bytes .../psbt_test_suite/TX-16.unknown_field.psbt | Bin 361 -> 361 bytes tests/data/psbt_test_suite/TX-17.psbt | Bin 329 -> 329 bytes tests/data/psbt_test_suite/TX-18.psbt | Bin 337 -> 337 bytes .../psbt_test_suite/TX-19.height_far.psbt | Bin 0 -> 329 bytes .../psbt_test_suite/TX-19.height_far_V2.psbt | Bin 370 -> 370 bytes .../psbt_test_suite/TX-19.height_near.psbt | Bin 0 -> 329 bytes tests/data/psbt_test_suite/TX-19.inert.psbt | Bin 0 -> 329 bytes .../TX-19.relative_blocks.psbt | Bin 0 -> 329 bytes .../TX-19.relative_rbf_masquerade.psbt | Bin 0 -> 329 bytes .../psbt_test_suite/TX-19.relative_time.psbt | Bin 0 -> 329 bytes .../TX-19.relative_time_V2.psbt | Bin 363 -> 363 bytes .../TX-19.timestamp_future.psbt | Bin 0 -> 329 bytes .../psbt_test_suite/TX-20.cltv_height.psbt | Bin 0 -> 354 bytes .../data/psbt_test_suite/TX-20.cltv_time.psbt | Bin 0 -> 356 bytes .../psbt_test_suite/TX-20.csv_relative.psbt | Bin 0 -> 353 bytes .../TX-21.claims_us_pays_other.psbt | Bin 0 -> 336 bytes .../TX-21.claims_us_pays_other_V2.psbt | Bin 0 -> 363 bytes .../TX-21.honest_foreign_annotated_spend.psbt | Bin 0 -> 1149 bytes .../TX-21.ms_fp_relabeled.psbt | Bin 0 -> 1156 bytes .../TX-21.ms_repointed_keys.psbt | Bin 0 -> 1156 bytes .../TX-21.ms_repointed_spk.psbt | Bin 0 -> 1156 bytes .../TX-21.pays_us_claims_other.psbt | Bin 0 -> 336 bytes .../TX-21.pays_us_claims_other_V2.psbt | Bin 0 -> 363 bytes .../TX-21.taproot_claims_other.psbt | Bin 0 -> 357 bytes .../TX-22.mixed_path_maps.psbt | Bin 0 -> 396 bytes .../TX-22.mixed_path_maps_input.psbt | Bin 0 -> 396 bytes .../psbt_test_suite/TX-22.ms_decoy_first.psbt | Bin 0 -> 1220 bytes .../psbt_test_suite/TX-22.ms_decoy_last.psbt | Bin 0 -> 1220 bytes .../psbt_test_suite/TX-22.surplus_paths.psbt | Bin 0 -> 396 bytes .../TX-22.taproot_surplus_internal_key.psbt | Bin 0 -> 417 bytes .../TX-23.forged_input_claim.psbt | Bin 0 -> 396 bytes .../TX-23.forged_input_claim_V2.psbt | Bin 0 -> 423 bytes .../TX-23.forged_output_claim.psbt | Bin 0 -> 336 bytes .../TX-23.forged_output_claim_V2.psbt | Bin 0 -> 363 bytes .../TX-23.forged_taproot_claim.psbt | Bin 0 -> 417 bytes .../XTRAS.ANYONE_CAN_SPEND_OUTPUT.psbt | Bin 0 -> 348 bytes .../XTRAS.ANYONE_CAN_SPEND_OUTPUT_V2.psbt | Bin 0 -> 375 bytes .../XTRAS.BARE_MULTISIG_OUTPUT.psbt | Bin 0 -> 385 bytes .../XTRAS.BARE_MULTISIG_OUTPUT_V2.psbt | Bin 0 -> 412 bytes .../psbt_test_suite/XTRAS.DUST_OUTPUT.psbt | Bin 329 -> 329 bytes .../data/psbt_test_suite/XTRAS.HUGE_FEE.psbt | Bin 329 -> 329 bytes .../psbt_test_suite/XTRAS.HUGE_FEE_V2.psbt | Bin 363 -> 363 bytes .../XTRAS.MISMATCHED_WITNESS_SCRIPT.psbt | Bin 539 -> 539 bytes .../psbt_test_suite/XTRAS.MISSING_UTXO.psbt | Bin 0 -> 302 bytes .../XTRAS.MISSING_UTXO_V2.psbt | Bin 0 -> 329 bytes .../XTRAS.MIXED_INPUT_TYPES.psbt | Bin 514 -> 514 bytes .../XTRAS.NEGATIVE_AMOUNT.psbt | Bin 363 -> 363 bytes .../psbt_test_suite/XTRAS.NEGATIVE_FEE.psbt | Bin 336 -> 336 bytes .../XTRAS.NEGATIVE_FEE_V2.psbt | Bin 363 -> 363 bytes .../XTRAS.NETWORK_HRP_MISMATCH.psbt | Bin 336 -> 472 bytes .../psbt_test_suite/XTRAS.OP_RETURN_BURN.psbt | Bin 369 -> 369 bytes .../XTRAS.OP_RETURN_BURN_V2.psbt | Bin 408 -> 408 bytes .../psbt_test_suite/XTRAS.RBF_SIGNAL.psbt | Bin 329 -> 329 bytes .../psbt_test_suite/XTRAS.TRUNCATED_PSBT.psbt | Bin 197 -> 197 bytes .../XTRAS.UNSUPPORTED_PSBT_VERSION.psbt | Bin 0 -> 336 bytes .../XTRAS.UNSUPPORTED_PSBT_VERSION_V2.psbt | Bin 0 -> 363 bytes .../XTRAS.V2_MISSING_PREVOUT.psbt | Bin 0 -> 321 bytes .../XTRAS.WITNESS_NONWITNESS_MISMATCH.psbt | Bin 0 -> 383 bytes .../XTRAS.WITNESS_UTXO_MISMATCH.psbt | Bin 339 -> 339 bytes tests/psbt_suite_util.py | 422 +++++++++++++++++- tests/test_flows_psbt_malicious.py | 4 +- tests/test_psbt_refusal_screens.py | 5 +- tests/test_psbt_test_suite.py | 112 +++++ 102 files changed, 862 insertions(+), 33 deletions(-) create mode 100644 tests/data/psbt_test_suite/TX-04.psbt create mode 100644 tests/data/psbt_test_suite/TX-05.psbt create mode 100644 tests/data/psbt_test_suite/TX-13.duplicate.psbt create mode 100644 tests/data/psbt_test_suite/TX-13.reorder.psbt create mode 100644 tests/data/psbt_test_suite/TX-13.substitute.psbt create mode 100644 tests/data/psbt_test_suite/TX-13.threshold.psbt create mode 100644 tests/data/psbt_test_suite/TX-19.height_far.psbt create mode 100644 tests/data/psbt_test_suite/TX-19.height_near.psbt create mode 100644 tests/data/psbt_test_suite/TX-19.inert.psbt create mode 100644 tests/data/psbt_test_suite/TX-19.relative_blocks.psbt create mode 100644 tests/data/psbt_test_suite/TX-19.relative_rbf_masquerade.psbt create mode 100644 tests/data/psbt_test_suite/TX-19.relative_time.psbt create mode 100644 tests/data/psbt_test_suite/TX-19.timestamp_future.psbt create mode 100644 tests/data/psbt_test_suite/TX-20.cltv_height.psbt create mode 100644 tests/data/psbt_test_suite/TX-20.cltv_time.psbt create mode 100644 tests/data/psbt_test_suite/TX-20.csv_relative.psbt create mode 100644 tests/data/psbt_test_suite/TX-21.claims_us_pays_other.psbt create mode 100644 tests/data/psbt_test_suite/TX-21.claims_us_pays_other_V2.psbt create mode 100644 tests/data/psbt_test_suite/TX-21.honest_foreign_annotated_spend.psbt create mode 100644 tests/data/psbt_test_suite/TX-21.ms_fp_relabeled.psbt create mode 100644 tests/data/psbt_test_suite/TX-21.ms_repointed_keys.psbt create mode 100644 tests/data/psbt_test_suite/TX-21.ms_repointed_spk.psbt create mode 100644 tests/data/psbt_test_suite/TX-21.pays_us_claims_other.psbt create mode 100644 tests/data/psbt_test_suite/TX-21.pays_us_claims_other_V2.psbt create mode 100644 tests/data/psbt_test_suite/TX-21.taproot_claims_other.psbt create mode 100644 tests/data/psbt_test_suite/TX-22.mixed_path_maps.psbt create mode 100644 tests/data/psbt_test_suite/TX-22.mixed_path_maps_input.psbt create mode 100644 tests/data/psbt_test_suite/TX-22.ms_decoy_first.psbt create mode 100644 tests/data/psbt_test_suite/TX-22.ms_decoy_last.psbt create mode 100644 tests/data/psbt_test_suite/TX-22.surplus_paths.psbt create mode 100644 tests/data/psbt_test_suite/TX-22.taproot_surplus_internal_key.psbt create mode 100644 tests/data/psbt_test_suite/TX-23.forged_input_claim.psbt create mode 100644 tests/data/psbt_test_suite/TX-23.forged_input_claim_V2.psbt create mode 100644 tests/data/psbt_test_suite/TX-23.forged_output_claim.psbt create mode 100644 tests/data/psbt_test_suite/TX-23.forged_output_claim_V2.psbt create mode 100644 tests/data/psbt_test_suite/TX-23.forged_taproot_claim.psbt create mode 100644 tests/data/psbt_test_suite/XTRAS.ANYONE_CAN_SPEND_OUTPUT.psbt create mode 100644 tests/data/psbt_test_suite/XTRAS.ANYONE_CAN_SPEND_OUTPUT_V2.psbt create mode 100644 tests/data/psbt_test_suite/XTRAS.BARE_MULTISIG_OUTPUT.psbt create mode 100644 tests/data/psbt_test_suite/XTRAS.BARE_MULTISIG_OUTPUT_V2.psbt create mode 100644 tests/data/psbt_test_suite/XTRAS.MISSING_UTXO.psbt create mode 100644 tests/data/psbt_test_suite/XTRAS.MISSING_UTXO_V2.psbt create mode 100644 tests/data/psbt_test_suite/XTRAS.UNSUPPORTED_PSBT_VERSION.psbt create mode 100644 tests/data/psbt_test_suite/XTRAS.UNSUPPORTED_PSBT_VERSION_V2.psbt create mode 100644 tests/data/psbt_test_suite/XTRAS.V2_MISSING_PREVOUT.psbt create mode 100644 tests/data/psbt_test_suite/XTRAS.WITNESS_NONWITNESS_MISMATCH.psbt diff --git a/src/seedsigner/models/psbt_parser.py b/src/seedsigner/models/psbt_parser.py index 9f35c6a0d..b8f2fa351 100644 --- a/src/seedsigner/models/psbt_parser.py +++ b/src/seedsigner/models/psbt_parser.py @@ -21,6 +21,10 @@ class OPCODES: OP_RETURN = 106 OP_PUSHDATA1 = 76 + OP_PUSHDATA2 = 77 + OP_PUSHDATA4 = 78 + OP_CHECKLOCKTIMEVERIFY = 177 + OP_CHECKSEQUENCEVERIFY = 178 # Consensus ceiling on any single amount, in sats. @@ -78,6 +82,14 @@ class RiskWarning: FUTURE_LOCKTIME = "FUTURE_LOCKTIME" LOCKTIME_FAR_FUTURE = "LOCKTIME_FAR_FUTURE" RELATIVE_TIMELOCK = "RELATIVE_TIMELOCK" + + # An output's own script contains OP_CHECKLOCKTIMEVERIFY or + # OP_CHECKSEQUENCEVERIFY. Unlike the two locktime warnings above, which + # delay *this* transaction, this locks the funds the output receives: + # consensus rejects any spend of them until the condition is met. The + # address alone never shows it. + SCRIPT_TIMELOCK = "SCRIPT_TIMELOCK" + RBF = "RBF" # Recorded, but not worth interrupting the user for. Opt-in RBF is the @@ -120,6 +132,10 @@ class RejectCode: # belongs to this seed when it does not. On an output that assertion is how a # fake change output is dressed up as the user's own, so it is treated as an # attack. + # + # Also raised for the mirror image: the claimed key really is ours, but the + # output's script pays someone else. Proving the key is only half the claim; + # the other half is that this output is locked to it. FORGED_OUTPUT_OWNERSHIP = "FORGED_OUTPUT_OWNERSHIP" # The same false claim, but on an input, where the threat picture inverts. A @@ -138,6 +154,21 @@ class RejectCode: # transaction into unsignability. FORGED_INPUT_OWNERSHIP = "FORGED_INPUT_OWNERSHIP" + # A single-key output carries more than one derivation claim. One key can + # only sit at one path, so the extras are either malformed or there to make + # a checker that reads only the first entry pass over a false one. + SURPLUS_DERIVATIONS = "SURPLUS_DERIVATIONS" + + # A scope declares both ecdsa and taproot derivations for this seed. No + # wallet produces this; it exists to confuse which key form is checked. + MIXED_DERIVATION_MAPS = "MIXED_DERIVATION_MAPS" + + # An output pays a key this seed derives, but the psbt attributes that key to + # another wallet's fingerprint. No funds are lost -- the output really is ours -- + # but the psbt misdescribes its own outputs, and one that lies about ownership in + # this direction cannot be trusted about anything else. + MISLABELED_OUTPUT_OWNERSHIP = "MISLABELED_OUTPUT_OWNERSHIP" + # The selected seed holds no key that could sign any input. Alone among these # codes this is a mismatch rather than a refusal of the psbt: the usual cause # is the user picking the wrong seed. It is raised so the flow can say so up @@ -347,7 +378,10 @@ def parse(self): 2. _verify_claimed_derivation_paths: each input and output scope that claims to be controlled by the seed is verified. Raises InvalidPSBTError with RejectCode.FORGED_[INPUT|OUTPUT]_OWNERSHIP if a claimed scope fails - verification. + verification. The claims that survive are then checked for shape + (_verify_claim_shapes: SURPLUS_DERIVATIONS, MIXED_DERIVATION_MAPS) and, + on outputs, against the script they sit on + (_verify_output_claims_match_scripts: FORGED_OUTPUT_OWNERSHIP). 3. _reject_if_seed_cannot_sign: raises RejectCode.SEED_CANNOT_SIGN if none of the inputs can be signed by the seed. A mismatch rather than an attack, @@ -420,6 +454,9 @@ def parse(self): # Work out what this seed actually owns before anything below reads the psbt's # claims about it. self._verify_claimed_derivation_paths(child_key_derivation_cache) + self._verify_claim_shapes() + self._verify_output_claims_match_scripts() + self._reject_mislabeled_outputs(child_key_derivation_cache) self._reject_if_seed_cannot_sign() rt = self._parse_inputs(child_key_derivation_cache) @@ -1380,6 +1417,53 @@ def _collect_risk_warnings(self): self.risk_warnings.add(RiskWarning.RELATIVE_TIMELOCK) break + # CLTV / CSV inside an output's own script. Only a script the psbt + # supplies *and* that hashes to the scriptPubKey is read; anything else + # says nothing about what the output is really locked by. + vout = self.psbt.tx.vout + for i, out in enumerate(self.psbt.outputs): + committed = PSBTParser._committed_output_script(out, vout[i].script_pubkey) + if committed is not None and PSBTParser._script_has_timelock(committed): + self.risk_warnings.add(RiskWarning.SCRIPT_TIMELOCK) + break + + + @staticmethod + def _committed_output_script(out: OutputScope, script_pubkey): + """The supplied witness or redeem script this output is provably locked by, if any.""" + if out.witness_script is not None: + wsh = script.p2wsh(out.witness_script).data + if wsh == script_pubkey.data or script.p2sh(script.Script(wsh)).data == script_pubkey.data: + return out.witness_script + if out.redeem_script is not None and script.p2sh(out.redeem_script).data == script_pubkey.data: + return out.redeem_script + return None + + + @staticmethod + def _script_has_timelock(sc) -> bool: + """ + Whether a script runs OP_CHECKLOCKTIMEVERIFY or OP_CHECKSEQUENCEVERIFY. + Walks the opcodes rather than searching the bytes, so a push that happens + to contain 0xb1 or 0xb2 is not mistaken for one. + """ + data = sc.data + pos = 0 + while pos < len(data): + op = data[pos] + pos += 1 + if op in (OPCODES.OP_CHECKLOCKTIMEVERIFY, OPCODES.OP_CHECKSEQUENCEVERIFY): + return True + if 0x01 <= op <= 0x4b: + pos += op + elif op == OPCODES.OP_PUSHDATA1: + pos += 1 + (data[pos] if pos < len(data) else 0) + elif op == OPCODES.OP_PUSHDATA2: + pos += 2 + int.from_bytes(data[pos:pos + 2], "little") + elif op == OPCODES.OP_PUSHDATA4: + pos += 4 + int.from_bytes(data[pos:pos + 4], "little") + return False + @staticmethod @@ -1848,6 +1932,178 @@ def _verify_claimed_derivation_paths(self, child_key_derivation_cache: dict): ] + def _seed_claims(self, scope: InputScope | OutputScope) -> tuple[list, list]: + """ + The (ecdsa, taproot) claims in a scope that name this seed's fingerprint. + Taproot entries are (pubkey, leaf_hashes). + """ + seed_fingerprint = self.master_fingerprint or self.root.my_fingerprint + ecdsa = [pub for pub, d in scope.bip32_derivations.items() + if d.fingerprint == seed_fingerprint] + taproot = [(pub, leaf_hashes) for pub, (leaf_hashes, d) in scope.taproot_bip32_derivations.items() + if d.fingerprint == seed_fingerprint] + return ecdsa, taproot + + + def _verify_claim_shapes(self): + """ + Refuses claims that are each individually true but could not all be true + of one honest wallet's scope. + + Runs after _verify_claimed_derivation_paths, so every claim here already + re-derives from the seed; a claim that does not is reported as forged + rather than as mis-shaped. + + * MIXED_DERIVATION_MAPS: a scope naming this seed in both the ecdsa and + the taproot derivation maps. A script is one or the other. + * SURPLUS_DERIVATIONS: a single-key output naming this seed more than + once. Only one of those keys can be the one the script pays, so the + rest are decoys for a checker that reads only the first entry. + """ + if not self.can_verify_derivations: + return + + vout = self.psbt.tx.vout + scopes = [(out, vout[i].script_pubkey) for i, out in enumerate(self.psbt.outputs)] + scopes += [(inp, None) for inp in self.psbt.inputs] + + for scope, script_pubkey in scopes: + ecdsa, taproot = self._seed_claims(scope) + if ecdsa and taproot: + raise InvalidPSBTError( + "A transaction entry names this seed as both an ecdsa and a taproot key.", + code=RejectCode.MIXED_DERIVATION_MAPS, + ) + + if script_pubkey is None: + continue + + script_type = script_pubkey.script_type() + is_single_key = script_type in ("p2pkh", "p2wpkh") or ( + script_type == "p2sh" + and scope.redeem_script is not None + and scope.redeem_script.script_type() == "p2wpkh" + ) + key_path_claims = [pub for pub, leaf_hashes in taproot if not leaf_hashes] + if (is_single_key and len(ecdsa) > 1) or (script_type == "p2tr" and len(key_path_claims) > 1): + raise InvalidPSBTError( + "A single-key output names more than one of this seed's keys.", + code=RejectCode.SURPLUS_DERIVATIONS, + ) + + + @staticmethod + def _output_commits_to_key(out: OutputScope, script_pubkey, public_key) -> bool | None: + """ + Whether an output's scriptPubKey is locked to `public_key`. None when the + psbt does not carry enough to tell (a script-hash output with no script + supplied), which is left to the rest of the parse to judge. + + The output-side counterpart of _input_commits_to_key. + """ + sec = public_key.sec() + script_type = script_pubkey.script_type() + + if script_type == "p2wpkh": + return script.p2wpkh(public_key).data == script_pubkey.data + if script_type == "p2pkh": + return script.p2pkh(public_key).data == script_pubkey.data + if script_type == "p2wsh": + if out.witness_script is None: + return None + return (script.p2wsh(out.witness_script).data == script_pubkey.data + and sec in out.witness_script.data) + if script_type == "p2sh": + if script.p2sh(script.p2wpkh(public_key)).data == script_pubkey.data: + return True + redeem = out.redeem_script + if redeem is None: + return None + if script.p2sh(redeem).data != script_pubkey.data: + return False + if redeem.script_type() == "p2wsh": + witness = out.witness_script + return (witness is not None + and script.p2wsh(witness).data == redeem.data + and sec in witness.data) + if redeem.script_type() == "p2wpkh": + # Wraps a single key, and the check above showed it isn't this one. + return False + return sec in redeem.data + return None + + + def _verify_output_claims_match_scripts(self): + """ + Refuses an output whose derivation names one of this seed's keys when the + output's script is not locked to that key. + + _verify_claimed_derivation_paths proves the key is ours. That is only half + of an ownership claim: a psbt can annotate a stranger's output with a + genuine key and path of ours, and the key check alone passes it. Such an + output is not labelled change (the script comparison in _parse_outputs + fails), so it would be shown as an ordinary payment with no hint that the + psbt tried to pass it off as ours. + + Taproot claims are not checked here. A key-path claim can still sit under + a script tree this parser does not reconstruct, so a mismatch is not proof + of a lie; such outputs are simply never labelled change. + """ + if not self.can_verify_derivations: + return + + vout = self.psbt.tx.vout + for i, out in enumerate(self.psbt.outputs): + ecdsa, _taproot = self._seed_claims(out) + for public_key in ecdsa: + if PSBTParser._output_commits_to_key(out, vout[i].script_pubkey, public_key) is False: + raise InvalidPSBTError( + f"Output {i} is annotated with one of this seed's keys, " + f"but its script pays a different key.", + code=RejectCode.FORGED_OUTPUT_OWNERSHIP, + ) + + + def _reject_mislabeled_outputs(self, child_key_derivation_cache: dict): + """ + Refuses an output whose derivation names a foreign fingerprint on a key this + seed actually derives at that path. + + The mirror image of FORGED_OUTPUT_OWNERSHIP: there the psbt claims a key of + someone else's is ours; here it claims a key of ours is someone else's. The + second costs nothing directly, but it is still the psbt misdescribing who owns + its outputs, and ownership is decided by re-derivation in both directions. + + All-zero fingerprints were already filled in by _fill_missing_fingerprints, so + an xpub imported without its fingerprint (issue #359) does not land here. + """ + if not self.can_verify_derivations: + return + + seed_fingerprint = self.master_fingerprint or self.root.my_fingerprint + for i, out in enumerate(self.psbt.outputs): + claims = [(pub, d, False) for pub, d in out.bip32_derivations.items()] + claims += [(pub, d, True) for pub, (_, d) in out.taproot_bip32_derivations.items()] + for public_key, derivation_path_obj, is_taproot in claims: + if derivation_path_obj.fingerprint == seed_fingerprint: + continue + try: + ours = PSBTParser.seed_owns_pubkey( + self.root, derivation_path_obj.derivation, public_key, + child_key_derivation_cache, is_taproot=is_taproot, + root_path=self.root_path, + ) + except Exception as e: + # e.g. a hardened step below an account-level xpub root + logger.debug("Could not derive %s: %s", derivation_path_obj.derivation, e) + ours = False + if ours: + raise InvalidPSBTError( + f"Output {i} pays this seed but is labelled as another wallet's.", + code=RejectCode.MISLABELED_OUTPUT_OWNERSHIP, + ) + + def _reject_if_seed_cannot_sign(self): """ Rejects the psbt when none of its inputs rely on a key derived by this seed. @@ -1887,12 +2143,46 @@ def _reject_if_seed_cannot_sign(self): def verify_multisig_output(self, descriptor: Descriptor, change_num: int) -> bool: + """ + Whether a change output really is the known-good descriptor's. + + embit's Descriptor.owns stops at the first derivation that names one of the + descriptor's keys. A psbt listing a genuine entry first and a decoy after it + therefore passes, while the same entries in the other order fail. Here + every entry that names a descriptor key has to derive this output's script, + and has to be one of the keys that script actually contains. + """ change_data = self.get_change_data(change_num) i = change_data["output_index"] output = self.psbt.outputs[i] - is_owner = descriptor.owns(output) - # print(f"{self.psbt.tx.vout[i].script_pubkey.address()} | {output.value} | {is_owner}") - return is_owner + script_pubkey = self.psbt.tx.vout[i].script_pubkey + + if not output.bip32_derivations: + # Taproot descriptors carry their claims in the taproot map instead. + return descriptor.owns(output) + + if script_pubkey.script_type() != descriptor.scriptpubkey_type(): + return False + + matched = False + for public_key, derivation_path_obj in output.bip32_derivations.items(): + res = descriptor.check_derivation(derivation_path_obj) + if res is None: + continue + idx, branch_idx = res + derived = descriptor.derive(idx, branch_index=branch_idx) + if derived.script_pubkey().data != script_pubkey.data: + return False + committed = derived.witness_script() or derived.redeem_script() + if committed is not None: + if committed.script_type() == "p2wpkh": + # sh(wpkh): the script holds the key's hash, not the key. + if script.p2wpkh(public_key).data != committed.data: + return False + elif public_key.sec() not in committed.data: + return False + matched = True + return matched def _fill_missing_fingerprints(self, child_key_derivation_cache: dict): diff --git a/src/seedsigner/views/psbt_views.py b/src/seedsigner/views/psbt_views.py index 341b1e0f0..2effc2586 100644 --- a/src/seedsigner/views/psbt_views.py +++ b/src/seedsigner/views/psbt_views.py @@ -511,6 +511,34 @@ class RejectPresentation: button_label=_mft("Discard transaction"), ), + # Both are ownership claims that could not all be honest at once: several of + # this seed's keys on a single-key output, or the same seed named as both an + # ecdsa and a taproot key. Same threat as a forged output. + RejectCode.SURPLUS_DERIVATIONS: RejectPresentation( + screen=DireWarningScreen, + title=_mft("Suspicious Transaction"), + headline=_mft("Likely an Attack!"), + # TRANSLATOR_NOTE: A psbt's claims about which keys belong to this seed contradict each other + text=_mft("This transaction makes contradictory claims about which keys are yours."), + button_label=_mft("Discard transaction"), + ), + + RejectCode.MIXED_DERIVATION_MAPS: RejectPresentation( + screen=DireWarningScreen, + title=_mft("Suspicious Transaction"), + headline=_mft("Likely an Attack!"), + text=_mft("This transaction makes contradictory claims about which keys are yours."), + button_label=_mft("Discard transaction"), + ), + + RejectCode.MISLABELED_OUTPUT_OWNERSHIP: RejectPresentation( + screen=WarningScreen, + title=_mft("Transaction Problem"), + # TRANSLATOR_NOTE: A psbt labels an output that really pays this seed as another wallet's + text=_mft("An output that pays this seed is labelled as another wallet's. The transaction misdescribes itself."), + button_label=_mft("Discard transaction"), + ), + RejectCode.FORGED_INPUT_OWNERSHIP: RejectPresentation( screen=WarningScreen, # TRANSLATOR_NOTE: Title of the screen shown when a psbt misstates who owns an input @@ -758,6 +786,9 @@ class PSBTRiskWarningView(View): # TRANSLATOR_NOTE: BIP-68 relative timelock; the delay runs from when the # input confirmed, so no fixed date can be shown. RiskWarning.RELATIVE_TIMELOCK: _mft("An input is time-locked and cannot be spent yet."), + # TRANSLATOR_NOTE: An output's script (CLTV/CSV) locks the funds it + # receives, so whoever gets them cannot spend them until later. + RiskWarning.SCRIPT_TIMELOCK: _mft("An output is time-locked by its script; those funds cannot be spent until later."), RiskWarning.RBF: _mft("This transaction is marked replaceable (RBF)."), } diff --git a/tests/data/psbt_test_suite/NORMAL-1_p2wpkh.psbt b/tests/data/psbt_test_suite/NORMAL-1_p2wpkh.psbt index 3b3cf3f214dc1d1d79a249805dd9a9c96dbfb88b..9716924c92f80002316d2547f32a8804cbc3f1b5 100644 GIT binary patch delta 61 zcmX@fbdqU;lgM4ukLSJonRmMMbZpxbr*r1s(#F>l!#c#Vi8C-VPK*LrqICbp6>f~;*d!Pj87FQKpDe><3jh~w B7uo;- delta 62 zcmcb~a+77k6cPS|O$&Ef~;*d!Pj87FQKpDe><3jlAD B8hii% diff --git a/tests/data/psbt_test_suite/NORMAL-4_multi_input_V2.psbt b/tests/data/psbt_test_suite/NORMAL-4_multi_input_V2.psbt index 72ada1820418a86240178f32f94e127dd68b2452..3e3a2c34fecb8c7c4c2a164954c048b7ff16ef76 100644 GIT binary patch delta 57 vcmeBX?PlF@gHiYQtX~nOj0`^?GAh00itGxRe&X#bMiwy!5o{8ZS((}Z-f|hD delta 57 vcmeBX?PlF@gHgBT;p_i%%6PfqKJpYZUU%iAoBa0Y=2sVkytW0eH^ehYgl0CdqH8vpbb)C?qR2*Jshf?jGrwxOIC0*Pbb)C?qR5=KUyrw4zK>=TOOJ_S6K4Pb-ToV) diff --git a/tests/data/psbt_test_suite/TX-03.fee_inflate_V2.psbt b/tests/data/psbt_test_suite/TX-03.fee_inflate_V2.psbt index 11caee28d4c92b4fd1879967bb63009dae60add0..71858e84e3bac3ed449695cb388444491442631f 100644 GIT binary patch delta 65 zcmaFO^qOgd5u;__o_9unCan6FrP8S_b6RY&t6%?TMiwy!5v&r-9BWz_8NdJlxknjY delta 65 ycmaFO^qOgd5u;^qrgcijlUD)9y8J9-+9tQjq?P|;WD#Q!!79Pbv8IKQ0So|q&KN5I diff --git a/tests/data/psbt_test_suite/TX-04.psbt b/tests/data/psbt_test_suite/TX-04.psbt new file mode 100644 index 0000000000000000000000000000000000000000..41860b66227677e5524a637c7035d66d25997efb GIT binary patch literal 1377 zcmXRYPAd7&$gqitfq{W(wZPRgQ%*^qX=5~#JXL<8yFtUnH}d|!+K=16@;ct-X922V zVE7LNnQM=2c_LElUKw}OTP*7gi%(eyi)e~nN|3{zDY>n@N8t*Y*0eB!IZ6x)J~Iw~ zw7zpOBmHN-&2gJEDs|6L@G5&%|TKck;cCK@4m-d<=Cpnttefip;Qr0-OQo%M=4*-+AHBt8 zz`y`B41$3{(g3wYab^k+$Pz(~_`mXct~+k&ZPwMPlv`C>7Hm*=T+NcvMrK#h@o(nL zft7g|MBJQKZgke3sb8ZNr>ti2bH@I2Id(l>&6ZueyhJoo0@!d^@~-g5QII7Tmp3p4 zE=k_-|K--Hm&Ak8e4>!RH@}^_W`fS@gbcGS$(2SnGZ{%qP#Y%jE3OyTR*}*a%uAgEcTf z4g~@wHiFKO!Imr_0Rq-f$dNMGVjQNQfuh)uNr*W&Ir77+GuJ=J?%rD>buywe)&BZt z3puaM1<%f@fqlrxC=ZK2F$NK-jgRkt-uYoy|Ms_ME6p?IXF2eER$_a4gynpr&+gv% zMJ(d!DQ=QStUjDjuARPPU+t%z|3#0_{=ow_3P^z6&BzFf;MIa0rP-F%bADfT`;mLq zrC1_+eu3cy`APHn?H{zclp%IP+59Lj7%QM_;d; z5S69K{721J#I#p(`V?WsZ~4Km8$R#$WLU2mxNZM^J+_wa=$pU@W+G@2)(8eU7?jMF WmHt*3 z!0;aknAWr~f;mbI3fJG=n(u$;(ee$Zf|l2Q{Po$Qap$8`?N%-gr4!yJ3wAdkDc!N; z-FXQQJxNDO_AcGx3~-#7=VUBFwmzBP)ihNrtp9)5!8tPE3fCe4}X3iW~nRh|N&1vOEXYHB#HCl1XY8F3d>_3-d*W=Y}*|p0{ zL?b1D4TmM~3V$30Sz>W{15@CV8bJSfd4N?E4!kN%c#Q&&$od$#;8GoN$R zIS%z z5E`BI1POrRj?saa87v8myNcT!(H3><46ZC~(F=6izf3TkbLpDk=JpTe{txa|tG@)P zV`R+?Qe<+KRLi@z=57bq0(a{_F5#7NTGE+{40>)Sn$5od)tPf!k=aAWthGBd-d9=W zK&bSimy>&&x@-a%L_=oHh~C?qzy6;h^QuSrzYaeCP^`z)QqQ9Ib(5)%?!#L5%V9ow zo?Rwqf8GsVr^H6kA{lI<07;At3`%SSogsrQJs{~PW~Hm^zv?Z&Zof#8*+NP2+bY{zb0z*(&tt2-&3U3k{ezIk z+MK4gH;ESnK0Hul-Ypcr^V>B`1J;ZELN%tbO}mtH7vFG=nv?O9C;b2QlU2aLVj^gf z%*^$_K7x`A(18uWxNHC=ejp7@HNe1PBIpd6#VwOo;L%UWkupu9$(*?KGcW)E|FE9j literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-06.branch127.psbt b/tests/data/psbt_test_suite/TX-06.branch127.psbt index 1f71d43678266ce99c28b468adbcef63b5ad3dd0..9887aa157e290fc4ee5fdb95052ec5e91a228075 100644 GIT binary patch delta 52 qcmX@fbdqU8qKJHp?Y73NyQCk^*ee+wI$c~lo|AWC>3&gc;tT*mMHG?% delta 52 qcmX@fbdqU8qR0u;!-WkgW?B7V0c{`mNKOlj+LAJ{biXJzaRvZ!;}@O) diff --git a/tests/data/psbt_test_suite/TX-06.depth6.psbt b/tests/data/psbt_test_suite/TX-06.depth6.psbt index d0155d754dc97366ccac6b95dd7e52d0c2f821b6..82ebad6de5a504b57bf9d894e20c962dcaf7e4ff 100644 GIT binary patch delta 52 qcmX@hbe3sCqDa0+Q`muv-F}kZ#t~~{r7kNqgmz3UJuHe%oB;qmPZd4@ delta 52 rcmX@hbe3sCqDa5@`#Hz_{-t_)GC4ivSuus>SNrRUrH4hai8BBIlie90 diff --git a/tests/data/psbt_test_suite/TX-08.ANYONECANPAY.psbt b/tests/data/psbt_test_suite/TX-08.ANYONECANPAY.psbt index 1ac18d0474d877d2540f6c14c71ca42dbe41013d..080bf9c378126fffcdf8806a878218ba00d68b72 100644 GIT binary patch delta 109 zcmbQuG@EIHlkwclClynyR!of%oViQye+Sq0n40#OgA8CG#vpQS$u9Q`sn5K1bf5Hql^zZKYUbHljm|XPWT^lkO2(D7(_&`JO0^n)i-{cg?Q)V6Z76XR2<}?Vao~2N}RXj6vj;&!wbad-PN@7WRwB ZuG2WbuEFQk#L{woY}yzY8FA=f002dTFdqN_ delta 109 zcmbQuG@EIHlktm)Nk&|8H+BXZb3A(QxnA)|NRxcbK?X1oV-Pu$6=JUUx~ceC;I6pa Y%n{RVD{5~~EG^f^rj3D-5r+;205SzDrvLx| diff --git a/tests/data/psbt_test_suite/TX-08.SINGLE.psbt b/tests/data/psbt_test_suite/TX-08.SINGLE.psbt index f81814402ee12b08c1bd98dc94c27442926612c8..2e1ff9b42c0bc3100aa1f0769816f1d445d13116 100644 GIT binary patch delta 109 zcmbQuG@EIHlkxu^fAi#-qSmW2BR(nX+WPhvdUeJeWB>y(29bK^Cx*usT{W3kqI@cP Yk%0%(uOo32OUw1KX=7ky#G!)$0J%jeVE_OC delta 109 zcmbQuG@EIHlX2a(^GuCA?wl*ms6F^u#`S96Ye(UjgA8CG#vqciyGu1{tEqZ&K=iG^ Y_Tbxh0}K==mX_;d)5gHah(iYh02Qe!ApigX diff --git a/tests/data/psbt_test_suite/TX-08.SINGLE_ACP.psbt b/tests/data/psbt_test_suite/TX-08.SINGLE_ACP.psbt index 85fc3f5086d14dfca32f8e752dbeb57a67e9ea51..cd67f7b59eab16786bc5510e01263bfc08ee493c 100644 GIT binary patch delta 109 zcmbQuG@EIHld(d}wFkGVm4X-F?k!yWsNdyW?9-f>gA8CG#vpQF{V}6cMY5fTmq=E; ZzVkA)EGT)_#L{woY}yzY8FA=f005@YGF<=w delta 109 zcmbQuG@EIHld*XG#Ijo5n~N{-Fuh*TRW~(YR-}H+K?X1oV-PtMxbn{T7sj3eP YIBxb8O8$H_v9w$tn>GeUMjSdA07h~whX4Qo diff --git a/tests/data/psbt_test_suite/TX-09.attacker_internal_key.psbt b/tests/data/psbt_test_suite/TX-09.attacker_internal_key.psbt index 5b8cee38a25b3acf90deb972b012d2b11c7247b2..fa4eca3ef55f9fbb1b768dbdbb5c50445bbdaf50 100644 GIT binary patch delta 182 zcmX@abc<<%lYQJ=y@=CY6?u;82c|@du=2GwF}tp9QnfrhcV>|x&wt@HEsP8xAjTka zBs%Na)y(_v7l&-jF+IxKy=u{i%!!S;Ijfkx#gqIu_IbGz8>Y!`0KYnj-X8$!qkiQ=QTxI!2h8i2;YFpvoZjEp#pWdHyP CQ9qmj diff --git a/tests/data/psbt_test_suite/TX-09.hidden_taptree.psbt b/tests/data/psbt_test_suite/TX-09.hidden_taptree.psbt index fc12c4ae3ef5fe8b0d193aee39717dd3129cad31..c999240babf0788f68f9b4489f6e2722d3b948db 100644 GIT binary patch delta 243 zcmbQiJdJsRll|9+GTJp0DxOFwNXUB?R(Z8AE!sBE(a`5f??qkiu;ck_S{NBXK#W0T z%L$_&<$-UR;&*Uv>pFFOUHy#s^ofnR^)Gb!Yo`5s$&_V1kLg2RxofeU@cT0p4&P#D z4P5TT^y{cDqv*_BK8pwS&HlbyrG+K;P26zw(&r~z^u&ds{2`kT;k7gi|v`d$wQHK#ufiIE%MPv4@Gc8rGhH% KY167sX*K{B;2ZD& delta 52 rcmcb>bb)C?qKH1r$9;W$U)J<4+x%+Nr;9GD^3M29EIlTQO`HJ$?hqY2 diff --git a/tests/data/psbt_test_suite/TX-11.v0_bech32m.psbt b/tests/data/psbt_test_suite/TX-11.v0_bech32m.psbt index e927d1c568d2c95232871c5d3dc923936464167a..d5023ae526542ebe1e4292326e9d8c04cc934f3a 100644 GIT binary patch delta 53 scmdnPyoY&0qR7L0dWpvSweFKhd_0j?xON|&su}Lrh0E9>vcmMzZ delta 53 rcmdnPyoY&0qKNG6m?i!UTsDoX{kd072^M&`%F$tCsS%?nHVFm*65kVY diff --git a/tests/data/psbt_test_suite/TX-11.v1_bech32.psbt b/tests/data/psbt_test_suite/TX-11.v1_bech32.psbt index 01490fe95c12e38f7462cd81151f37f4215faec8..797306d73b3bb931475cf91a448f117d20800823 100644 GIT binary patch delta 234 zcmeyx{F`}#lYN+D*tVHs_B-qMezp8jv+9%f^|)&NXvb?&_kV;v??1eAO$#Ff2#7I= zTu^EWzi^1XE@XzQ;*zZNOG-8@AYVHJBcr?n?_^cRg-ntR NlaDjXiDGji0|4&QSDpX> delta 205 zcmey({EK;l)8rOL1^G2Cj0_+k#vtO%xZ}-)`2sV8<|*tJIq1`9!TZl_Vxww(NxFq` zvayL#c|o>mNQRl$d;iQBD+_3mE{@u|-G# diff --git a/tests/data/psbt_test_suite/TX-12.psbt b/tests/data/psbt_test_suite/TX-12.psbt index c826b1807548f1e0a7a09063676470c0748c8475..7b86f296eedf96645a208bf7429cc13a90dcfafe 100644 GIT binary patch delta 65 zcmaFQ^qy&h8KY%!-?>Lm(iAEslU4nH>F8XDe53Y@kwuI_1giuy$C?&K1~32sj$;^w delta 65 zcmaFQ^qy&h8Kb4t>ylMIw=?hfckW2#JazN+vZY&gFtUg-h+vgq=2+9h$N&Za_>>$I diff --git a/tests/data/psbt_test_suite/TX-13.duplicate.psbt b/tests/data/psbt_test_suite/TX-13.duplicate.psbt new file mode 100644 index 0000000000000000000000000000000000000000..3c263801d6882b78b46c245bfdf1936e55a585e9 GIT binary patch literal 1021 zcmXRYPAd7&$k55ez`(#b?Pu)7QS9}u?YS%z5E`BI1POrRj&VU7BUlm`cjo1L3Nw}_ESHE5 zUR)$}x7nfdpW=)=_a2qq(%<8=+b9#Hj*&GpNRin?#;mnFG~QQPgWiDt9!e|6^E4qm6k zM$jS|Z1D;45Cek}8$nBCu!SN_KLaBp(6daep*!XHU!K;Sn7(>-o7s(%(?76Ta4{@r z6n?X2jooH(TOw32=ejtzn2Pr0AC|FQv**s;+GkvfDWxK9EcXnp`L$*QP62wBiJ(PT VJqwN$Afd!W&=Rbkh3RKt0046(aCZOz literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-13.reorder.psbt b/tests/data/psbt_test_suite/TX-13.reorder.psbt new file mode 100644 index 0000000000000000000000000000000000000000..487f0ac360af6313e557012b28239a4564d1d488 GIT binary patch literal 1149 zcmXRYPAd7&$k55ez`(#*_itwWc5n3qRVlGEVzR6<7q*%-bY2`*|?V0*DT5-y17C&d~ zKbK?I%fPn#M7z6`-+5ojg=F@aBkR`hp96u$-)z0^Cr^D(A7rtot zzmksQRTNLJYqCFFryHKkBxU{e_jmIPpED=_b-Uv!%xV2PSU1)G!Tp=vmr7gj%-0kt zK6;A_hb8X{e;fr_VsUu`Q{a;14gX(moq9<;D9tBIS*G)k{+4f3S5G*5w)`$LpL5hY zv&N=S&Pvr|m(JaK*;bjj^zIqGhP_$53>igjhehm@qmt1rVPIs41IOLkdq58Y!TWs> z8lCh634r2`aX}j+SP~d_A`{tozU%$_X7xI#^MXvM-wi)uv14m9I9#>)_Wu9*%mSp2 zku@_&k$Kgl{9gy3e<;>tYN=<@`?|?gNB3c^`{gj7JkKtZvp?@DGJD9FwRVTb`zos( z2$g>Ha&m7|mrVeJXvnM?(R+LI*Z)&wa+OreySCpw2xm2q0qnTia0ZYP?} zzW>#kb31sQ5*tB_WU$32#6t`WK>dWAA%iWd5c&x^QU+Tr!1OaPGJ*n2DTcLB;Z*y9 zw~u^1mHM@{ES7f~UeOkxkh195p(~A>zbP`YhVGQ(e|cJSV*2XUZDu!4PXEAW!Nstg zQTWZ8HFlfDZ55ewU7TA?Mf>s(%h;~jbLVdDGcLuHQjs>6dxqBhS~CKt00WDOphZ{% b3mmCHLWzl>Gq460LO(%AVht>qeg*~r)J%?3 literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-13.substitute.psbt b/tests/data/psbt_test_suite/TX-13.substitute.psbt new file mode 100644 index 0000000000000000000000000000000000000000..81ea478480855fd9b92a3488018d293fa1dc2ba5 GIT binary patch literal 1149 zcmXRYPAd7&$k55ez`(%xiODlI+Jn(V_BkXlwQaYOu6kTk<^C2)>GZXF zJ^N!~lJ-7JEt|J_o(jjk$Ysoz+r5r!T;TWqQ1Ag{ravQ#Y5RGI=|FN(-L`DD0;AuV z=bjm<96NY=mf?yKl)p~O&zOPLOCl{k6k)<>t$PI;?lck^cwbN@iJr-wH+3*PmW4Pw}gR_Ar2gO zYwrQ=1%mhcAT&DZ2@(Ls9pi#FU{C-7Fz&Sfygai0u(GM3j_`p+Wmg}?o(`C>Dr?e} zQ2Ui1xvXnnfs`?_W(FxT|Cc=FcP&v{aVoFQ-#<6^pUULPjQZQ9E7J3N*0#5i&zC7O zuX>dK>)`Vb#d=IF^(=Z{H<{|_KCE@W9Ojef*=2I}=Uqi6S4p+JYisUya4m4R{^Jr} z8K)(ksmP$`cB0wr`(K?ow}aOyu@SUL23veWJOuO-8$oBtV2dh*eu9pa!4?ZJ{S1tZ zpupNK6un#kH(^$Hb>^6l9eAxvy?t_8F*# zf#E+8FvT1Mvl)~a6xs|YOQ^Wmg^8ZOzhdPRN$1Yg-)>EcC*Nm0FsL|L{rm}%Qpu#p zCRf%3_pEa2JN?z~-NC;N)nabn8H|2Dzx8`^m+w`Onf{C{9h>A>WIjz7YhYkt+P&cT zDKV~gzJEI%R!_L_MZ^D#x7Rn_u{xIr*>K9Zz9S>({}$ zss0b{-|W6r+InZcrbzM8TU-VV3_!ym80gams3nRsQ+Pm@2x`RtmDh9KaZ7Kru1=-g zs@k$(gSz8tmW(zsyNZr~GiMI0%)21s=CpF7v-V8=8m%~GHH)7!_MgkK>+x!~?Aqle zqLC87hQpF~g+GphEU~z}fhllF@`nE}w@$qz9+c)2r7Y9=M}Nz=sjDZPJzIX4na??D zompd3C}*YWu}kM}y=<#YTzdD6Uc=rjUWSaKw!Uv*S?V8xeN6W)W= zF|uX`Dl)lBs^wiK>dd*V$m}6w*4iB!@2jkG zAXNI%%gMb>T{Zy>q9Ls$u#W7#Tr<#TvR(j{oIp z&57x&SGSqnI63_Tn*|rcaz^1dYu4Cp7PnPoR*GRQR5;as;O!${Po;isEsN!yhF7%3 zC!{PocIZmu=5LD3xh~EvrlNiMhh=Qn?74Hd_8FIAN~uU2%RNJDeytgSQ-FcRM9?Cv co&`rLkWgYG=nSl$Mbb~mkys-Ork{ZU0N9k0UjP6A literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-14.cross_net.psbt b/tests/data/psbt_test_suite/TX-14.cross_net.psbt index 3b98fc3cd33eb390563f9d777c8b1aeb9b8a9495..d0beff08072cb625713747614eea24d6bf254d52 100644 GIT binary patch delta 64 zcmX@fbb)C?qV)N{d5Joc9a=M{B=|2YZqdFYcbbm@2pE5}Oe_s%WSn?1TNJAr08x_} AsQ>@~ delta 57 vcmcb>bdqU8qDcA-bF0Rt`vP?wei?Js++qU17|2Yl31(!Ncp+O9n@Gp diff --git a/tests/data/psbt_test_suite/TX-16.global_xpub_injected.psbt b/tests/data/psbt_test_suite/TX-16.global_xpub_injected.psbt index 5d2fbfa07838a0ee6b3cafebb411320678170616..3caee6af5a88320c1745bf60b2054ccdb9c349a6 100644 GIT binary patch delta 53 scmdnXyq9@GqR64WJaezV+H4-P@p{S)n~%$vt$tIqvDBDR6q^JC0Q9FE;Q#;t delta 53 scmdnXyq9@GqKMp&jf%hbh{;*)KCJVIt^A`)=h_<^ON|*tu}Lrh0E^TZrvLx| diff --git a/tests/data/psbt_test_suite/TX-16.unknown_field.psbt b/tests/data/psbt_test_suite/TX-16.unknown_field.psbt index ff765d18b61ee95a8ed281ce09a187d31a5e2b2b..6f66d87cc4a058f1bd6fa793fa4527671e96ed6b 100644 GIT binary patch delta 52 rcmaFK^pa^pqR5@I%B}P3ZCYpUPh*Z<`c9B-+V}X0rT0a#i8BBImX#Qu delta 52 rcmaFK^pa^pqR8|OvkC&9>`3+D=lXSQOGWO7e;M)Q-yn7C6e{0`G6@<@Qk*7DYbiXJzaRvZ)PZ$&c delta 52 rcmX@fbdqU8qDaZ*qaE(gzpzN3S;=>A{)9e>g4dTPmhKnDCe8o=y@?v= diff --git a/tests/data/psbt_test_suite/TX-18.psbt b/tests/data/psbt_test_suite/TX-18.psbt index d3f05c947778351d6e4bf5f6bccf6a63782159ae..ee11fb53a47717d1e00e5e80194c020b35967da2 100644 GIT binary patch delta 52 qcmcb}bdhO7qR6LfGW={y%x12)Ip=%A#M8G_Iq<{8(&M7o#2ElpYZgcV delta 52 rcmcb}bdhO7qKJav(^+R*H$49Pc#7p>zvnDr;v%vWOOK0U6K4PbmSGqM diff --git a/tests/data/psbt_test_suite/TX-19.height_far.psbt b/tests/data/psbt_test_suite/TX-19.height_far.psbt new file mode 100644 index 0000000000000000000000000000000000000000..981c027b918501b68088b03d635dfe1b901d8887 GIT binary patch literal 329 zcmXRYPAd7&$WX|{z`($G=2LI-e*Md~-?R1KI6hE2yWo3+___kq<@)lk_-3oj5CE!S zVEFg{|9_^KgJ3p;7=y@xb9=5GzI>{u^iJF{y?vp^d_M&qAxVEaRegG?pzp+^8aEpz zY@IIgDfo%chxb6E7#Zakv@wE>0h(fGG9&g>{@s(m&1O10Iez0&yM53cB{pWJV3m$O zr&&85-(D|Y!IaWH=Yrg9$ClQkzkH-;hci4}CQ*F!7FP%ZLj%wpFoqZinZlJ(e diff --git a/tests/data/psbt_test_suite/TX-19.height_near.psbt b/tests/data/psbt_test_suite/TX-19.height_near.psbt new file mode 100644 index 0000000000000000000000000000000000000000..9f2f89c4ceaa534d2aa158af946247143e9b63d7 GIT binary patch literal 329 zcmXRYPAd7&$WX|{z`($G=2LI-e*Md~-?R1KI6hE2yWo3+___kq<@)lk_-3oj5CE!S zVEFg{|9_^KgJ3p;7=y@xb9=5GzI>{u^iJF{y?vp^d_M&qAxT?Ji_u=nas8jy`RPY5 zv~~KPQ+JVAu$vcX8>9S!Hb$^9KvV2YX2hP#zkBkx*-VEg$8S7pw-1`5#Kz1NtkTiv zG;7D>+w0{km{PjuT#%dX*wT9Rmyh)9aE6D=B#MvT;tFA4XaJf6#t;L6JVr(wZc}1n yHn{44;jR-`UVN{a%Gb{xI_pgNE3bYiwf?&A{T$ti>uoSh1)2u|U{kSqi2(pcnR|r* literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-19.inert.psbt b/tests/data/psbt_test_suite/TX-19.inert.psbt new file mode 100644 index 0000000000000000000000000000000000000000..87aa35546fce0ff46433879cd4fff3391420ccac GIT binary patch literal 329 zcmXRYPAd7&$WX|{z`($G=2LI-e*Md~-?R1KI6hE2yWo3+___kq<@)lk_-3oj5CE!S zVE7LNOfd(+Yz8p~kpt)UTswUER8Q%hxMO`Z3Fp31*_^0(PchbPBxJZiTOnxn+V%oMEB(dRU4 z$K%`UVM&`6IWh*ubIl%&mKDKO!+IXekis6y6^oQ-HGdMFiZuS2LWJHv3ZFB0PMGV82|tP literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-19.relative_blocks.psbt b/tests/data/psbt_test_suite/TX-19.relative_blocks.psbt new file mode 100644 index 0000000000000000000000000000000000000000..8082194d73de20e15ef48844697ced159edfffa2 GIT binary patch literal 329 zcmXRYPAd7&$WX|{z`($G=2LI-e*Md~-?R1KI6hE2yWo3+___kq<@)lk_-3oj5CE!S zVEF%^fq^OJAehY{#vpRw+@5QPFQ4iuy%Tp#Z(pb}-%o)@NYXFtnMy@&-1IH|uc?;r zGiCOtr`;35dKnqz7ql^gnLtzQOlHKM%D;Q^x7kdGC&zC*YPS!Xqr}F{6s*$G=QL}_ z~MyM%Or}A-r@>jU}ylE1I7>ofjmY=9Bxx$Vm7$y uf8nkZS6+OtnabDC9y;qx`75t}D7F5&@BJLziR*1JOa+<;0bo literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-19.relative_rbf_masquerade.psbt b/tests/data/psbt_test_suite/TX-19.relative_rbf_masquerade.psbt new file mode 100644 index 0000000000000000000000000000000000000000..3613cce65a410a67246b93f652de83b8afeaf498 GIT binary patch literal 329 zcmXRYPAd7&$WX|{z`($G=2LI-e*Md~-?R1KI6hE2yWo3+___kq<@)lk_-3oj5CE!S zVEF%^fq^OJAehY{#vpRw+@5QPFQ4iuy%Tp#Z(pb}-%o)@NYYE5oX$C%)KWcj*}S{o zKk)uxVPUWa>t$q=U(m(~W&%yIGno;4D*x`u-)1u%o*cjNsNFtjjuIO)Q?N=$pVO=z zk8iJ+uV6~)o^wHNwqr}{(O*8&v%?u4E|VxedW$QBfuR9t4j4lW1o9Xeakx#1iP_+) u|Ao6wTzT=mW-4Dld+4k)<*&T@q15{8zV~xLmaKS$Zk} literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-19.relative_time.psbt b/tests/data/psbt_test_suite/TX-19.relative_time.psbt new file mode 100644 index 0000000000000000000000000000000000000000..aca1f1aa1ec5cbb8543edb6d62cd0d92fb2c91fe GIT binary patch literal 329 zcmXRYPAd7&$WX|{z`($G=2LI-e*Md~-?R1KI6hE2yWo3+___kq<@)lk_-3oj5CEzH z0s#jGrkH~ewituRfpdGV9lm_3r}R$TF};1E#(X~o9wABVeK0q5>`Z3Fp31*_^0(PchbPBxJZiTOnxn+V%oMEB(dRU4$K%`U zVM&` r6IWh*ubIl%&mKDKO!+IXekis6y6^oQ-HGdMFiZuS2LWJHv3dyruh?^5 literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-19.relative_time_V2.psbt b/tests/data/psbt_test_suite/TX-19.relative_time_V2.psbt index 067c4886760381447ef177df3cca2d6fad2f3fb1..c86cd2855f6050077df25602fcf6f7f3dbfaf47e 100644 GIT binary patch delta 65 ycmaFO^qOgd5u>Ht`I5Ng-<YHE diff --git a/tests/data/psbt_test_suite/TX-19.timestamp_future.psbt b/tests/data/psbt_test_suite/TX-19.timestamp_future.psbt new file mode 100644 index 0000000000000000000000000000000000000000..43127b877052c5584866e5cb344c8d17d4177001 GIT binary patch literal 329 zcmXRYPAd7&$WX|{z`($G=2LI-e*Md~-?R1KI6hE2yWo3+___kq<@)lk_-3oj5CE!S zVEFg{|9_^KgJ3p;7=y@xb9=5GzI>{u^iJF{y?vp^d_M&qAxWp-UjFi-imAo}i%n;1 z_U!!mI-7F}!xYnU21Z8t1#OIAV}PdEnaqeim4El-Z?l;WPmbSs)NUU%M~RJ@DOjbW z&uP|<$G6wZS1_e?&$%Es+p(qf=r14X+2ITimq`>Ky~P#6z|a6R2aF*G0(p##INYYh y#B6ZY|H54-uDtkOGnKEOJ#^NY@>gE{P-^{k-}^bb6W7~dmGwX^%4NqH-8rZ literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-20.cltv_height.psbt b/tests/data/psbt_test_suite/TX-20.cltv_height.psbt new file mode 100644 index 0000000000000000000000000000000000000000..fc411ce29379d6301748b1a2506c48265b7fa679 GIT binary patch literal 354 zcmXRYPAd7&$WX|{z`($G=2LI-e*Md~-?R1KI6hE2yWo3+___kq<@)lk_-3oj5CE!S zVE7LNOfd(+Yz8p~kpt)UTswUER8Q%hxMOqk+5-NGN^B07r&#;# zoN|ami65kw@iz4$?+SH+U%Q zInCPf`1X4F3Z|6qITz$+JGQhQ{pBM)JDlO+GKu1&x41$W7#e`)fHA~CAdis|hZB{U zm<_J_U%2bUl^5S@rtrN#O0B={dp}2a;(8klQ-S6|03)LY^NCRYO{G3% o!fy)}{XEEDIqj0n-6wye;`jPjq?|c&#{A!pnLa6g2iGtF0QfA0k^lez literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-20.cltv_time.psbt b/tests/data/psbt_test_suite/TX-20.cltv_time.psbt new file mode 100644 index 0000000000000000000000000000000000000000..0c2b0c9238fdbbbee1ea5ad23c8d88d056d1a257 GIT binary patch literal 356 zcmXRYPAd7&$WX+@z`($G=2LI-e*Md~-?R1KI6hE2yWo3+___kq<@)lk_-3oj5CE!S zVE7LNOfd(+Yz8p~kpt)UTswUER8Q%hxMO44HDd%?rP6SoJz}b&%WXv!6b#HeazwbLtuf0HIWdX#fBK literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-20.csv_relative.psbt b/tests/data/psbt_test_suite/TX-20.csv_relative.psbt new file mode 100644 index 0000000000000000000000000000000000000000..888f22f091dc1aef15f9915ea61291ab5b12f9e9 GIT binary patch literal 353 zcmXRYPAd7&$WX|{z`($G=2LI-e*Md~-?R1KI6hE2yWo3+___kq<@)lk_-3oj5CE!S zVE7LNOfd(+Yz8p~kpt)UTswUER8Q%hxMOnGt&`|L)1(W-}e09KZ3X-9BiJ5*ss9uu4at z)2tnjZ?BiHU`pwpb3tylV@vDNUp~^a!xqkI_37$ mW4{jkQ@DElShlK(oc4W zZ!B$0J3(3*f3tv1U}Thc;AMsxW@j=Z_Ei4elfTVoIy^ak<59bP&>ST;W~N}3jy|VZ zJ09O&FJHlw(mm&b+-%2|)}z0Cq-TdSJX|JGeDoGq2m?a{&>S#^xDLo;WCS|#z_~rw z4qraiQ+g-vnBKlnW4@mPkCd304X*lMxa-7~7vF29^7XTa&N@^6%Bvqrt-tPjKSy`s RdK(N=f#yK~*i@`O0|18jd2Rpz literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-21.claims_us_pays_other_V2.psbt b/tests/data/psbt_test_suite/TX-21.claims_us_pays_other_V2.psbt new file mode 100644 index 0000000000000000000000000000000000000000..1b3d5cccce5db2532878eb02ac09484be79c7d8b GIT binary patch literal 363 zcmXRYPAd7&$i%|Lz`(%B%mO4C7+Dw@8Ce;b7=MFB85kMm9e9~RG7Mr2B6cP-Vo&AY zJ^9;gro)rtHy*Xy2hCApV`d6g>F9Hswd3*a_3{-=Dcy4}$jx?aX+8SOM|yTR!^33~ z#Yb;(g)lHQ08Ig7Mj!(O82J>k5>Lu3JGxWrjJD-%=cL^h^?MASmP)+;7rFKCrEj0w ztQq+s?h;`64+KE>0G)B*+@5QPFQ4iuy%Tp#Z(pb}-%o)@N=(cKSN$*Cb>hm4?=@5T z`q@Kgohg6i)eoiCU-!MAqdRfE4TduyjsSTYXz1(5Li&#cZRJZ29}hcWn|b>6N$q)z o%p7Z4ppFIGylqp>mk6n~jwXL!{Ibq})mHyy(JioUtP)7N0d5k200000 literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-21.honest_foreign_annotated_spend.psbt b/tests/data/psbt_test_suite/TX-21.honest_foreign_annotated_spend.psbt new file mode 100644 index 0000000000000000000000000000000000000000..74fcc6260387e668450435dec894b6909123a452 GIT binary patch literal 1149 zcmXRYPAd7&$k55ez`(#5^=(aYL};e)MDeQXB^O^j`1xaASH_gN|5CVX|NG57>Ht*3 z!0;aknAWr~f;mbI3dh$pGD$74yV0gB!PWjy@L3?s&Mws(6CeDO&(fIfFTDdv>DCWX z-zKvbN2Sd?_9JeWWcG=w=`)e|m!(eQsI9mlIEo?h2vf4ELJJef(#`s?rS<`+I^PX6n5$5WWo`gO2w zs{e!gH@h#Dw%(bqDN=m&7MB471JE!C2KuxCYKh{^6dsTzf*SFE<@H>5+|t{ut5Yer zsgow+&z9e1=5vl( zXV%yh%2}y;?9#bgFWV{;m)mm#C5?XZY_a#S+9B@B!Vap1UHdk^SAAb7tI zLZg$OAOTR^F*@)vgC&7+S80DOFC1LLC@_(v)T8*I&*F-GJD9FwRVTb`zos( z2$g>Ha&m7|mrVeJXvnM?(R+LI*Z)&wUiB#d*TLr>iuIUU>RI%@ZZg%;eOT*$Im{=| zv&-b{&%43vl-LMbB!ev!Ac>KIL5Yo^Gi0!(2PFN394Uh>s$u#W7#Tr<^(Qm!%ABuj zte2(Q%bot``i(>St73SOcyZo_0>GNW~2M?~Vn&0(t z&9nPT?()IkygL+`O>@q%oO^xfnOf)*r#+euPxv4ARhG!M|2w+hW%q5<%;mtqVj^gf ojE2OF%@|1r6sbV0#6-{;G6sLA?7*X+kRxS^7HxQfOFshx00L^H^Z)<= literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-21.ms_fp_relabeled.psbt b/tests/data/psbt_test_suite/TX-21.ms_fp_relabeled.psbt new file mode 100644 index 0000000000000000000000000000000000000000..1d9e9719aadb2a2492e739bb580cd4b51ec395f2 GIT binary patch literal 1156 zcmXRYPAd7&$k55ez`(#5^=(aYL};e)MDeQXB^O^j`1xaASH_gN|5CVX|NG57>Ht*3 z!0;aknAWr~f;mbI3hJ&2Oa^E7-p^Gz>T~vo?A8F|XSq$h0lw3^PMvtax$+Z|QYo#o z7TRqyjf!I5T~?DVU822T;mhi~-y5%fEli3?d>;%l(w~u~W0M?<%%|yM4GauSyB8ck zCC1gx_iv}e>IoOVX!yU9j^kAnPp@mTKU}99p3Ed={q^^E^9!FdC;xT3<0;H({W@4T z)&If$o86a6Tkp)*6e&J>i_3t40caQm1AW>6wM21d3J=H$HSJClr=FEYWc^5?7oK|jh)}Elg=_DD zxeV|3L1=W+6C?nNLPiH(X0RkM3M+1NL|fFYGq|#}MK924|1!aF&ZTRDo7+E>`#-o> zt^N|Ej*&GpNRi1^QZ4V=n!6ob3*4>$xP({6X-Q`)GU&OTXg2%)S7**`MP?5fv)1m= zcwc3e1EJE7UQX_9>aq!75Dl3%BYJOd{`!B4%&Q*d|2p{mL$MxHOFfI;*G;B6x({pJ zFNgW$d3Kqc{dqTdoe~>Ci)63{2G~Ok3`%SSogsrQSwPY>SU(|0%3zCen0^LEMo?g} zhVGQ(e|cJSV*2XUZDu!4PXEAW!NstgQTWZ8HFlfDZ55f7Vpt0mPPHF+`^eW*sb5>m zVtJ?G6>aeeDT|IBy3)A$n<8_ri*t*qXkY$e8QV2`?%b_?#-*52D$>Ss&(NA*YewJ{ oU|=y3v`FUO+I{cQQw}&%frJthL1$p~ERudgj>H;SF#QY+09Rp?*#H0l literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-21.ms_repointed_keys.psbt b/tests/data/psbt_test_suite/TX-21.ms_repointed_keys.psbt new file mode 100644 index 0000000000000000000000000000000000000000..3add9605769bda862cd929ebf5d9075864f4e339 GIT binary patch literal 1156 zcmXRYPAd7&$k55ez`(#5^=(aYL};e)MDeQXB^O^j`1xaASH_gN|5CVX|NG57>Ht*3 z!0;aknAWr~f;mbI3dh$pGD$74yV0gB!PWjy@L3?s&Mws(6CeDO&(fIfFTDdvsoKkj zhg&qeH!?6x%UJqJ*W0jJk@b?d8~Zb{$^Upbf9(bt>Ced0u}O|a=F@bs1_lPE-3yMN z660#;`?u3!^@IywH2hyl$MGtPr`I*vAFk64PiB&`{`&j7`GwD!lmEKi@f7B?ejTiv z>i^*W&F)L3t#{^YiWDEc#bv<205lAOfj(`3TB0~Jg$HDbpho;(c|F%1xAZpa>Qu_D zsx1pPs5`D^$!H_9tLXSQbLPOxybB_3PAfM$YtPiL(TY=6v-mk<|G6By9(oo)L1{iw$}*jQ^tXJQx_ZLdv*mZ0`JAKH znKd?ra#pGyyL9f>%eKnIrFYNhHSEpeWymOMJ1kf23FB`TpvQo5#}EgO!nOCn zT!#1iAT&DZ2@(KBA)^B?GguNBg%!6sqAlvy8C+S~q8I42f0J1@6{=T*52kw4^f?8T8yvG@E_@t25`eBD05#S!;J_ zysxs#fl%p3FDLglb=d?kh=$CX5xuuJfBip2=2egKe;s`Op;(WprJhCa>n2kj-G{aA zm&1JWJiAQJ{=6H!PKk}6MKV|e1MDFN1|>Fv&XB>DEFftbte=o0Ww6CKOg{r7BPg)` zWTsu2^L35&vQ&Gy)Bjw*aY%nv3@@_WUC{aaMIL{tvm&$XK?~1S<{M&{KNcu`Ud;F4 z!Sz-1yFRXYc3;U|KKPq=ha$6S&N-HIuMa&_3w`3WN7La6|Kq;O64~~DNB6tzzHOSh z92i(kOst_h<@jHo)|{BWdUc!Gjg!+quvu_1EN2vcvu2ImW^r4ro&`rLkWgY`R*GRQ zR5;as;O!${Po;isEsN!yhF7%3C!{PocIZmu=5JU%i=;o-#ks{)v@id#jP05|ckb3c b<5Em16=`F+XK2l@H6w5e*2seCXJ7yTt_hcN literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-21.ms_repointed_spk.psbt b/tests/data/psbt_test_suite/TX-21.ms_repointed_spk.psbt new file mode 100644 index 0000000000000000000000000000000000000000..9106498a4266d1cc2ca0c0c293cc1d88ee0df040 GIT binary patch literal 1156 zcmXRYPAd7&$k55ez`(#5^=(aYL};e)MDeQXB^O^j`1xaASH_gN|5CVX|NG57>Ht*3 z!0;aknAWr~f;mbI3dh$pGD$74yV0gB!PWjy@L3?s&Mws(6CeDO&(fIfFTDdv=`E93 z76-BK5<=Q9DnA`rdFTJO*{n5q(37|$0j)znNQQj8W`)e|m!(eQsI9mlIEo?h2vf4ELJJef(#`s?rS<`+I^PX6n5$5WWo`gO2w zs{e!gH@h#Dw%(bqDN=m&7MB471JE!C2KuxCYKh{^6dsTzf*SFE<@H>5+|t{ut5Yer zsgow+&z9e1=5vl( zXV%yh%2}y;?9#bgFWV{;m)mm#C5?XZY_a#S+9C5*pWfF1+J9YY*A3fJBP za~a<6gV5-tCrAJkg^Uio%wS1i6jt2kh_7PwpgaS5-C(~{0qWYBXv(QNkpug;v?ip(A|X06?! z@xIC`2STMEy`0?J)MXREAR01jM)cm^{Pq77nO8l^|8?;BhhjaZmUxh^XxJ?`}1z_IwdxO7Rg`@46uh77?juuIzt9qvVf#%uzo_0l))C`F#QaSjG(|` z4c#fn|MIlv#Prpx+stm9oc@8$f{S4}qwt$GYwR|Q+bS|E#jqACoN7Pt_K~lrQopvA z#qv(WE85}{QWhOMbft0gH$~=L7v~mJ(Z2k{GPY~>+__u(j7u@4RHTjNo}o3r){MX@ jz`$Z6Xc1P=f+H13C@~Rq23F4^=_lk!tdRxN&%gixRkM(G literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-21.pays_us_claims_other.psbt b/tests/data/psbt_test_suite/TX-21.pays_us_claims_other.psbt new file mode 100644 index 0000000000000000000000000000000000000000..caf107dd22c74f6eac79f422e14523efd6886bea GIT binary patch literal 336 zcmXRYPAd7&$WX|{z`($mm3UHS+0mU^XS6MEJ16b7sNZAov{d5#zsRkBFMa#eW(`!s z!0;aknAWr~f;nOgA_vaxxpw&Ssh-k1amV!bg&Ony6nKOrefG?;mXO(zH&$+6Fz4!= zj46D7G=G4!GX7=(o508@@4(9pGtACpM(nBlyC;8}&2)Hj{Klhp`=B{WY|Ko-Djj`J zvvxeby2B0}$3~?Qh$H<7oiAqe& z23P$r+;!s0i|;j4`TE&IXPqg3<<$?R)?fF%pQAf*y^X}Zwfo*9n+h}!0>GwX^%($5 CpMpXF literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-21.pays_us_claims_other_V2.psbt b/tests/data/psbt_test_suite/TX-21.pays_us_claims_other_V2.psbt new file mode 100644 index 0000000000000000000000000000000000000000..fc63ad12a41499a01df2da0b9d6c8113a22dce36 GIT binary patch literal 363 zcmXRYPAd7&$i%|Lz`(%B%mO4C7+Dw@8Ce;b7=MFB85kMm9e9~RG7Mr2B6cP-Vo&AY zJ^9;gro)rtHy*Xy2hCApV`d6g>F9Hswd3*a_3{-=Dcy4}$jx?aX+8SOM|yTR!^33~ z#Yb;(g)lHQ08Ig7Mj!(O82J>k5>Lu3JGxWrjJD-%=cL^h^?MASmP)+;7rFKCrEj0w ztQq+s?h;`64+KE>0G)B*+@5QPFQ4iuy%Tp#Z(pb}-%o)@N=(cKSN$*Cb>hm4?=@5T z`q@Kgohg6i)eoiCU-!MAqdRfEjl{jR``#lv1L6pfr*Rm{$jq^(1?pI^%{MLYEk1C1 Z>xZO?D<=z`KI-1X&u|;88>+F z!0;aknAWr~f;mco3TL{!kNI|1-#z;K(6@r`D|T^Pq*n^$d{nZ@KYIOa{y|YBrQfE! zQwiJ|WPg8B&c25~A348UC+z0Pv3v8`_=@C>S1&vU8OivY1#B`SqqYMtGt3gp`O^B% zlRwRpIBDKGC-%nj;s61|@YfyuOfL>JiKy4SR}>?pLXx5Q=q;`=28ITpnP3d@0nkQq a1wxt`6xj)RQST;W~N}3jy|VZ zJ09O&FJHlw(mm&b+-%2|)}z0Cq-TdSJX|JGeDoGq2m?a{&>S#^xDLo;WW?b_B_?Kr ztNs`6I&tO2_nN7E{p_K$&Xm9M>W5P6ulwH5(Ve*72E$aKd0?Q(PDraH1G8@iXb=iCN z{cuZEI|S0o_?rc60wbfm11~eoFgueOv8VFyp8Rb#)8WbS8;{!UgXSo)F*60Lbo4pR z+VS}Idie^blyHCBRxBu;o≶-j~?LKqktfaZWP#B~e|ieiMcN;2Tm z%fQHp!+T0h%m!EeFWhzF%8TzcQ~CPYLuZ{Sf92H=rPg2fy`Q5yalH+Oi@-hv5nxlX Gh6(^oT#-)z literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-22.ms_decoy_first.psbt b/tests/data/psbt_test_suite/TX-22.ms_decoy_first.psbt new file mode 100644 index 0000000000000000000000000000000000000000..b709b5add1a4ff1e703529c5be31034178338593 GIT binary patch literal 1220 zcmXRYPAd7&$k55ez`(#5^=(aYL};e)MDeQXB^O^j`1xaASH_gN|5CVX|NG57>Ht*3 z!0;aknAWr~f;mbI3hJ&2Oa^E7-p^Gz>T~vo?A8F|XSq$h0lw3^PMvtax$+Z|(oS=q z$yy?scFPx3?ongf96952vblRy>&{LTF(R->Ced0u}O|a=F@bs1_lPE-3yMN z660#;`?u3!^@IywH2hyl$MGtPr`I*vAFk64PiB&`{`&j7`GwD!lmEKi@f7B?ejTiv z>i^*W&F)L3t#{^YiWDEc#bv<205lAOfj(`3TB0~Jg$HDbpho;(c|F%1xAZpa>Qu_D zsx1pPs5`D^$!H_9tLXSQbLPOxybB_3PAfM$YtPiL(TY=6v-mk<|G6By9(oo)L1{iw$}*jQ^tXJQx_ZLdv*mZ0`JAKH znKd?ra#pGyyL9f>%eKnIrFYNhHSEpeWymOMJ1kf23FB`TpvQo5#}EgO!nOCn zT!#1iAT&DZ2@(KBA)^B?GguNBg%!6sqAlvy8C+S~q8I42f0J1@6{=T*52kw4^f?8T8yvG@E_@t25`eBD05#S!;J_ zysxs#fl%p3FDLglb=d?kh=$CX5xuuJfBip2=2egKe;s`Op;(WprJhCa>n2kj-G{aA zm&1JWJiAQJ{=6H!PKk}6MKV|e1MDFN1|>Fv&XB>DEFftbte=o0Ww6CKOg{r7BPg&~ zLwCyYzdWruF@5#wHnSTir+;9x;9^+LDEwy48oSNnwu;P3F|36Or`iv^edOz@)UT~& zvAompinjQKltsr5U1{9>O_4d*#ks{)v@id#jP05|ckb3c<5Em16=`F+XK2l@H6w5e zFtC`ILvJ#ieE6+)PuJ1I%#}CUHl`OWoO!8lq5d|uqpw#^h|0q1Sx{Jkl8h1)L5Jeh c5Arb3enQ^B8dxCvq527V5^H3`^fNF303Al9{r~^~ literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-22.ms_decoy_last.psbt b/tests/data/psbt_test_suite/TX-22.ms_decoy_last.psbt new file mode 100644 index 0000000000000000000000000000000000000000..973004eb4a932554d9abc1ecb1dd0d120d4256f9 GIT binary patch literal 1220 zcmXRYPAd7&$k55ez`(#5^=(aYL};e)MDeQXB^O^j`1xaASH_gN|5CVX|NG57>Ht*3 z!0;aknAWr~f;mbI3hJ&2Oa^E7-p^Gz>T~vo?A8F|XSq$h0lw3^PMvtax$+Z|(&=|E zJ#u|_lo)mq@`1Dpqc0JRw;>WW=M*1_dbZnAik@+-Ttbu`nY4?KT zr^LA0`Tp&6SUusw7Y+Yc(s8_s;^}ow_J`|q!;_h$tiS&LZhql&=H$O_cRYnTtzQT0 zrusj)f3y2iY3rT&nj*zVZ*dtgFaQmMV4zPMpq41kOyL1pBB&AnS6?%6`&73)~GVg+jo72jT&e}8eYqa8&)hvF_*ncj^uE(p{vTK)@ zh(<~P8xBj}75+F1vc%%@2ByFz$s7K^+&cA=cu<;8l(J0cAN?)grmmiF_H6lGWq?O!Gs&bf3=aC7^Ia{mYS zs?}eD)G@MV1}QSRN~+~uTXVOAYk|AAp&0qgdk$Kgl{9gy3e<;>tYN=<@`?|?gNB3c^ z`{gj7JkKtZvp??!uTx?pXps!ozyN!QfkBClpfhB!B@0NJ2J0u}NEvJ~4%5%T$OsB7 z*3g}D{4Y;yPE23Dy3Opy$>|^1EVvk!GYY?1v&L?-xUC|yQVeUM!m0KHZy))3D)nn? zSuF1~yrL~WA!X6ALsuF%e^X@6b#ZPn746GEEMvQ7&z-xq&$tv*N=4dO?ipJ1Yt0Cp z0t_rBf)-)*EI3kugc1`$XJGX#l72#t#2Q&h`a^FroP7ALc2C#Q!_1X8**2yZES!0% XZ=wD+wxh3CPKe6F>3&d>XJ7yT6Pl}N literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-22.surplus_paths.psbt b/tests/data/psbt_test_suite/TX-22.surplus_paths.psbt new file mode 100644 index 0000000000000000000000000000000000000000..e27f0f32e080b463aec4a959a4d118722dbbe1ec GIT binary patch literal 396 zcmXRYPAd7&$WX|{z`($mm3UHS+0mU^XS6MEJ16b7sNZAov{d5#zsRkBFMa#eW(`!s z!0;aknAWr~f;nOgA_vaxxpw&Ssh-k1amV!bg&Ony6nKOreO2-9)>)Q98J8nZ{_uFv zt-P@6S1Cv<<8KzQ35<;L4!q1T!|Y6E#GcB(d-Av0Oou1OZ#-(Z51OOI#>^C~($VKM zYscf;>*Xt$Qo83{kelt;(t7llkM!(thKI`}ijUsn3SnSq0Gb2F5Z3{DjEp#(sKmr< zaMl09T_>)*_+B%Wub(}1)|v8GUj0yN{dM2_Il2?q+hCXqG!G1bdY_m64g7F_$Jw^n m`5(_LS{QLYRsQAlzbF5_Ja~EQ%c-x*vFZi83hW}Rp#lKuewnNQ literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-22.taproot_surplus_internal_key.psbt b/tests/data/psbt_test_suite/TX-22.taproot_surplus_internal_key.psbt new file mode 100644 index 0000000000000000000000000000000000000000..8e5070a55a041d1790665ea5ce371f82effc272f GIT binary patch literal 417 zcmXRYPAd7&$k55ez`(%x(f*a?1C#s4+Tj%^T5cF!Ph2h4@p+F z!0;aknAWr~f;mco3TL{!kNI|1-#z;K(6@r`D|T^Pq*n^$d{nZ@KYIOa{y|YBrIVLf zUCMpLlU*x+XJwP8eD8k=>1T5r?Qc!k#>8cLy6+>%NXFkRV3QdcwHH2z{n`?z{?CX%+6#+?5X^_Cx4sGba-<7#-n!opgBrx%uK;59eqx- zc09hlUcQ1UrF+f=x!H~_tw(?PNY4&uc(_cW_~1ps`%ju8L= literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-23.forged_input_claim_V2.psbt b/tests/data/psbt_test_suite/TX-23.forged_input_claim_V2.psbt new file mode 100644 index 0000000000000000000000000000000000000000..f1aebca550eefc0c5e0952f908e9f85ecc8cad9d GIT binary patch literal 423 zcmXRYPAd7&$i%|Lz`(%B%mO4C7+Dw@8Ce;b7=MFB85kMm9e9~RG7Mr2B6cP-Vo&AY zJ^9;gro)rtHy*Xy2hCApV`d6g>F9Hswd3*a_3{-=Dcy4}$jx?aX+8SOM|yTR!^33~ z#Yb;(g)lHQ08Ig7Mj!(OfO=V8^SwOUr2Xz+((Ugr3^FwOPWCO~Pv$U{>8v{U+&@?e zt6p}XUPeBJti+Qt%Z~2UI-_lQ+c{~sMg1Owr==3_|3z;7d+FP!Hfu(Hh@S*l{sRHf zFF-FGIJf88;mfCbO7FxS)7uwn%=c5^krETL!BzhYcb&NM;(N_hzJB)5S!c>$dG$l7 z_1Asx=jcvcZ-e0su=_#IV8LN1BQwXE7N|$THvcwJt8ST;W~N}3jy|VZ zJ09O&FJHlw(mm&b+-%2|)}z0Cq-TdSJX|JGeDoGq2m?a{&>S#^xDLo;WCS|#z_~rw z4qraiQ+g-vnBKlnW4@mPkCd30IKD5r*6G_}vA1c$sf7PKx@EGx`^5wn>c2gy;dJA{ QcUP>YvH}f-n2ObB0BQJmYXATM literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-23.forged_output_claim_V2.psbt b/tests/data/psbt_test_suite/TX-23.forged_output_claim_V2.psbt new file mode 100644 index 0000000000000000000000000000000000000000..c75c7f55e21017dabb9074d79b1fbd0b12c81178 GIT binary patch literal 363 zcmXRYPAd7&$i%|Lz`(%B%mO4C7+Dw@8Ce;b7=MFB85kMm9e9~RG7Mr2B6cP-Vo&AY zJ^9;gro)rtHy*Xy2hCApV`d6g>F9Hswd3*a_3{-=Dcy4}$jx?aX+8SOM|yTR!^33~ z#Yb;(g)lHQ08Ig7Mj!(O82J>k5>Lu3JGxWrjJD-%=cL^h^?MASmP)+;7rFKCrEj0w ztQq+s?h;`64+KE>0G)B*+@5QPFQ4iuy%Tp#Z(pb}-%o)@N=!@~-Z-)TY!YpY-zkIquLK!bi{RD1mijl|a%B04!{Jvj6}9 literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-23.forged_taproot_claim.psbt b/tests/data/psbt_test_suite/TX-23.forged_taproot_claim.psbt new file mode 100644 index 0000000000000000000000000000000000000000..ec9c964f0676804cdf592ad420f5eb646cd99759 GIT binary patch literal 417 zcmXRYPAd7&$k55ez`(%x(f*a?1C#s4+Tj%^T5cF!Ph2h4@p+F z!0;aknAWr~f;mco3TL{!kNI|1-#z;K(6@r`D|T^Pq*n^$d{nZ@KYIOa{y|YBrS}A` z80UJdVV(Lp>u1H;?pJ@=OIuFMn$)jUvUnQc-mn{FB;#)uu*r;!+77(TFiR}wOY1vN z{xnPCq0|X4iUw7~`y*SV$qF(b}QH+oZNrvL1x46O>7#e_Pf-%GgKpVvs z2x(?eWGCcJO!L8R2NH_x*(Y*E?@he6YFGCGivp4Je@wcazpj~O`=r08clmDjOA(lQ KL2ly&8vpST;W~N}3jy|VZJ09O&FJHlw(mm&b+-%2|)}z0Cq-TdSJX|JGeDoGq2m?a{ z&>S#^xD?1^WW?cIB_?KrtNs`6I&tO2_nN7E{p_K$&Xm9M>W5P6ulwH5(Ve*72E$aK fc@O|L)kpn>W5MhPPA@;z2J+Qvtqfb)!_NQ!PECTz literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/XTRAS.ANYONE_CAN_SPEND_OUTPUT_V2.psbt b/tests/data/psbt_test_suite/XTRAS.ANYONE_CAN_SPEND_OUTPUT_V2.psbt new file mode 100644 index 0000000000000000000000000000000000000000..c991bbd286c4d559471b7bd24d6f8aaa435a4d67 GIT binary patch literal 375 zcmXRYPAd7&$i%|Lz`(%B%mO4C7+Dw@8Ce;b7=MFB85kMm9e9~RG7Mr2B6cP-Vo&AY zJ^9;gro)rtHy*Xy2hCApV`d6g>F9Hswd3*a_3{-=Dcy4}$jx?aX+8SOM|yTR!^33~ z#Yb;(g)lHQ08Ig7Mj!(O82J>k5>Lu3JGxWrjJD-%=cL^h^?MASmP)+;7rFKCrEj0w ztQq+s?h;`64+KE>0G)B*+@5QPFQ4iuy%Tp#Z(pb}-%o)@N=(cKSN$*Cb>hm4?=@5T z`q@Kgohg6i)eoiCU-!MAqdRfE4TduyjsSTYhoOwj9BW#jjs@G?w4T@PK-1Tzw+yow zZLbHcJoTZWnvq2*R6#g!ZAnMaqMX~(GnH?i)GCoXAhlqru>yxKa^U3-S>Wu?!@&r7^VWvg8;CpOLx!QCSdJb Sawd4^|G?G8!D*c3x(on>=#}vR literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/XTRAS.BARE_MULTISIG_OUTPUT_V2.psbt b/tests/data/psbt_test_suite/XTRAS.BARE_MULTISIG_OUTPUT_V2.psbt new file mode 100644 index 0000000000000000000000000000000000000000..1afa322c5318a8222c7a23b8de85f47f4bf8f0bb GIT binary patch literal 412 zcmXRYPAd7&$i%|Lz`(%B%mO4C7+Dw@8Ce;b7=MFB85kMm9e9~RG7Mr2B6cP-Vo&AY zJ^9;gro)rtHy*Xy2hCApV`d6g>F9Hswd3*a_3{-=Dcy4}$jx?aX+8SOM|yTR!^33~ z#Yb;(g)lHQ08Ig7Mj!(O82J>k5>Lu3JGxWrjJD-%=cL^h^?MASmP)+;7rFKCrEj0w ztQq+s?h;`64+KE>0G)B*+@5QPFQ4iuy%Tp#Z(pb}-%o)@N=(cKSN$*Cb>hm4?=@5T z`q@Kgohg6i)eoiCU-!MAqdRfE4TduyjsSTYhoOwj9BW#jjs@Ginz4Gli{{D0M!&u* ztK1KolJZH`k&(qcNRg?%Vww7S!9^~j%kxfr&3Nq3KV98GWb>9U-03`5FWG9=Dl+ew pysqHby-C(u^HyzNF1gt&q}Rh{;j`O|cJ-|h`t!))RnR(Q>i{~$l;i*a literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/XTRAS.DUST_OUTPUT.psbt b/tests/data/psbt_test_suite/XTRAS.DUST_OUTPUT.psbt index e26bed1b0a61f88f0b3d0706b10ac7fdcb5bc355..8eaa7cb6afc4ce58386af02e097054e9f3b281d3 100644 GIT binary patch delta 52 rcmX@fbdqU8qR4ke#kBi}e;PRW&)LVK{6=KW?_c*PmhKnDCe8o=pw}8| delta 52 rcmX@fbdqU8qR8D>o972Q=*^2awcj*HZHlS7#P^7arTay(i8BBIZV48i diff --git a/tests/data/psbt_test_suite/XTRAS.HUGE_FEE.psbt b/tests/data/psbt_test_suite/XTRAS.HUGE_FEE.psbt index 3d3bfc7123657f246581c814354d0ab8b6742bf6..2e1546fb15ce48b62429b5cace4ebda1b2f403c1 100644 GIT binary patch delta 52 qcmX@fbdqU8qR3~#%4C7em#-ovh2OEyW@U;HvOYhtbiXJzaRvY=qZ94` delta 52 rcmX@fbdqU8qKLBb3(?!QFEYOHZr(g8!u!awCs)@`EZr}PO`HJ$p{W|k diff --git a/tests/data/psbt_test_suite/XTRAS.HUGE_FEE_V2.psbt b/tests/data/psbt_test_suite/XTRAS.HUGE_FEE_V2.psbt index b333b1a755ab58619f9e6c45d7b0923a9b19144a..61f3639145fa954fbbfa7d0871638d5aa2f5a0a6 100644 GIT binary patch delta 65 xcmaFO^qOgd5u>HxYu<XTfZImX@qMnT$S8b-yQ;8rD0_y?)s-RPyR)moL|Lc;(!a z+!AZ%9i?dP)fxC_@0}>SCyF<2ZWBySm(4hsy(RHWz5V`tquaNREj=@xcg{)03$K31 zpDto&GGDn yA)_{O)x4PLrFY-GHT{=mVVPIEg1N@irTn8!ng8a(;%zQJXHCvyoFR(Mmka8Q#p{lo)L%ZmE6O}!`lrozjvsNeF>_g|;4;mqeNFRPoio$2+@`h% z&VO2^%Jf5f(N6Bjxt{5z>N1)N+sYT#n}3!!;Z%?l*6Kf!TH<+O4O>2=?=rE#-l;N) zR?nqobDiI_!D4M3+Y6(8LEG9rPkoI)d#h7+>6B?}PtQM-z0GQJ9^(vAY`$aw0DVq* As{jB1 diff --git a/tests/data/psbt_test_suite/XTRAS.MISSING_UTXO.psbt b/tests/data/psbt_test_suite/XTRAS.MISSING_UTXO.psbt new file mode 100644 index 0000000000000000000000000000000000000000..02bd32413443581ba6b9fbfd33bad55f467d1cd9 GIT binary patch literal 302 zcmXRYPAd7&$WX|{z`($mm3UHS+0mU^XS6MEJ16b7sNZAov{d5#zsRkBFMa#eW(`!s z!0;aknAWr~f;nOgA_vaxxpw&Ssh-k1amV!bg&Ony6nKOr-5?cvZ2mu+eWxbBK zy~P#6z|a8H0LBozfjmY=91c)oVm7$yf8nkZS6+OtnabDC9y;qx`75t}D7F5&@BJLz SiR*1JOa+<;0bohm4?=@5T`q@Kgohg6i)eoiCU-!MAqdRfE4TduyjsSTHhoOwj o9BW#jjs@F%_4%Q96V2~Dxv~9SuGp)VDfYY7CW3Wil|a%B0BfywC;$Ke literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/XTRAS.MIXED_INPUT_TYPES.psbt b/tests/data/psbt_test_suite/XTRAS.MIXED_INPUT_TYPES.psbt index c36499da25d02b197923316090e81c7b5f0aebb6..f285d1811eaa11e409d0ce0fe391b62cfa83116c 100644 GIT binary patch delta 53 rcmZo-X=0hsC9-Ip3)gau&kt^}>;5>-lpyigd3(afdH#%|*d!PLa{d={ delta 53 rcmZo-X=0hsB~o(lX;`1Y?)IICR@0^_#j4WadB3LDuIsQWd0{|nlBJ2PF delta 65 xcmaFO^qOgd5u+tX$JyQ&g%t&Bd7oWj;CjA4&w6_xBa0Y=2v!MZj{i`=0066NA1VL< diff --git a/tests/data/psbt_test_suite/XTRAS.NEGATIVE_FEE.psbt b/tests/data/psbt_test_suite/XTRAS.NEGATIVE_FEE.psbt index 16c9d431ea336fea3be0334e700e64b977be57d9..4f30fb08bf0cf76a870a4d7017bd85aabb221f92 100644 GIT binary patch delta 52 rcmcb>bb)C?qR7sG(ESFvU%kJ*{~EaA?)k!_hW|V#mL3zuCe8o==B6C! delta 52 qcmcb>bb)C?qR2;vjnd0<k9K@_R@m+?nZbc30WCPc#r$tF z`s?bY?AQZT$H4F(2$+1hnI~Gw$O9>`m>7cyj|~5!ExUieh=|I+BGDClzVz3oSrbch zBjp`<;cA@JZYgl00w6qBme*a delta 53 scmey!^pR;oqDaV&(?2!+85T(H`S57ko^4Cr*ov=CEPW=1O`L%N0M{fMjsO4v diff --git a/tests/data/psbt_test_suite/XTRAS.OP_RETURN_BURN_V2.psbt b/tests/data/psbt_test_suite/XTRAS.OP_RETURN_BURN_V2.psbt index ed9391f03c329b0277a08c76c0d24cb6fd66f7d6..a5e0298fda0b55363514581824ec112ea8f5cb6a 100644 GIT binary patch delta 57 wcmbQiJcD_I5u@(O1N)!-a6P!;*R|poXEW!2$?Cmo&&VRiAc9R|ay+9Y0DhS=Bta_r(QevfO}upTA4(S=41Dy8Ck>_M6gLrj%Tz40Oi*ing9R* diff --git a/tests/data/psbt_test_suite/XTRAS.RBF_SIGNAL.psbt b/tests/data/psbt_test_suite/XTRAS.RBF_SIGNAL.psbt index aef2353afea941572bff35854fbe082f1af685e5..9e5e458aec07ddbac623c4fb9f40ce51ee78f1b7 100644 GIT binary patch delta 52 rcmX@fbdqU8qR1o3WlOkz^~pcJcDPTIUxLHr>Fae9OZSUn6K4PbiO(2{ delta 52 rcmX@fbdqU8qDZ*oo^JD*cT@!zbR4{Xbe>~dclh>+rTay(i8BBIg-ICx diff --git a/tests/data/psbt_test_suite/XTRAS.TRUNCATED_PSBT.psbt b/tests/data/psbt_test_suite/XTRAS.TRUNCATED_PSBT.psbt index d238404f30d5bddf0fd4986d7f9b44936ba7670b..f09a34783b17a049f704c09e838d0ce88e03efe1 100644 GIT binary patch delta 30 mcmX@gc$9HMqDY>*!U+}T#;~e~7MAPRcv|fJ$+%-;X#fDWSqz#0 delta 30 ocmV+(0O9||0mT83VHCGt2^YxRc{SX}(~~%LpRazd(gTroP}RW>bpQYW diff --git a/tests/data/psbt_test_suite/XTRAS.UNSUPPORTED_PSBT_VERSION.psbt b/tests/data/psbt_test_suite/XTRAS.UNSUPPORTED_PSBT_VERSION.psbt new file mode 100644 index 0000000000000000000000000000000000000000..9c50c1e7b7578cb57b96f9c280822d5d1b36f751 GIT binary patch literal 336 zcmXRYPAd7&$WX|{z`($mm3UHS+0mU^XS6MEJ16b7sNZAov{d5#zsRkBFMa#eW(`!s z!0;aknAWr~f;nOgA_vaxxpw&Ssh-k1amV!bg&Ony6nKOrozr?-dhKMb*Ux6}i<`GP z>fsBOMGrt)8Go~YjbLPyci?4)8D?iPBlcAO-IKq~W;#4Me&bQQeb5{wHfE+^m5x5A zSvwxzUN2w4l+r!tg4}G!me!-ce57ZGGdx@-QGE0kR|o?`1JE2WhPV#MV`RkPL?tF> wgRA}*?mBVh#rK-2eEsa9v(A*i^6H0D>#zIX&(WQ@-Uh=|pm`7gHWjPS0K27tj{pDw literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/XTRAS.UNSUPPORTED_PSBT_VERSION_V2.psbt b/tests/data/psbt_test_suite/XTRAS.UNSUPPORTED_PSBT_VERSION_V2.psbt new file mode 100644 index 0000000000000000000000000000000000000000..b6f5bc738fcec05bda91da154ee076a7ebe4fcd0 GIT binary patch literal 363 zcmXRYPAd7&$i%|Lz`(%B%mO4C7+Dw@8Ce;b7=N=cgZYf|4!mF%gBXK|oym;YQ~7sK z{x+NG@Z|W7NA31ObClSanSxb1`kZF%czk=kd<9cV_nZrIvmIMnkN)zJo*mBcaG6B$ z(OX<03=9oG6Tz4fWHb;k@+o8`o|IX3bf?xCZOhxvNxLoT_ZU1am3aRza_iqq-#)cj zGx9^+CBX6@2pAX{fzCK^ZqK#DmrwPS-ibS=w=dL~@29{cB_?KrtNs`6I&tO2_nN7E z{p_K$&Xm9M>W5P6ulwH5(Ve*72E!Q;M}Rzy!%#+Mjx{Y%$AWFXJWXR|-W01JUmPyV TwU%$cdC`8YB3L(82_)SBwPAkM literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/XTRAS.V2_MISSING_PREVOUT.psbt b/tests/data/psbt_test_suite/XTRAS.V2_MISSING_PREVOUT.psbt new file mode 100644 index 0000000000000000000000000000000000000000..889e7b582c2f2ecdd871130b3bb0dd8c7da92115 GIT binary patch literal 321 zcmXRYPAd7&$i%|Lz`(%B%mO4C7+Dw@8Ce;b7=MFB85kMm9e9~RG7Mr2B6cP-Vo&AY zJ^9;gro)rtHy*Xy2hCApV`d6g>F9Hswd3*a_3{-=Dcy4}$jx?aX+8SOM|yTR!^33~ z#Yb;(g)lHQ08Ig7Mj!(O7zJ4V0|C$$py3D3?YVaN@~NKEJ8{SK_Jtbr{SC$7BsUNe=ipFMQeneta&{ZMNCb>I6rx)ayiU>FWD8srrmhB7j9tZ9Kd0c>;3 eyCb4z!OC*)th_IaOP}4o;2CQJST|M)B;5cO189-} literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/XTRAS.WITNESS_NONWITNESS_MISMATCH.psbt b/tests/data/psbt_test_suite/XTRAS.WITNESS_NONWITNESS_MISMATCH.psbt new file mode 100644 index 0000000000000000000000000000000000000000..04238b39a5b697bb6da22af887dff58f6627e8a3 GIT binary patch literal 383 zcmXRYPAd7&$WYG2z`($$nN?V-llJ?|!`i5qehu{#-M=NV?tJ5MEBBDney?rcrUBJ3 zF#HDsrZp{$V2)(jN|6KS_FOxB`BYEoow#Fq`$CQRehNJ5Sc9xWIqc~yrRt*9pOO~z zrM8*}tnyl8(y<0)0OM~KusMtjpCQFIFLk(bryJ^-Dn#Kz1N ztkTivG;7D>+w0{km{PjuT#%dX*wT9Rmyh)9aE6D=B#MvT;tFA4XaL#?#t<`sJS8S( sgRA}*?mBVh#rK-2eEsa9v(A*i^6H0D>#zIX&(WQ@-UdT6P#Y8g0Og8;rvLx| literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/XTRAS.WITNESS_UTXO_MISMATCH.psbt b/tests/data/psbt_test_suite/XTRAS.WITNESS_UTXO_MISMATCH.psbt index 1a14c37e558588ba38c4fa90c4d5207803d39838..7f18e6d5d1d425a687643eb5aeba834337383dd6 100644 GIT binary patch delta 99 zcmcc2beU;FqVwCoeVtoHWr82p_`3>s^|QJO{QbrN1dP8~KokQbqmlzJGngq^wo*ii fW5VGX+`_7&B@fqIrJuT|Rb?<|;*wdSSd9SyjxZwk delta 99 zcmcc2beU;FqI3Lpp07ufrW+Z$O?bKUc8Gb1dSDF$5HS8`0Z|N$j7ko?%wVQu*-DYQ f8nrhwfBrr6S)#A?ZNTY&J}ZqUPFyle6ss`+73(IL diff --git a/tests/psbt_suite_util.py b/tests/psbt_suite_util.py index c7b19a68a..075375d58 100644 --- a/tests/psbt_suite_util.py +++ b/tests/psbt_suite_util.py @@ -81,6 +81,9 @@ class RejectCode: FORGED_OUTPUT_OWNERSHIP = "FORGED_OUTPUT_OWNERSHIP" FORGED_INPUT_OWNERSHIP = "FORGED_INPUT_OWNERSHIP" SEED_CANNOT_SIGN = "SEED_CANNOT_SIGN" + SURPLUS_DERIVATIONS = "SURPLUS_DERIVATIONS" + MISLABELED_OUTPUT_OWNERSHIP = "MISLABELED_OUTPUT_OWNERSHIP" + MIXED_DERIVATION_MAPS = "MIXED_DERIVATION_MAPS" class Advisory: @@ -94,6 +97,7 @@ class Advisory: DUST_OUTPUT = "DUST_OUTPUT" FUTURE_LOCKTIME = "FUTURE_LOCKTIME" RELATIVE_TIMELOCK = "RELATIVE_TIMELOCK" + SCRIPT_TIMELOCK = "SCRIPT_TIMELOCK" LOCKTIME_FAR_FUTURE = "LOCKTIME_FAR_FUTURE" RBF = "RBF" @@ -250,16 +254,21 @@ def path(self) -> str: ), Vector( "TX-14.cross_net", "binding", - "Mainnet chain params with testnet-labeled derivation.", - Expect.PARSES, - input_amount=200_000, output_amount=199_000, num_outputs=2, owned_outputs=1, - vacuous=True, # shipped derivation is m/84h/0h/0h — mainnet coin type, nothing crossed + "Mainnet transaction whose input derivation is relabelled to coin type 1h " + "(testnet) while the change stays at 0h. The input key is really our 0h key, " + "so the 1h claim is false -- refused as forged rather than by a network rule.", + Expect.REJECT_PARSER, + input_amount=200_000, output_amount=199_000, num_outputs=2, + reject_code=RejectCode.FORGED_INPUT_OWNERSHIP, ), Vector( "TX-16.foreign_fingerprint", "binding", - "Output bip32_derivation with a foreign master fingerprint and an " - "unparseable pubkey.", - Expect.REJECT_EMBIT, + "Output bip32_derivation with a foreign master fingerprint. A foreign " + "fingerprint only means 'not claimed as ours': the output is shown as an " + "external payment, and ownership of the real change is still decided by " + "re-derivation.", + Expect.PARSES, + input_amount=200_000, output_amount=199_000, num_outputs=2, owned_outputs=1, ), Vector( "TX-16.global_xpub_injected", "binding", @@ -277,13 +286,16 @@ def path(self) -> str: ), Vector( "TX-09.attacker_internal_key", "binding", - "p2tr change with an attacker-supplied internal key.", - Expect.REJECT_EMBIT, + "p2tr change with an attacker-supplied internal key. Must not be labelled " + "change: the output key cannot be rebuilt from anything this seed derives.", + Expect.PARSES, + input_amount=200_000, output_amount=199_000, num_outputs=2, owned_outputs=0, ), Vector( "TX-09.hidden_taptree", "binding", - "p2tr change with an unverifiable taptree leaf.", - Expect.REJECT_EMBIT, + "p2tr change with an unverifiable taptree leaf. Must not be labelled change.", + Expect.PARSES, + input_amount=200_000, output_amount=199_000, num_outputs=2, owned_outputs=0, ), # ------------------------------------------------------------------ crypto @@ -339,11 +351,11 @@ def path(self) -> str: ), Vector( "TX-10", "coverage", - "Destination address ground to collide on the first 6 + last 6 characters " - "with the change address, defeating truncated verification.", + "Destination copies the first program bytes of the change output, so both " + "addresses share the HRP and leading characters and differ in the middle. " + "A display-layer trap: only full-address rendering catches it.", Expect.PARSES, input_amount=200_000, output_amount=199_000, num_outputs=2, owned_outputs=1, - vacuous=True, # the shipped outputs share no visible prefix or suffix ), Vector( "TX-15.mismatch", "coverage", @@ -357,16 +369,18 @@ def path(self) -> str: # --------------------------------------------------------------- catalogue Vector( "TX-11.v0_bech32m", "catalogue", - "v0 witness program encoded with bech32m.", + "A wrong-variant (bech32m) address string for a v0 output planted in a " + "non-standard global field. Display addresses must be re-derived from the " + "scriptPubKey, never read from the psbt.", Expect.PARSES, input_amount=200_000, output_amount=199_000, num_outputs=2, owned_outputs=1, - vacuous=True, # a PSBT carries scriptPubKey bytes; the address encoding is display-layer ), Vector( "TX-11.v1_bech32", "catalogue", - "v1+ witness program encoded with bech32 instead of bech32m.", - Expect.REJECT_EMBIT, - vacuous=True, + "The v1/taproot counterpart: a bech32 (not bech32m) address string planted " + "in a non-standard global field.", + Expect.PARSES, + input_amount=200_000, output_amount=199_000, num_outputs=2, owned_outputs=0, ), # ------------------------------------------------------------------ extras @@ -402,7 +416,9 @@ def path(self) -> str: "must carry a witness program.", Expect.REJECT_PARSER, input_amount=200_000, output_amount=199_000, num_outputs=2, - vacuous=True, # no non_witness_utxo ships, so the real cross-check is untested here + # No non_witness_utxo ships, so the real cross-check is left to + # XTRAS.WITNESS_NONWITNESS_MISMATCH. + vacuous=True, reject_code=RejectCode.INVALID_WITNESS_UTXO, ), Vector( @@ -427,6 +443,8 @@ def path(self) -> str: advisories=frozenset({Advisory.DUST_OUTPUT, Advisory.HIGH_FEE, Advisory.HIGH_FEE_RATE}), ), Vector( + # Dropped upstream in favour of TX-19.timestamp_future; kept as a local + # fixture because TestTimelocks mutates it. "XTRAS.LOCKTIME_FUTURE", "extras", "nLocktime 2,000,000,000 — a unix timestamp in 2033.", Expect.PARSES, @@ -442,10 +460,13 @@ def path(self) -> str: ), Vector( "XTRAS.NETWORK_HRP_MISMATCH", "extras", - "Output address HRP does not match the active network.", - Expect.PARSES, - input_amount=200_000, output_amount=199_000, num_outputs=2, owned_outputs=1, - vacuous=True, # the shipped output is an ordinary mainnet bc1q address + "Two inputs claiming different networks: input 0 at coin type 0h, input 1 " + "relabelled to 1h. scriptPubKeys carry no network, so the coin type is the " + "only cross-network signal -- and input 1's key is really our 0h key, so the " + "claim is false.", + Expect.REJECT_PARSER, + input_amount=400_000, output_amount=399_000, num_outputs=2, + reject_code=RejectCode.FORGED_INPUT_OWNERSHIP, ), Vector( "XTRAS.TRUNCATED_PSBT", "parser", @@ -535,6 +556,347 @@ def path(self) -> str: Expect.PARSES, input_amount=100_000, output_amount=99_000, num_outputs=2, owned_outputs=1, ), + + # ------------------------------------------------------ structural (XTRAS) + Vector( + "XTRAS.MISSING_UTXO", "extras", + "The sole input carries neither witness_utxo nor non_witness_utxo: no " + "amount, no script, nothing to sign against.", + Expect.REJECT_PARSER, + reject_code=RejectCode.MISSING_UTXO, + ), + Vector( + "XTRAS.MISSING_UTXO_V2", "extras", + "BIP-370 twin of XTRAS.MISSING_UTXO: a v2 input naming its prevout but " + "carrying no utxo.", + Expect.REJECT_PARSER, + reject_code=RejectCode.MISSING_UTXO, + ), + Vector( + "XTRAS.V2_MISSING_PREVOUT", "extras", + "A v2 input with a witness_utxo but no previous_txid / output_index. " + "BIP-370 requires the outpoint; without it there is no transaction to sign.", + Expect.REJECT_PARSER, + reject_code=RejectCode.MISSING_UTXO, + ), + Vector( + "XTRAS.UNSUPPORTED_PSBT_VERSION", "extras", + "A v0 psbt declaring PSBT_GLOBAL_VERSION 1, which BIP-370 reserves.", + Expect.REJECT_PARSER, + reject_code=RejectCode.UNSUPPORTED_PSBT_VERSION, + ), + Vector( + "XTRAS.UNSUPPORTED_PSBT_VERSION_V2", "extras", + "A structurally complete v2 psbt declaring version 3, which is undefined.", + Expect.REJECT_PARSER, + reject_code=RejectCode.UNSUPPORTED_PSBT_VERSION, + ), + Vector( + "XTRAS.ANYONE_CAN_SPEND_OUTPUT", "extras", + "The spend output pays witness version 2: no address form, and " + "anyone-can-spend until a soft fork defines it.", + Expect.REJECT_PARSER, + input_amount=200_000, output_amount=199_000, num_outputs=2, + reject_code=RejectCode.UNDISPLAYABLE_OUTPUT, + ), + Vector( + "XTRAS.ANYONE_CAN_SPEND_OUTPUT_V2", "extras", + "BIP-370 twin of XTRAS.ANYONE_CAN_SPEND_OUTPUT.", + Expect.REJECT_PARSER, + input_amount=200_000, output_amount=199_000, num_outputs=2, + reject_code=RejectCode.UNDISPLAYABLE_OUTPUT, + ), + Vector( + "XTRAS.BARE_MULTISIG_OUTPUT", "extras", + "The spend output is a bare 2-of-2 multisig script, which has no address " + "and so cannot be reviewed.", + Expect.REJECT_PARSER, + input_amount=200_000, output_amount=199_000, num_outputs=2, + reject_code=RejectCode.UNDISPLAYABLE_OUTPUT, + ), + Vector( + "XTRAS.BARE_MULTISIG_OUTPUT_V2", "extras", + "BIP-370 twin of XTRAS.BARE_MULTISIG_OUTPUT.", + Expect.REJECT_PARSER, + input_amount=200_000, output_amount=199_000, num_outputs=2, + reject_code=RejectCode.UNDISPLAYABLE_OUTPUT, + ), + Vector( + "XTRAS.WITNESS_NONWITNESS_MISMATCH", "extras", + "An input ships both utxo forms and they disagree (100,000 vs 200,000 sats, " + "different scripts) -- the BIP-143 amount-binding attack.", + Expect.REJECT_PARSER, + num_outputs=2, + reject_code=RejectCode.UTXO_MISMATCH, + ), + + # --------------------------------------------------------------- timelocks + Vector( + "TX-19.timestamp_future", "extras", + "nLocktime 2,000,000,000 (~2033) with a non-final input: unconfirmable until then.", + Expect.PARSES, + input_amount=100_000, output_amount=99_000, num_outputs=2, owned_outputs=1, + advisories=frozenset({Advisory.FUTURE_LOCKTIME}), + ), + Vector( + "TX-19.height_far", "extras", + "Block-height nLockTime ~4 years out. With no block anchor it parses as an " + "ordinary spend, like its v2 twin.", + Expect.PARSES, + input_amount=100_000, output_amount=99_000, num_outputs=2, owned_outputs=1, + ), + Vector( + "TX-19.height_near", "extras", + "Negative control: nLockTime at the chain tip (anti-fee-sniping). Normal; " + "must not warn.", + Expect.PARSES, + input_amount=100_000, output_amount=99_000, num_outputs=2, owned_outputs=1, + ), + Vector( + "TX-19.inert", "extras", + "Negative control: far-future nLockTime with every input final, so the " + "locktime is not enforced. Must not warn.", + Expect.PARSES, + input_amount=100_000, output_amount=99_000, num_outputs=2, owned_outputs=1, + ), + Vector( + "TX-19.relative_blocks", "extras", + "BIP-68 block-based relative timelock (0x0000ffff, ~15 months).", + Expect.PARSES, + input_amount=100_000, output_amount=99_000, num_outputs=2, owned_outputs=1, + advisories=frozenset({Advisory.RBF, Advisory.RELATIVE_TIMELOCK}), + ), + Vector( + "TX-19.relative_time", "extras", + "BIP-68 time-based relative timelock (512-second units, ~24 days).", + Expect.PARSES, + input_amount=100_000, output_amount=99_000, num_outputs=2, owned_outputs=1, + advisories=frozenset({Advisory.RBF, Advisory.RELATIVE_TIMELOCK}), + ), + Vector( + "TX-19.relative_rbf_masquerade", "extras", + "Same bytes as relative_blocks, presented as mere RBF. 'Replaceable' alone " + "would hide a ~15-month hold.", + Expect.PARSES, + input_amount=100_000, output_amount=99_000, num_outputs=2, owned_outputs=1, + advisories=frozenset({Advisory.RBF, Advisory.RELATIVE_TIMELOCK}), + ), + Vector( + "TX-20.cltv_time", "coverage", + "A P2SH output whose redeem script is CLTV-locked until ~2033. Consensus " + "rejects any earlier spend of those funds; the address alone hides it.", + Expect.PARSES, + input_amount=100_000, output_amount=99_000, num_outputs=2, owned_outputs=1, + advisories=frozenset({Advisory.SCRIPT_TIMELOCK}), + ), + Vector( + "TX-20.cltv_height", "coverage", + "Meant as a CLTV-locked P2WSH output.", + Expect.PARSES, + input_amount=100_000, output_amount=99_000, num_outputs=2, owned_outputs=1, + # The shipped scriptPubKey is still a p2wpkh; the CLTV witness script is + # attached but not committed, so there is correctly nothing to flag. + vacuous=True, + ), + Vector( + "TX-20.csv_relative", "coverage", + "Meant as a CSV-locked P2WSH output.", + Expect.PARSES, + input_amount=100_000, output_amount=99_000, num_outputs=2, owned_outputs=1, + vacuous=True, # same upstream defect as TX-20.cltv_height + ), + + # --------------------------------------------------------------- ownership + Vector( + "TX-21.claims_us_pays_other", "ownership", + "Change annotated with one of our genuine keys and paths, but the script " + "pays a stranger. The key re-derives; the output is not locked to it.", + Expect.REJECT_PARSER, + input_amount=200_000, output_amount=199_000, num_outputs=2, + reject_code=RejectCode.FORGED_OUTPUT_OWNERSHIP, + ), + Vector( + "TX-21.claims_us_pays_other_V2", "ownership", + "BIP-370 twin of TX-21.claims_us_pays_other.", + Expect.REJECT_PARSER, + input_amount=200_000, output_amount=199_000, num_outputs=2, + reject_code=RejectCode.FORGED_OUTPUT_OWNERSHIP, + ), + Vector( + "TX-21.pays_us_claims_other", "ownership", + "Change pays our key but is annotated with a foreign fingerprint. The " + "funds are ours, but the psbt misdescribes who owns its outputs, which is " + "refused just like the opposite lie.", + Expect.REJECT_PARSER, + input_amount=200_000, output_amount=199_000, num_outputs=2, + reject_code=RejectCode.MISLABELED_OUTPUT_OWNERSHIP, + ), + Vector( + "TX-21.pays_us_claims_other_V2", "ownership", + "BIP-370 twin of TX-21.pays_us_claims_other.", + Expect.REJECT_PARSER, + input_amount=200_000, output_amount=199_000, num_outputs=2, + reject_code=RejectCode.MISLABELED_OUTPUT_OWNERSHIP, + ), + Vector( + "TX-21.taproot_claims_other", "ownership", + "P2TR change paying our internal key but claiming a foreign fingerprint.", + Expect.REJECT_PARSER, + input_amount=200_000, output_amount=199_000, num_outputs=2, + reject_code=RejectCode.MISLABELED_OUTPUT_OWNERSHIP, + ), + Vector( + "TX-22.surplus_paths", "ownership", + "A single-sig output naming two of our keys. Only one can be the key the " + "script pays; the other is a decoy for a first-entry-only checker.", + Expect.REJECT_PARSER, + input_amount=200_000, output_amount=199_000, num_outputs=2, + reject_code=RejectCode.SURPLUS_DERIVATIONS, + ), + Vector( + "TX-22.taproot_surplus_internal_key", "ownership", + "A P2TR output claiming two internal keys; a taproot output has one.", + Expect.REJECT_PARSER, + input_amount=200_000, output_amount=199_000, num_outputs=2, + reject_code=RejectCode.SURPLUS_DERIVATIONS, + ), + Vector( + "TX-22.mixed_path_maps", "ownership", + "An output scope naming us in both the ecdsa and taproot derivation maps.", + Expect.REJECT_PARSER, + input_amount=200_000, output_amount=199_000, num_outputs=2, + reject_code=RejectCode.MIXED_DERIVATION_MAPS, + ), + Vector( + "TX-22.mixed_path_maps_input", "ownership", + "The input-side variant of TX-22.mixed_path_maps.", + Expect.REJECT_PARSER, + input_amount=200_000, output_amount=199_000, num_outputs=2, + reject_code=RejectCode.MIXED_DERIVATION_MAPS, + ), + Vector( + "TX-23.forged_output_claim", "ownership", + "Change claims our fingerprint at a plausible change path, on a key we do " + "not derive.", + Expect.REJECT_PARSER, + input_amount=200_000, output_amount=199_000, num_outputs=2, + reject_code=RejectCode.FORGED_OUTPUT_OWNERSHIP, + ), + Vector( + "TX-23.forged_output_claim_V2", "ownership", + "BIP-370 twin of TX-23.forged_output_claim.", + Expect.REJECT_PARSER, + input_amount=200_000, output_amount=199_000, num_outputs=2, + reject_code=RejectCode.FORGED_OUTPUT_OWNERSHIP, + ), + Vector( + "TX-23.forged_taproot_claim", "ownership", + "P2TR change claiming our fingerprint on an internal key we do not derive.", + Expect.REJECT_PARSER, + input_amount=200_000, output_amount=199_000, num_outputs=2, + reject_code=RejectCode.FORGED_OUTPUT_OWNERSHIP, + ), + Vector( + "TX-23.forged_input_claim", "ownership", + "An extra input derivation naming our fingerprint on a foreign key, " + "alongside the genuine one.", + Expect.REJECT_PARSER, + input_amount=200_000, output_amount=199_000, num_outputs=2, + reject_code=RejectCode.FORGED_INPUT_OWNERSHIP, + ), + Vector( + "TX-23.forged_input_claim_V2", "ownership", + "BIP-370 twin of TX-23.forged_input_claim.", + Expect.REJECT_PARSER, + input_amount=200_000, output_amount=199_000, num_outputs=2, + reject_code=RejectCode.FORGED_INPUT_OWNERSHIP, + ), + + # ---------------------------------------------------------------- multisig + # Built against the suite's 2-of-3 wallet (MULTISIG_DESCRIPTOR). Parsed with + # the seed alone, as the flow does before a descriptor is loaded; the + # descriptor checks are in TestMultisigPolicy. + Vector( + "TX-04", "multisig", + "Mixed input script types in a multisig flow, carrying an invalid pubkey.", + Expect.REJECT_EMBIT, + ), + Vector( + "TX-13.duplicate", "multisig", + "Duplicated cosigner key: nominally 2-of-3, effectively 2-of-2.", + Expect.REJECT_EMBIT, + ), + Vector( + "TX-13.substitute", "multisig", + "One cosigner key swapped for an attacker's; ours is gone from the inputs.", + Expect.REJECT_PARSER, + input_amount=100_000, output_amount=99_000, num_outputs=2, + reject_code=RejectCode.SEED_CANNOT_SIGN, + ), + Vector( + "TX-13.threshold", "multisig", + "Change script reduced to 1-of-3. Only a registered descriptor can tell.", + Expect.PARSES, + input_amount=100_000, output_amount=99_000, num_outputs=2, owned_outputs=1, + ), + Vector( + "TX-13.reorder", "multisig", + "Cosigner keys reordered, which breaks sortedmulti. Only a registered " + "descriptor can tell.", + Expect.PARSES, + input_amount=100_000, output_amount=99_000, num_outputs=2, owned_outputs=1, + ), + Vector( + "TX-05", "multisig", + "Multisig change built from attacker-only xpubs. Must not be labelled change.", + Expect.PARSES, + input_amount=200_000, output_amount=199_000, num_outputs=2, owned_outputs=0, + ), + Vector( + "TX-21.honest_foreign_annotated_spend", "multisig", + "Negative control: an honest payment to a stranger's M-of-N, fully " + "annotated with their keys. An external payment, not an attack.", + Expect.PARSES, + input_amount=200_000, output_amount=199_000, num_outputs=2, owned_outputs=0, + ), + Vector( + "TX-21.ms_fp_relabeled", "multisig", + "Genuine multisig change with our cosigner entry relabelled to a foreign " + "fingerprint: our key, attributed to another wallet.", + Expect.REJECT_PARSER, + input_amount=200_000, output_amount=199_000, num_outputs=2, + reject_code=RejectCode.MISLABELED_OUTPUT_OWNERSHIP, + ), + Vector( + "TX-21.ms_repointed_keys", "multisig", + "Change witness script swapped for a stranger's M-of-N while our " + "derivation entry stays: the script no longer contains our key.", + Expect.REJECT_PARSER, + input_amount=200_000, output_amount=199_000, num_outputs=2, + reject_code=RejectCode.FORGED_OUTPUT_OWNERSHIP, + ), + Vector( + "TX-21.ms_repointed_spk", "multisig", + "Change scriptPubKey repointed while the supplied witness script stays " + "ours: the script no longer hashes to the output.", + Expect.REJECT_PARSER, + input_amount=200_000, output_amount=199_000, num_outputs=2, + reject_code=RejectCode.FORGED_OUTPUT_OWNERSHIP, + ), + Vector( + "TX-22.ms_decoy_first", "multisig", + "Genuine multisig change with a decoy entry of ours listed first.", + Expect.REJECT_PARSER, + input_amount=200_000, output_amount=199_000, num_outputs=2, + reject_code=RejectCode.FORGED_OUTPUT_OWNERSHIP, + ), + Vector( + "TX-22.ms_decoy_last", "multisig", + "The same decoy listed last, which a first-match check never reaches.", + Expect.REJECT_PARSER, + input_amount=200_000, output_amount=199_000, num_outputs=2, + reject_code=RejectCode.FORGED_OUTPUT_OWNERSHIP, + ), ] VECTORS_BY_NAME = {v.name: v for v in VECTORS} @@ -545,6 +907,18 @@ def path(self) -> str: NORMAL_VECTORS = [v for v in VECTORS if v.category == "normal"] +MULTISIG_VECTORS = [v for v in VECTORS if v.category == "multisig"] + +# The suite's 2-of-3 wallet, from psbt_test_suite/test_vectors.json ("multisig"). +# The corpus seed is the 73c5da0a cosigner. +MULTISIG_DESCRIPTOR = ( + "wsh(sortedmulti(2," + "[73c5da0a/48h/0h/0h/2h]xpub6DkFAXWQ2dHxq2vatrt9qyA3bXYU4ToWQwCHbf5XB2mSTexcHZCeKS1VZYcPoBd5X8yVcbXFHJR9R8UCVpt82VX1VhR28mCyxUFL4r6KFrf/<0;1>/*," + "[28645006/48h/0h/0h/2h]xpub6DnEBNkSJKBYQmsbhS1sP9cNdtU5c9PLFGCjTJmxicxc13WB8zNNGQazabQpyFAGW5bV9tMko4uBxDxjUKL6dSAcx1tEbgEHtgSqyRsekh6/<0;1>/*," + "[3f635a63/48h/0h/0h/2h]xpub6FHZCoNb3tg3o1GAJQxSwgFNF8mLRtTk2GgkF7n5rwzoxBhUEdFWa8cyZRHqytAzKZWsKz8627cQEMCCfR5GDSv6yXegqirpgDUX41Pxybr/<0;1>/*" + "))" +) + # Vectors whose sighash flag is anything other than SIGHASH_ALL; signing must be # refused outright rather than producing a partial signature. NON_SIGHASH_ALL_VECTORS = [v for v in VECTORS if v.category == "crypto"] diff --git a/tests/test_flows_psbt_malicious.py b/tests/test_flows_psbt_malicious.py index ca6148adc..ca3564a89 100644 --- a/tests/test_flows_psbt_malicious.py +++ b/tests/test_flows_psbt_malicious.py @@ -132,7 +132,7 @@ def test_spliced_change_path_is_refused(self): def test_unparseable_psbt_is_rejected_at_scan(self): """ - TX-16.foreign_fingerprint carries a pubkey embit cannot parse. Delivered + TX-04 carries a pubkey embit cannot parse. Delivered as UR2 (how a real scan arrives), `DecodeQR.is_psbt` is True but `get_psbt()` returns None. ScanView must refuse it there, rather than routing on with `controller.psbt = None` — which PSBTSelectSeedView @@ -142,6 +142,6 @@ def test_unparseable_psbt_is_rejected_at_scan(self): self.run_sequence([ FlowStep(MainMenuView, button_data_selection=MainMenuView.SCAN), FlowStep(scan_views.ScanView, - before_run=self.load_psbt_as_ur2("TX-16.foreign_fingerprint")), + before_run=self.load_psbt_as_ur2("TX-04")), FlowStep(MainMenuView), ]) diff --git a/tests/test_psbt_refusal_screens.py b/tests/test_psbt_refusal_screens.py index fa88b012d..36994f9bc 100644 --- a/tests/test_psbt_refusal_screens.py +++ b/tests/test_psbt_refusal_screens.py @@ -105,9 +105,8 @@ def test_real_refusal_message_fits(self, vector): PSBTParser(p=load_psbt(vector.name), seed=suite_seed(), network=SUITE_NETWORK) presentation = REJECT_PRESENTATION.get(excinfo.value.code, RejectPresentation()) - assert presentation.text is None, ( - f"{vector.name}: this code now renders fixed prose, so the parser's own " - f"message is never shown; cover it in test_table_prose_fits instead.") + if presentation.text is not None: + pytest.skip(f"{excinfo.value.code} renders fixed prose; see test_table_prose_fits") text = str(excinfo.value) if presentation.tip: diff --git a/tests/test_psbt_test_suite.py b/tests/test_psbt_test_suite.py index 2ffc6c1ef..ac6bbdb2c 100644 --- a/tests/test_psbt_test_suite.py +++ b/tests/test_psbt_test_suite.py @@ -851,3 +851,115 @@ def test_it_warns_rather_than_refuses(self): network=SUITE_NETWORK, max_fee_rate=1) assert parser.fee_amount > 0 # parsed fine, was not refused assert RiskWarning.HIGH_FEE_RATE not in RiskWarning.INFORMATIONAL # but interrupts + + +class TestOutputClaimsMatchScripts: + """ + Re-deriving a claimed key proves it is ours. It does not prove the output + pays it: a psbt can annotate a stranger's output with a genuine key and path + of ours (TX-21.claims_us_pays_other). Both halves have to hold. + """ + + def _with_other_genuine_key(self, name: str): + """The fixture's change output, re-annotated with a different key of ours.""" + from embit.psbt import DerivationPath + + psbt = load_psbt(name) + root = suite_seed().get_root(SUITE_NETWORK) + for out in psbt.outputs: + for pub, der in list(out.bip32_derivations.items()): + path = list(der.derivation[:-1]) + [der.derivation[-1] + 7] + del out.bip32_derivations[pub] + out.bip32_derivations[root.derive(path).key] = DerivationPath(der.fingerprint, path) + return psbt + + @pytest.mark.parametrize("name", ["NORMAL-1_p2wpkh", "NORMAL-2_wrapped", "NORMAL-3_legacy", + "NORMAL-1_p2wpkh_V2"]) + def test_genuine_key_on_a_script_that_does_not_pay_it_is_refused(self, name): + with pytest.raises(InvalidPSBTError) as excinfo: + PSBTParser(p=self._with_other_genuine_key(name), seed=suite_seed(), network=SUITE_NETWORK) + assert excinfo.value.code == RejectCode.FORGED_OUTPUT_OWNERSHIP + + def test_a_bogus_script_on_a_foreign_output_is_not_a_claim(self): + """NORMAL-2's destination carries a redeem script that hashes to nothing; it names no key of ours.""" + parser = PSBTParser(p=load_psbt("NORMAL-2_wrapped"), seed=suite_seed(), network=SUITE_NETWORK) + assert parser.num_change_outputs == 1 + + +class TestMultisigPolicy: + """ + The multisig vectors against the suite's registered 2-of-3 wallet. Without a + descriptor the parser can only tell whether this seed's key is in a script; + whether the script is the *wallet's* is the descriptor's job. + """ + + @staticmethod + def _descriptor(): + from embit.descriptor import Descriptor + from psbt_suite_util import MULTISIG_DESCRIPTOR + return Descriptor.from_string(MULTISIG_DESCRIPTOR) + + @staticmethod + def _honest_change(): + """TX-22.ms_decoy_first with its decoy removed: genuine multisig change.""" + psbt = load_psbt("TX-22.ms_decoy_first") + out = psbt.outputs[0] + decoys = [pub for pub in out.bip32_derivations if pub.sec() not in out.witness_script.data] + assert len(decoys) == 1 + decoy = (decoys[0], out.bip32_derivations.pop(decoys[0])) + return psbt, decoy + + @pytest.mark.parametrize("name", ["TX-13.threshold", "TX-13.reorder"]) + def test_tampered_change_is_not_the_wallets(self, name): + parser = parse_vector(VECTORS_BY_NAME[name]) + assert parser.num_change_outputs == 1 + assert parser.verify_multisig_output(self._descriptor(), 0) is False + + def test_genuine_change_is_the_wallets(self): + psbt, _decoy = self._honest_change() + parser = PSBTParser(p=psbt, seed=suite_seed(), network=SUITE_NETWORK) + assert parser.num_change_outputs == 1 + assert parser.verify_multisig_output(self._descriptor(), 0) is True + + @pytest.mark.parametrize("position", ["first", "last"]) + def test_a_decoy_fails_in_either_position(self, position): + """ + embit's Descriptor.owns stops at the first matching entry, so a decoy listed + after a genuine one used to pass. Checked here on an already-parsed psbt, + because the parser itself now refuses the decoy before it gets this far. + """ + from collections import OrderedDict + + psbt, (decoy_pub, decoy_der) = self._honest_change() + parser = PSBTParser(p=psbt, seed=suite_seed(), network=SUITE_NETWORK) + + out = parser.psbt.outputs[parser.get_change_data(0)["output_index"]] + entries = list(out.bip32_derivations.items()) + entries = [(decoy_pub, decoy_der)] + entries if position == "first" else entries + [(decoy_pub, decoy_der)] + out.bip32_derivations = OrderedDict(entries) + + assert parser.verify_multisig_output(self._descriptor(), 0) is False + + +class TestScriptTimelock: + """CLTV / CSV inside an output's own script lock the funds, not the transaction.""" + + def test_committed_cltv_script_is_flagged(self): + assert Advisory.SCRIPT_TIMELOCK in parse_vector(VECTORS_BY_NAME["TX-20.cltv_time"]).risk_warnings + + def test_uncommitted_script_is_ignored(self): + """TX-20.cltv_height's CLTV script does not hash to its p2wpkh output; it says nothing.""" + assert Advisory.SCRIPT_TIMELOCK not in parse_vector(VECTORS_BY_NAME["TX-20.cltv_height"]).risk_warnings + + def test_push_data_is_not_mistaken_for_an_opcode(self): + from embit.script import Script + # OP_DROP: the bytes are pushed as data, never executed. + assert PSBTParser._script_has_timelock(Script(bytes([0x03, 0xB1, 0xB2, 0xB1, 0x75]))) is False + # <0x0100> OP_CHECKSEQUENCEVERIFY + assert PSBTParser._script_has_timelock(Script(bytes([0x02, 0x00, 0x01, 0xB2]))) is True + + def test_it_interrupts_rather_than_being_informational(self): + from seedsigner.models.psbt_parser import RiskWarning + from seedsigner.views.psbt_views import PSBTRiskWarningView + assert RiskWarning.SCRIPT_TIMELOCK not in RiskWarning.INFORMATIONAL + assert RiskWarning.SCRIPT_TIMELOCK in PSBTRiskWarningView.RISK_TEXT From e2fe07a0dde7bf9d0d0ef9772cef40e6e1059b2d Mon Sep 17 00:00:00 2001 From: 3rd Iteration Date: Fri, 18 Sep 2026 11:08:20 -0400 Subject: [PATCH 2/4] test: stop flow tests hanging when collected after the refusal-screen tests tests/test_psbt_refusal_screens.py imported the GUI before tests/base.py installed its renderer and hardware-button doubles. Any flow test collected after it then ran against the real, never-configured Renderer (every View and the error View raise, so the Controller loops forever) or against real buttons (real-screen flows wait for a key press forever). The full suite only passed because alphabetical order puts the flow tests first. The refusal-screen test now imports base first, and base.py also rebinds seedsigner.gui.Renderer when the package was already imported by some other module collected earlier. Co-Authored-By: Claude Opus 5 --- tests/base.py | 8 ++++++++ tests/test_psbt_refusal_screens.py | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/tests/base.py b/tests/base.py index 0834cdbf8..6a76edba3 100644 --- a/tests/base.py +++ b/tests/base.py @@ -19,6 +19,14 @@ _renderer_module.Renderer.get_instance.return_value.canvas_width = 240 _renderer_module.Renderer.get_instance.return_value.canvas_height = 240 sys.modules['seedsigner.gui.renderer'] = _renderer_module +# Views resolve the renderer as `from seedsigner.gui import Renderer`, i.e. through +# the package attribute, not sys.modules. If a test module collected before this +# one already imported seedsigner.gui (tests/test_psbt_refusal_screens.py does), +# that attribute is still the real, never-configured Renderer: every View -- and +# the error View the Controller falls back to -- raises "Must call +# Renderer.configure_instance() first", and the Controller loops on it forever. +if 'seedsigner.gui' in sys.modules: + sys.modules['seedsigner.gui'].Renderer = _renderer_module.Renderer sys.modules['seedsigner.gui.screens.screensaver'] = MagicMock() sys.modules['seedsigner.gui.toast'] = MagicMock() sys.modules['seedsigner.hardware.buttons'] = MagicMock() diff --git a/tests/test_psbt_refusal_screens.py b/tests/test_psbt_refusal_screens.py index 36994f9bc..fde3fee9f 100644 --- a/tests/test_psbt_refusal_screens.py +++ b/tests/test_psbt_refusal_screens.py @@ -6,6 +6,12 @@ reason produces a visually broken screen that nothing else catches. These tests measure the real layout and fail if a message no longer fits. """ +# Before any seedsigner import: base installs the test doubles for the renderer +# and the hardware buttons. Importing the GUI first bound the real ones for every +# module collected after this file, so the flow tests that followed it hung -- on +# an unconfigured Renderer, or on real buttons waiting for a key press. +import base # noqa: F401 + import threading from unittest.mock import patch From d5d5d92351ebde43bfd0f08a3154c3dc750d7ef2 Mon Sep 17 00:00:00 2001 From: 3rd Iteration Date: Fri, 18 Sep 2026 11:08:52 -0400 Subject: [PATCH 3/4] fix: port upstream PSBT/QR hardening; identify multisig change only via descriptor From a review of open upstream SeedSigner PRs and their discussions: - Previous-tx proof (upstream #995/#977): a non_witness_utxo must hash to the txid its input spends (UTXO_MISMATCH), and a legacy p2sh input may not rely on a witness_utxo alone (INVALID_WITNESS_UTXO). Legacy signatures commit to no amount, so either lie hides fee in a single signing. - Multisig change without global xpubs (review thread on upstream #1032): a change-shaped m-of-n containing our key is not provably this wallet's. It is now a payment unless a loaded descriptor identifies it; the new PSBTIdentifyChangeView offers "Load descriptor to identify change", and returning with a descriptor re-reads the psbt. verify_multisig_output's per-entry check is shared as _descriptor_owns_output. - OP_RETURN payload read from its push opcode (#965/#1003): direct pushes lost their first byte on screen. - INCONSISTENT_FINGERPRINTS (#1040): a global xpub whose fingerprint disagrees with the keys it derives. - Untrusted-QR crashes (#967/#968/#970/#971): SeedQR checksum and whole-payload detection, signmessage bounds, parse_derivation_path on short/48h paths, and a UR2 seq_len bound. New psbt_faker vectors cover each (PREV_TX_TXID_MISMATCH, LEGACY_P2SH_WITNESS_ONLY, OP_RETURN_DIRECT_PUSH, TX-24.xpub_fingerprint_mismatch, TX-21.ms_foreign_quorum*, TX-21.ms_honest_change_no_xpubs). TX-20 and XTRAS.MIXED_INPUT_TYPES are re-vendored after generator fixes; TX-20 is no longer vacuous. Co-Authored-By: Claude Opus 5 --- src/seedsigner/helpers/embit_utils.py | 12 +- .../helpers/ur2/fountain_decoder.py | 14 ++ src/seedsigner/models/decode_qr.py | 64 +++++--- src/seedsigner/models/psbt_parser.py | 149 ++++++++++++++++-- src/seedsigner/views/psbt_views.py | 86 ++++++++-- src/seedsigner/views/seed_views.py | 10 +- tests/data/psbt_test_suite/PROVENANCE.md | 16 +- .../psbt_test_suite/TX-20.cltv_height.psbt | Bin 354 -> 366 bytes .../data/psbt_test_suite/TX-20.cltv_time.psbt | Bin 356 -> 356 bytes .../psbt_test_suite/TX-20.csv_relative.psbt | Bin 353 -> 365 bytes .../TX-21.ms_foreign_quorum.psbt | Bin 0 -> 1149 bytes .../TX-21.ms_foreign_quorum_no_xpubs.psbt | Bin 0 -> 846 bytes .../TX-21.ms_honest_change_no_xpubs.psbt | Bin 0 -> 846 bytes .../TX-24.xpub_fingerprint_mismatch.psbt | Bin 0 -> 1156 bytes .../XTRAS.LEGACY_P2SH_WITNESS_ONLY.psbt | Bin 0 -> 1076 bytes .../XTRAS.MIXED_INPUT_TYPES.psbt | Bin 514 -> 514 bytes .../XTRAS.OP_RETURN_DIRECT_PUSH.psbt | Bin 0 -> 381 bytes .../XTRAS.OP_RETURN_DIRECT_PUSH_V2.psbt | Bin 0 -> 420 bytes .../XTRAS.PREV_TX_TXID_MISMATCH.psbt | Bin 0 -> 346 bytes .../XTRAS.PREV_TX_TXID_MISMATCH_V2.psbt | Bin 0 -> 373 bytes tests/psbt_suite_util.py | 84 +++++++++- tests/test_flows_psbt_malicious.py | 76 +++++++++ tests/test_psbt_refusal_screens.py | 20 +++ tests/test_psbt_test_suite.py | 138 +++++++++++++++- tests/test_untrusted_qr_hardening.py | 91 +++++++++++ 25 files changed, 698 insertions(+), 62 deletions(-) create mode 100644 tests/data/psbt_test_suite/TX-21.ms_foreign_quorum.psbt create mode 100644 tests/data/psbt_test_suite/TX-21.ms_foreign_quorum_no_xpubs.psbt create mode 100644 tests/data/psbt_test_suite/TX-21.ms_honest_change_no_xpubs.psbt create mode 100644 tests/data/psbt_test_suite/TX-24.xpub_fingerprint_mismatch.psbt create mode 100644 tests/data/psbt_test_suite/XTRAS.LEGACY_P2SH_WITNESS_ONLY.psbt create mode 100644 tests/data/psbt_test_suite/XTRAS.OP_RETURN_DIRECT_PUSH.psbt create mode 100644 tests/data/psbt_test_suite/XTRAS.OP_RETURN_DIRECT_PUSH_V2.psbt create mode 100644 tests/data/psbt_test_suite/XTRAS.PREV_TX_TXID_MISMATCH.psbt create mode 100644 tests/data/psbt_test_suite/XTRAS.PREV_TX_TXID_MISMATCH_V2.psbt create mode 100644 tests/test_untrusted_qr_hardening.py diff --git a/src/seedsigner/helpers/embit_utils.py b/src/seedsigner/helpers/embit_utils.py index 0eea39faf..e43c4c441 100644 --- a/src/seedsigner/helpers/embit_utils.py +++ b/src/seedsigner/helpers/embit_utils.py @@ -235,9 +235,15 @@ def parse_derivation_path(derivation_path: str) -> dict: sections = derivation_path.split("/") - if sections[1] == "48h": - # So far this helper is only meant for single sig message signing - raise Exception("Not implemented") + # The path can come verbatim from an untrusted signmessage QR. A path too short + # to name a purpose and coin type, or a multisig (48h) one -- this helper is + # only meant for single sig -- is reported as an unclean match, which callers + # already turn into "not supported", rather than raised as a System Error. + if len(sections) < 3 or sections[1] == "48h": + return dict( + script_type=None, network=None, is_change=None, index=None, + wallet_derivation_path=None, clean_match=False, + ) lookups = { "script_types": { diff --git a/src/seedsigner/helpers/ur2/fountain_decoder.py b/src/seedsigner/helpers/ur2/fountain_decoder.py index 9e8dcdf34..268830cae 100644 --- a/src/seedsigner/helpers/ur2/fountain_decoder.py +++ b/src/seedsigner/helpers/ur2/fountain_decoder.py @@ -8,6 +8,16 @@ from .fountain_utils import choose_fragments, contains, is_strict_subset, set_difference from .utils import join_lists, join_bytes, crc32_int, xor_with, take_first +# A part's seq_len comes straight off a scanned QR; the UR parser only rejects values +# below 1 or above 2**64. validate_part() builds a set that size and choose_fragments() +# runs a shuffle quadratic in it, so one frame could exhaust memory or hang a Pi Zero +# for hours. The shuffle is part of the fountain code and can't be changed without +# breaking interoperability, so the count is bounded instead. 10,000 fragments is far +# beyond any real message (100 KB even at a 10-byte fragment). Same bound as upstream +# SeedSigner #970. +MAX_SEQ_LEN = 10000 + + class InvalidPart(Exception): pass @@ -268,6 +278,10 @@ def process_mixed_part(self, p): self.mixed_parts[p2.indexes] = p2 def validate_part(self, p): + # Reject implausible part counts before allocating anything sized by them + if p.seq_len < 1 or p.seq_len > MAX_SEQ_LEN: + return False + # If this is the first part we've seen if self.expected_part_indexes == None: # Record the things that all the other parts we see will have to match to be valid. diff --git a/src/seedsigner/models/decode_qr.py b/src/seedsigner/models/decode_qr.py index 6e3ebb7a7..10a79839f 100644 --- a/src/seedsigner/models/decode_qr.py +++ b/src/seedsigner/models/decode_qr.py @@ -717,7 +717,9 @@ def detect_segment_type(s, wordlist_language_code=None): return QRType.WALLET__GENERIC # Seed - if re.search(r'\d{48,96}', s): + # The whole payload, not merely a digit run inside something else (a + # SettingsQR with a long number in it is not a seed). + if re.fullmatch(r'(?:\d{4}){12,24}', s.strip()): return QRType.SEED__SEEDQR # Bitcoin Address @@ -1218,7 +1220,13 @@ def add(self, segment, qr_type=QRType.SEED__SEEDQR): if len(self.seed_phrase) > 0: if not self.has_valid_word_count(): return DecodeQRStatus.INVALID - self.seed_type = "bip39" + # Hand-transcribed SeedQRs are exactly where a wrong digit is + # expected, and the checksum is what catches it. Unchecked, the + # bad mnemonic only failed later, as a System Error. + seed_type = self._classify_mnemonic(self.seed_phrase) + if seed_type is None: + return DecodeQRStatus.INVALID + self.seed_type = seed_type self.complete = True self.collected_segments = 1 return DecodeQRStatus.COMPLETE @@ -1249,23 +1257,10 @@ def add(self, segment, qr_type=QRType.SEED__SEEDQR): if not self.has_valid_word_count(): return DecodeQRStatus.INVALID - is_valid_bip39 = False - try: - Seed(seed_phrase_list, passphrase="", wordlist_language_code=self.wordlist_language_code) - is_valid_bip39 = True - except Exception: - is_valid_bip39 = False - - is_valid_aezeed = len(seed_phrase_list) == 24 and aezeed_has_valid_checksum(seed_phrase_list, self.word_to_index) - - if is_valid_aezeed and is_valid_bip39: - self.seed_type = "ambiguous" - elif is_valid_aezeed: - self.seed_type = "aezeed" - elif is_valid_bip39: - self.seed_type = "bip39" - else: + seed_type = self._classify_mnemonic(seed_phrase_list) + if seed_type is None: return DecodeQRStatus.INVALID + self.seed_type = seed_type self.seed_phrase = seed_phrase_list self.complete = True @@ -1312,6 +1307,29 @@ def get_seed_type(self): return self.seed_type return None + def _classify_mnemonic(self, words: list) -> str | None: + """ + "bip39", "aezeed", or "ambiguous" (both checksums pass) for a mnemonic whose + checksum holds; None when neither does. + """ + is_valid_bip39 = False + try: + Seed(words, passphrase="", wordlist_language_code=self.wordlist_language_code) + is_valid_bip39 = True + except Exception: + is_valid_bip39 = False + + is_valid_aezeed = len(words) == 24 and aezeed_has_valid_checksum(words, self.word_to_index) + + if is_valid_aezeed and is_valid_bip39: + return "ambiguous" + elif is_valid_aezeed: + return "aezeed" + elif is_valid_bip39: + return "bip39" + return None + + def has_valid_word_count(self): return len(self.seed_phrase) in (12, 15, 18, 21, 24) @@ -1440,10 +1458,14 @@ def add(self, segment, qr_type=QRType.SIGN_MESSAGE): signmessage {derivation_path} ascii:{message} """ - parts = segment.split() + # Split off the header only: the message itself may contain spaces or + # another "ascii:". A malformed payload is INVALID, never an IndexError -- + # this decoder runs inside the camera loop, where an exception is a crash. + parts = segment.split(maxsplit=2) + if len(parts) < 3 or ":" not in parts[2]: + return DecodeQRStatus.INVALID self.derivation_path = parts[1].replace("h", "'") - fmt = parts[2].split(":")[0] - self.message = segment.split(f"{fmt}:")[1] + fmt, self.message = parts[2].split(":", 1) # TODO: support formats other than ascii? if fmt != "ascii": diff --git a/src/seedsigner/models/psbt_parser.py b/src/seedsigner/models/psbt_parser.py index b8f2fa351..c50f70888 100644 --- a/src/seedsigner/models/psbt_parser.py +++ b/src/seedsigner/models/psbt_parser.py @@ -169,6 +169,11 @@ class RejectCode: # this direction cannot be trusted about anything else. MISLABELED_OUTPUT_OWNERSHIP = "MISLABELED_OUTPUT_OWNERSHIP" + # A key's derivation entry and the global xpub that derives it name different + # master fingerprints. Both are the coordinator's claims about the same key, so + # one of them is wrong; nothing says which, so it is not graded as an attack. + INCONSISTENT_FINGERPRINTS = "INCONSISTENT_FINGERPRINTS" + # The selected seed holds no key that could sign any input. Alone among these # codes this is a mismatch rather than a refusal of the psbt: the usual cause # is the user picking the wrong seed. It is raised so the flow can say so up @@ -254,6 +259,7 @@ def __init__( reference_time: int | None = None, max_fee_rate: float | None = None, block_anchor: tuple[int, int] | None = None, + multisig_descriptor: Descriptor | None = None, ): self.psbt: PSBT = p self.seed = seed @@ -268,6 +274,16 @@ def __init__( self.reference_time = reference_time self.block_anchor = block_anchor + # A user-loaded, known-good multisig descriptor. Without one, multisig change + # can only be identified when the psbt's global xpubs tie every cosigner key + # back to the inputs' wallet; see _parse_outputs. + self.multisig_descriptor = multisig_descriptor + + # Output indexes that look like multisig change (same script shape, our key + # among the cosigners) but that nothing could tie to the inputs' wallet. They + # are presented as payments until a descriptor identifies them. + self.unidentified_change_outputs: list[int] = [] + self.change_index_lookahead = ( change_index_lookahead if change_index_lookahead is not None @@ -470,6 +486,10 @@ def parse(self): if rt == False: return False + # Last, so that a more serious finding about this seed's own keys is the + # one reported. + self._reject_inconsistent_fingerprints(child_key_derivation_cache) + return True @@ -862,6 +882,24 @@ def _validate_input(index: int, inp: InputScope): code=RejectCode.MISSING_UTXO, ) + if non_witness_utxo is not None: + # non_witness_utxo is the whole previous transaction, so unlike + # witness_utxo it can be proven: it has to hash to the txid this input + # spends. A legacy signature commits to no amount at all, so an altered + # previous tx is enough to understate an input and hide the difference + # in the fee, in a single signing. (embit's InputScope.verify does the + # same hash, but raises bare exceptions and skips inputs without one.) + if non_witness_utxo.txid() != inp.txid: + raise InvalidPSBTError( + f"Input {index} previous tx does not match the txid it spends.", + code=RejectCode.UTXO_MISMATCH, + ) + if inp.vout is None or not 0 <= inp.vout < len(non_witness_utxo.vout): + raise InvalidPSBTError( + f"Input {index} spends an output its previous tx does not have.", + code=RejectCode.UTXO_MISMATCH, + ) + if witness_utxo is not None and non_witness_utxo is not None: # Both forms supplied: they must describe the same prevout. This is # the BIP-143 amount-binding attack -- a lowered witness_utxo value @@ -924,6 +962,14 @@ def _validate_input(index: int, inp: InputScope): code=RejectCode.SCRIPT_HASH_MISMATCH, ) effective_type = inp.redeem_script.script_type() + if non_witness_utxo is None and effective_type not in ("p2wpkh", "p2wsh"): + # A p2sh that wraps no witness program is legacy (e.g. bare p2sh + # multisig): its signature commits to no amount, so a witness_utxo + # alone is an unprovable claim about it. + raise InvalidPSBTError( + f"Input {index} is legacy p2sh with no previous tx.", + code=RejectCode.INVALID_WITNESS_UTXO, + ) if effective_type == "p2wsh": if inp.witness_script is None: @@ -1228,6 +1274,17 @@ def _parse_outputs(self, child_key_derivation_cache: dict): if sc.data == vout[i].script_pubkey.data: is_change = True + if is_change and self.is_multisig and "cosigners" not in self.policy: + # The script is a well-formed m-of-n that contains our key, but with no + # global xpubs nothing ties its other keys to the inputs' wallet. A + # different wallet that shares our key -- the same m-of-n with one + # cosigner swapped for an attacker's -- looks identical. Labelling it + # change would hide it from review, so it stays a payment unless a + # known-good descriptor identifies it. + if self.multisig_descriptor is None or not self._descriptor_owns_output(self.multisig_descriptor, i): + is_change = False + self.unidentified_change_outputs.append(i) + if is_change: # The seed can derive this scriptPubKey, but the path is not one # any wallet will scan for. There is no honest reason to build @@ -1270,8 +1327,7 @@ def _parse_outputs(self, child_key_derivation_cache: dict): ) if vout[i].script_pubkey.data[0] == OPCODES.OP_RETURN: - # The data is written as: OP_RETURN + OP_PUSHDATA1 + len(payload) + payload - self.op_return_data = vout[i].script_pubkey.data[3:] + self.op_return_data = PSBTParser._op_return_payload(vout[i].script_pubkey.data) # Bitcoin Core v30 relaxed OP_RETURN standardness, so the amount # cannot be assumed to be zero. An OP_RETURN is provably @@ -1441,28 +1497,54 @@ def _committed_output_script(out: OutputScope, script_pubkey): @staticmethod - def _script_has_timelock(sc) -> bool: + def _script_ops(data: bytes): """ - Whether a script runs OP_CHECKLOCKTIMEVERIFY or OP_CHECKSEQUENCEVERIFY. - Walks the opcodes rather than searching the bytes, so a push that happens - to contain 0xb1 or 0xb2 is not mistaken for one. + Yields (opcode, pushed_bytes) for each operation in a script; pushed_bytes is + None for anything that is not a push. A push that runs past the end of the + script yields what is there and stops. """ - data = sc.data pos = 0 while pos < len(data): op = data[pos] pos += 1 - if op in (OPCODES.OP_CHECKLOCKTIMEVERIFY, OPCODES.OP_CHECKSEQUENCEVERIFY): - return True if 0x01 <= op <= 0x4b: - pos += op + length = op elif op == OPCODES.OP_PUSHDATA1: - pos += 1 + (data[pos] if pos < len(data) else 0) + length, pos = int.from_bytes(data[pos:pos + 1], "little"), pos + 1 elif op == OPCODES.OP_PUSHDATA2: - pos += 2 + int.from_bytes(data[pos:pos + 2], "little") + length, pos = int.from_bytes(data[pos:pos + 2], "little"), pos + 2 elif op == OPCODES.OP_PUSHDATA4: - pos += 4 + int.from_bytes(data[pos:pos + 4], "little") - return False + length, pos = int.from_bytes(data[pos:pos + 4], "little"), pos + 4 + else: + yield op, None + continue + yield op, data[pos:pos + length] + pos += length + + + @staticmethod + def _script_has_timelock(sc) -> bool: + """ + Whether a script runs OP_CHECKLOCKTIMEVERIFY or OP_CHECKSEQUENCEVERIFY. + Walks the opcodes rather than searching the bytes, so a push that happens + to contain 0xb1 or 0xb2 is not mistaken for one. + """ + return any( + op in (OPCODES.OP_CHECKLOCKTIMEVERIFY, OPCODES.OP_CHECKSEQUENCEVERIFY) + for op, _pushed in PSBTParser._script_ops(sc.data) + ) + + + @staticmethod + def _op_return_payload(data: bytes) -> bytes: + """ + The data an OP_RETURN script carries: everything its pushes push, in order. + + Payloads of 75 bytes or fewer are pushed directly (OP_RETURN ), + which is how Bitcoin Core writes them; OP_PUSHDATA1 is only for longer ones. + Slicing at a fixed offset dropped the first byte of every short payload. + """ + return b"".join(pushed for _op, pushed in PSBTParser._script_ops(data[1:]) if pushed is not None) @@ -2104,6 +2186,38 @@ def _reject_mislabeled_outputs(self, child_key_derivation_cache: dict): ) + def _reject_inconsistent_fingerprints(self, child_key_derivation_cache: dict): + """ + Refuses a psbt where a key's derivation entry and the global xpub that derives + that key name different master fingerprints. + + Keys are matched to xpubs by derivation, not by fingerprint, so a mislabel + changes nothing downstream -- but it is a self-contradictory psbt, which is + refused like the others. All-zero fingerprints are skipped on either side: + coordinators write 00000000 for a fingerprint they do not know. + """ + zero = bytes(4) + for scope in list(self.psbt.inputs) + list(self.psbt.outputs): + for public_key, derivation_path_obj in scope.bip32_derivations.items(): + if derivation_path_obj.fingerprint == zero: + continue + path = derivation_path_obj.derivation + for xpub, origin in self.psbt.xpubs.items(): + if origin.fingerprint == zero or origin.fingerprint == derivation_path_obj.fingerprint: + continue + if len(path) < 2 or list(origin.derivation) != list(path[:-2]): + continue + try: + derived = PSBTParser._derive_with_cache(xpub, path[-2:], child_key_derivation_cache) + except Exception: + continue + if derived.key == public_key: + raise InvalidPSBTError( + "A key's fingerprint disagrees with the xpub that derives it.", + code=RejectCode.INCONSISTENT_FINGERPRINTS, + ) + + def _reject_if_seed_cannot_sign(self): """ Rejects the psbt when none of its inputs rely on a key derived by this seed. @@ -2152,8 +2266,11 @@ def verify_multisig_output(self, descriptor: Descriptor, change_num: int) -> boo every entry that names a descriptor key has to derive this output's script, and has to be one of the keys that script actually contains. """ - change_data = self.get_change_data(change_num) - i = change_data["output_index"] + return self._descriptor_owns_output(descriptor, self.get_change_data(change_num)["output_index"]) + + + def _descriptor_owns_output(self, descriptor: Descriptor, i: int) -> bool: + """See verify_multisig_output; takes an output index rather than a change number.""" output = self.psbt.outputs[i] script_pubkey = self.psbt.tx.vout[i].script_pubkey diff --git a/src/seedsigner/views/psbt_views.py b/src/seedsigner/views/psbt_views.py index 2effc2586..a5335cab6 100644 --- a/src/seedsigner/views/psbt_views.py +++ b/src/seedsigner/views/psbt_views.py @@ -539,6 +539,14 @@ class RejectPresentation: button_label=_mft("Discard transaction"), ), + RejectCode.INCONSISTENT_FINGERPRINTS: RejectPresentation( + screen=WarningScreen, + title=_mft("Transaction Problem"), + # TRANSLATOR_NOTE: Two records in the psbt disagree about which wallet a key comes from + text=_mft("This transaction's records disagree about which wallet a key comes from."), + button_label=_mft("Discard transaction"), + ), + RejectCode.FORGED_INPUT_OWNERSHIP: RejectPresentation( screen=WarningScreen, # TRANSLATOR_NOTE: Title of the screen shown when a psbt misstates who owns an input @@ -695,6 +703,7 @@ def __init__(self): network=self.settings.get_value(SettingsConstants.SETTING__NETWORK), reference_time=getattr(self.controller, "psbt_source_time", None), block_anchor=(_Controller.RELEASE_BLOCK_HEIGHT, _Controller.RELEASE_BLOCK_TIME), + multisig_descriptor=self.controller.multisig_wallet_descriptor, ) except InvalidPSBTError as e: # A deliberate refusal, not a crash: the psbt is parseable but unsafe to @@ -751,19 +760,76 @@ def run(self): self.controller.psbt_seed = None return Destination(BackStackView) - if psbt_parser.risk_warnings - RiskWarning.INFORMATIONAL: - return Destination(PSBTRiskWarningView) + if psbt_parser.unidentified_change_outputs: + return Destination(PSBTIdentifyChangeView) - # expecting p2sh (legacy multisig) and p2pkh to have no policy set - # skip change warning and psbt math view - if psbt_parser.policy == None: - return Destination(PSBTUnsupportedScriptTypeWarningView) - - elif psbt_parser.change_amount == 0: - return Destination(PSBTNoChangeWarningView) + return post_overview_destination(psbt_parser) + + + +def post_overview_destination(psbt_parser: PSBTParser, skip_current_view: bool = False) -> Destination: + """Where review continues once the overview (and any interstitial after it) is done.""" + if psbt_parser.risk_warnings - RiskWarning.INFORMATIONAL: + return Destination(PSBTRiskWarningView, skip_current_view=skip_current_view) + + # expecting p2sh (legacy multisig) and p2pkh to have no policy set + # skip change warning and psbt math view + if psbt_parser.policy == None: + return Destination(PSBTUnsupportedScriptTypeWarningView, skip_current_view=skip_current_view) + + elif psbt_parser.change_amount == 0: + return Destination(PSBTNoChangeWarningView, skip_current_view=skip_current_view) + + else: + return Destination(PSBTMathView, skip_current_view=skip_current_view) + + + +class PSBTIdentifyChangeView(View): + """ + Some output looks like this multisig wallet's change, but the psbt carries no global + xpubs to tie its other cosigner keys to the inputs' wallet. A different wallet that + shares our key would look the same, so PSBTParser shows it as a payment. Only the + wallet's descriptor can identify it as change. + """ + LOAD_DESCRIPTOR = ButtonOption("Load descriptor") + # TRANSLATOR_NOTE: Review the unidentified output as a payment, without loading a descriptor + CONTINUE_AS_PAYMENT = ButtonOption("Continue as payment") + CONTINUE = ButtonOption("Continue") + + def run(self): + psbt_parser: PSBTParser = self.controller.psbt_parser + if not psbt_parser: + # Should not be able to get here + return Destination(MainMenuView) + if self.controller.multisig_wallet_descriptor: + # TRANSLATOR_NOTE: A loaded multisig descriptor did not match an output that looked like change + text = _("The loaded descriptor doesn't identify it. Shown as a payment.") + button_data = [self.CONTINUE] else: - return Destination(PSBTMathView) + # TRANSLATOR_NOTE: Multisig change can't be told apart from a payment without the wallet descriptor + text = _("Load descriptor to identify change.") + button_data = [self.LOAD_DESCRIPTOR, self.CONTINUE_AS_PAYMENT] + + selected_menu_num = self.run_screen( + WarningScreen, + # TRANSLATOR_NOTE: Headline when multisig change cannot be identified + status_headline=_("Change Not Identified"), + text=text, + button_data=button_data, + ) + + if selected_menu_num == RET_CODE__BACK_BUTTON: + return Destination(BackStackView) + + if button_data[selected_menu_num] == self.LOAD_DESCRIPTOR: + from seedsigner.controller import Controller + from seedsigner.views.seed_views import LoadMultisigWalletDescriptorView + self.controller.resume_main_flow = Controller.FLOW__PSBT + return Destination(LoadMultisigWalletDescriptorView) + + return post_overview_destination(psbt_parser, skip_current_view=True) diff --git a/src/seedsigner/views/seed_views.py b/src/seedsigner/views/seed_views.py index 7ced83b45..1874d8bd3 100644 --- a/src/seedsigner/views/seed_views.py +++ b/src/seedsigner/views/seed_views.py @@ -4813,9 +4813,17 @@ def run(self): return Destination(BackStackView) elif button_data[selected_menu_num] == self.RETURN: + self.controller.resume_main_flow = None + psbt_parser = self.controller.psbt_parser + if psbt_parser and psbt_parser.unidentified_change_outputs: + # The descriptor decides which outputs are change, so the psbt has to be + # read again with it; the review restarts from the overview. + from seedsigner.views.psbt_views import PSBTOverviewView + self.controller.psbt_parser = None + return Destination(PSBTOverviewView, skip_current_view=True) + # Jump straight back to PSBT change verification from seedsigner.views.psbt_views import PSBTChangeDetailsView - self.controller.resume_main_flow = None return Destination(PSBTChangeDetailsView, view_args=dict(change_address_num=0)) elif button_data[selected_menu_num].button_label.startswith(_(self.VERIFY_ADDR.button_label)): diff --git a/tests/data/psbt_test_suite/PROVENANCE.md b/tests/data/psbt_test_suite/PROVENANCE.md index aaa15c283..f11d78d9f 100644 --- a/tests/data/psbt_test_suite/PROVENANCE.md +++ b/tests/data/psbt_test_suite/PROVENANCE.md @@ -43,12 +43,22 @@ Local deviations from upstream: * `XTRAS.LOCKTIME_FUTURE.psbt` is kept though upstream dropped it (superseded by TX-19.timestamp_future); TestTimelocks mutates it. -* `TX-20.cltv_height` and `TX-20.csv_relative` are vacuous as shipped: the output - scriptPubKey is still a p2wpkh, so the CLTV/CSV witness script is attached but - not committed. Only `TX-20.cltv_time` (P2SH) carries the trap. Reported upstream. +* The TX-20 vectors were re-vendored on 2026-09-18 after two generator fixes + (P2WSH was built as a p2wpkh-shaped hash160, and OP_CLTV/OP_CSV had the wrong + opcode values); all three now carry a committed CLTV/CSV script. * Only three vectors are refused by embit itself: TX-04, TX-13.duplicate and XTRAS.TRUNCATED_PSBT. +## Follow-up of 2026-09-18 + +Vectors added for the fixes brought over from the upstream SeedSigner PR review +(#995/#977, #965/#1003, #1040, and the #1032 review thread), generated with the +local psbt_faker: XTRAS.PREV_TX_TXID_MISMATCH(_V2), XTRAS.LEGACY_P2SH_WITNESS_ONLY, +XTRAS.OP_RETURN_DIRECT_PUSH(_V2), TX-24.xpub_fingerprint_mismatch, +TX-21.ms_foreign_quorum, TX-21.ms_foreign_quorum_no_xpubs and +TX-21.ms_honest_change_no_xpubs. XTRAS.MIXED_INPUT_TYPES was re-vendored too: its +legacy input used to spend its previous tx by a placeholder txid. + The multisig vectors (TX-04/05, TX-13.*, TX-21.ms_*, TX-22.ms_*) are built against the suite's 2-of-3 `wsh(sortedmulti)` wallet at `m/48h/0h/0h/2h`; see `MULTISIG_DESCRIPTOR` in `tests/psbt_suite_util.py`. diff --git a/tests/data/psbt_test_suite/TX-20.cltv_height.psbt b/tests/data/psbt_test_suite/TX-20.cltv_height.psbt index fc411ce29379d6301748b1a2506c48265b7fa679..28e73c724fa07afa9c5a573ab59b5a8f6986b054 100644 GIT binary patch delta 93 zcmV-j0HXim0`39`aC2gG{{aAfkqA~JA^;%f`(!7!E4f7PJ+1X4uBuiB3%!2imAr!I z+}_?>%hc+Tb;u>Lb*YO0l$fmgf_WBC;-x%4^_auI7!MdN?0U%@{-`QG-axDX8u%^M delta 81 zcmV-X0IvV;0^$M)aC2gG{{aATkqA~77625FlbDvE50N4UK+}{vPPvrA2qF)WfygDY nbxd{>?Qo*`!4G+s(j497{aRnWPk3a^#LPGT_?b*(PQk1IQWPZ< diff --git a/tests/data/psbt_test_suite/TX-20.cltv_time.psbt b/tests/data/psbt_test_suite/TX-20.cltv_time.psbt index 0c2b0c9238fdbbbee1ea5ad23c8d88d056d1a257..258b8d7c7fc5822293285ff89e0c3b2f0381a65a 100644 GIT binary patch delta 68 zcmV-K0K5O>0^|aaVH9olF<*`?n;Y+#9wKF>g`clJwfm8E$|bRNQ0%YA_BvwW0^|aaVH8HyajP125xjyFM6~08gJxCd5sZ;_$|bUOhZ8<6ywSCv(lG*U a3pa80u&V22t5QbG&GPcAH>jd1m8<|n3n4TB diff --git a/tests/data/psbt_test_suite/TX-20.csv_relative.psbt b/tests/data/psbt_test_suite/TX-20.csv_relative.psbt index 888f22f091dc1aef15f9915ea61291ab5b12f9e9..963bb18a713d9bd3c7a458bf7eb98e2b14895fb5 100644 GIT binary patch delta 93 zcmV-j0HXil0__3_aC2gG{{aAfkqA~JA^;%k1EeiKHSbgqh2Ht*3 z!0;aknAWr~f;mbI3dWIQ6IulvQgl-)otLa~Si|;y|FXRBSRtP8EGHLB?=VMFI)B5A zYZ_(q7oShe(0sAXKS^2M?uR53(}N>P=Fde>{p0`{>Ced0u}O|a=F@bs1_lPE-3yMN z660#;`?u3!^@IywH2hyl$MGtPr`I*vAFk64PiB&`{`&j7`GwD!lmEKi@f7B?ejTiv z>i^*W&F)L3t#{^YiWDEc#bv<205lAOfj(`3TB0~Jg$HDbpho;(c|F%1xAZpa>Qu_D zsx1pPs5`D^$!H_9tLXSQbLPOxybB_3PAfM$YtPiL(TY=6v-mk<|G6By9(oo)L1{iw$}*jQ^tXJQx_ZLdv*mZ0`JAKH znKd?ra#pGyyL9f>%eKnIrFYNhHSEpeWymOMJ1kf22?HZT960XQ-UE6N2;T35 z(CDNmNB|Ufj1IiaU`b%yRov!?wy0ZYaAj$WUZB(dWrE?HOVgWfQ<48Zv7}^xoe5_5T!^S3S!Ab@2IzVm+podKSH}n@n|dAJ)2G4)e+L z>@qp~^KS4uB{qT<$zTfwNMdAQP+}wK3>j?c0ZBh0N6KJ}YM6coMn+Izv4-xH<9~Tt zb7K1H)oo@sPEP;8X2Hd<6G4lx kdKMh1Kmw?rkTYa7BxY>JNOGV=0oG5@kyrx@WHt*3 z!0;aknAWr~f;mbI3dWIQ6IulvQgl-)otLa~Si|;y|FXRBSRtP8EGHLB?=VMFdZ?gu zZm-3`Mcoa;>}5xagLb7}NdIa3?P0mh;-~+Z*2RL2WMqf~J7(=YFqh%|J_wCYdV&N% zj$w4*Wd=(E9aC|eBif>Foxzo*EqZ}Y`8e?n6-9?#``L(90-+u^m1}< zQy+3CS|nqi9F=Uqz|a768W;n8-v9|+1_mWIg3gdBK6;A_kA6aql+j2DV8f-Kfsqju zSgfHt<@jHo)|{BWdUc!Gjg!+quvu_1EN2vcvu2ImW^r3Zrazf!SLS?OW4$cZUheci z*KZusUlqfPEO!@l{(h0iU+S#LtQ5mqsBo(Nz}rW@o=W}NS{BPY4Xk1SX70DAc&2LJ#7 literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/TX-21.ms_honest_change_no_xpubs.psbt b/tests/data/psbt_test_suite/TX-21.ms_honest_change_no_xpubs.psbt new file mode 100644 index 0000000000000000000000000000000000000000..dcbdf720af633aa2ea21c0060ec8a146ec44dc6e GIT binary patch literal 846 zcmXRYPAd7&$k55ez`(#5^=(aYL};e)MDeQXB^O^j`1xaASH_gN|5CVX|NG57>Ht*3 z!0;aknAWr~f;mbI3hJ&2Oa^E7-p^Gz>T~vo?A8F|XSq$h0lw3^PMvtax$+Z|(l61> z*QRqNAN&1I^uzvlSEsyAOF#2y_TqyoTVp~d?+Gjf8_CEJ2X@TbdtffZ`+X1^o%93= zfE>f*d_U5nur^vkOQU0%k&p#CFF}2jQ=zZN}s-yd`*8OsrPo8I&$=RQG zgV!ms5wu9gJ~=AcfPtX_=rk|}`n~}Yx(p0TYy_PlQ+)Im7askD94Vub62OK_KLaBp zD6m*VcgpdyUpUZip)wetc41v+7G;aHt*3 z!0;aknAWr~f;mbI3hJ&2Oa^E7-p^Gz>T~vo?A8F|XSq$h0lw3^PMvtax$+Z|(gLmd zHxlX=Zz~bpAC|rK&yLOBXS~=}GiAsGyYAU@C(#gOq(37|$0j)znNQQj8W`)e|m!(eQsI9mlIEo?h2vf4ELJJef(#`s?rS<`+I^PX6n5$5WWo`gO2w zs{e!gH@h#Dw%(bqDN=m&7MB471JE!C2KuxCYKh{^6dsTzf*SFE<@H>5+|t{ut5Yer zsq?O!Gs&bf3=aC7^Ia{mYS zs?}eD)G@MV1}QSRN~+~uTXVOAYk|AAp&0qgdk$Kgl{9gy3e<;>tYN=<@`?|?gNB3c^ z`{gj7JkKtZvp??!uTx?pXps!ozyN!QfkBClpfhB!B@0NJ2J0u}NEwZk05*)sfZET% z$OsB7*3g}D{4Y;yPE23Dy3Opy$>|^1EVvk!GYY?1v&L?-xUC|yQVeUM!m0KHZy))3 zD)nn?SuF1~yrL~WA!X6ALsuF%e^X@6b#ZPn746GEEMvQ7&z-xq&$tv*N=4dO?ipJ1 nYt0Cp0t_rBf)-)*EI3kugc1`$XJGX#l72#t#2Q&J{R|8MHLa9O literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/XTRAS.LEGACY_P2SH_WITNESS_ONLY.psbt b/tests/data/psbt_test_suite/XTRAS.LEGACY_P2SH_WITNESS_ONLY.psbt new file mode 100644 index 0000000000000000000000000000000000000000..68e7a672df41811b616d1f3302da1445a9dd65cd GIT binary patch literal 1076 zcmXRYPAd7&$WX_`z`(%B`{a4!QpMnY{~V*)<(rD*?oKgweCfCIUZ|!byT?qn>p(RO z4F7?EX-x|wm?OSYB<)~Uw|$_S>3Pn7o;MW!oRisn-?<$ouf(8m#9m7!J0ky#=@b7y zN>eX=TIv7OYD0gg$En1~kJlXh=7P-eXJqNvB*!B2X}VYg0|V3U1;zeEj*Xf2QGf7#0{r%ni!spD%f8FkQ3UgY&4%SWee{lb1_odR- zJM%R~ijUsnGGJf;8V12Y?=?UzQJk5=1F}R=BmS?vp6iZVdYg51D&T#j9jSF>f;E-w*{lmIpymb@$c zaTH{U#pMl5flHD%{C~N1>Lu}@G@mGCna)4@TfR+QJ>l%x^1IA@&Qa^k8k<5nD^-tO zI(O@3TV>+XyJz$o_Ga-iWE8a>7O_u`N=CPYfss+cftMNRIR*w`3}ka2Gvmm)SpB;D zQpNdw$EF;zYmI4VWXTLtWO9{M%e%JbZU@%_ck4ec;gxY((wT}3dTuA0&A$KDnR8o_ z*+a&xwL3K4S6SsisPv?14nF@-tjE++&!YEr zlc|pG!&>*tVLo}DT_$IL-VI)-#758}8EpQ5q#*_dB{qW2kiizCNcssmQU+UO!SpjQ zGJpb$HFT#O|I5>w6Vq3(ZZo@aa{3203oeG`jKXi$tg+iHZmYl+ef~h zO8wee7Rx&guV{-;NLh63(3Qr`-xQg1U7TA?Mf>s(%h;~jbLVdDGcLuHQjs>6dxqBh oS~CKt00WDOphZ|c3yN%zgO!*FIs>a`k@ORCB-Y4+>1SX70MmeTkKgNsvnSFidzG0a3Hz}c%o d?uO90=o6p!M~5ZYioDUke>$RWEQ0;Bqe6%F! zwJ$dG$l7_1Asx=jcvcZ-Zef&^!nLn~FUY0Msgrod5s; literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/XTRAS.OP_RETURN_DIRECT_PUSH_V2.psbt b/tests/data/psbt_test_suite/XTRAS.OP_RETURN_DIRECT_PUSH_V2.psbt new file mode 100644 index 0000000000000000000000000000000000000000..0c956208a25ba794cfc41391124d8390c0533301 GIT binary patch literal 420 zcmXRYPAd7&$i%|Lz`(%B%mO4C7+Dw@8Ce;b8GnOC85kMm9e9~RG7Mr2B6cP-Vo&AY zJ^9;gro)rtHy*Xy2hCApV`d6g>F9Hswd3*a_3{-=Dcy4}$jx?aX+8SOM|yTR!^33~ z#Yb;(g)lHQ08Ig7Mj!(O82J>k5>Lu3JGxWrjJD-%=cL^h^?MASmP)+;7rFKCrEj0w ztQq+s?h;`64+KE>0G)B*+@5QPFQ4iuy%Tp#Z(pb}-%o)@N=(cKSN$*Cb>hm4?=@5T z`q@Kgohg6i)eoiCU-!MAqdRfE4TduyjsSTYhoOwj9BW#jjs@E+v~`M7r@di*9ryI~8Aqfpue*K-SHom8IdFk(ig9nv;`Xq>!JdP?C|VkW`eJm#vVW2IOQGr6?pN PX6EFVmH@4VIgJ4T<~@kf literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/XTRAS.PREV_TX_TXID_MISMATCH.psbt b/tests/data/psbt_test_suite/XTRAS.PREV_TX_TXID_MISMATCH.psbt new file mode 100644 index 0000000000000000000000000000000000000000..3ab263d477e88d185010fa841a1393c187e4b14f GIT binary patch literal 346 zcmXRYPAd7&$WYG2z`(%Be6UV5_%ZkAt3?r2VUt4=TC84Ps4-@E^_8=z*6OIsAD|ir zhW|jow4jX<%#kcxDRSW4o@<9MpXw>S6L(B+U#KzPPk~1rYmik0MSS&|qJBN^4YSBz zk=s>IQ}*k|bgTgx!1$X5Yz`wsDA)yS?}51t@ApAybkY+f0CEANh9EOo6669qlNqt6 z^6#GfZ8p>4$?+SH+UF9Hswd3*a_3{-=Dcy4}$jx?aX+8SOM|yTR z!^33~#Yb;(g)lHQ0F47W5P6ulwH5 P(Ve*7217GY8x#NlrAu-* literal 0 HcmV?d00001 diff --git a/tests/data/psbt_test_suite/XTRAS.PREV_TX_TXID_MISMATCH_V2.psbt b/tests/data/psbt_test_suite/XTRAS.PREV_TX_TXID_MISMATCH_V2.psbt new file mode 100644 index 0000000000000000000000000000000000000000..de7d7347ecad7af69843c041110713add07254b2 GIT binary patch literal 373 zcmXRYPAd7&$i%|Lz`(%B%mO4C7+Dw@8Ce;b7=MFB85kKt!Ln=bfn*sN-tU9Z=%gn| z;6D&BY6voeB_+#NirAUVh&`2m_vCN0nGR2m-+0t+A2g?94MrN#O0B={dp}2a;(8kl+aPv7O0)mDoH9rN~GE?C*?deUIdhv}&50O!zhF8}}l literal 0 HcmV?d00001 diff --git a/tests/psbt_suite_util.py b/tests/psbt_suite_util.py index 075375d58..b4cc94887 100644 --- a/tests/psbt_suite_util.py +++ b/tests/psbt_suite_util.py @@ -83,6 +83,7 @@ class RejectCode: SEED_CANNOT_SIGN = "SEED_CANNOT_SIGN" SURPLUS_DERIVATIONS = "SURPLUS_DERIVATIONS" MISLABELED_OUTPUT_OWNERSHIP = "MISLABELED_OUTPUT_OWNERSHIP" + INCONSISTENT_FINGERPRINTS = "INCONSISTENT_FINGERPRINTS" MIXED_DERIVATION_MAPS = "MIXED_DERIVATION_MAPS" @@ -691,19 +692,19 @@ def path(self) -> str: ), Vector( "TX-20.cltv_height", "coverage", - "Meant as a CLTV-locked P2WSH output.", + "A P2WSH output whose witness script is CLTV-locked at a block height ~2 " + "years out.", Expect.PARSES, input_amount=100_000, output_amount=99_000, num_outputs=2, owned_outputs=1, - # The shipped scriptPubKey is still a p2wpkh; the CLTV witness script is - # attached but not committed, so there is correctly nothing to flag. - vacuous=True, + advisories=frozenset({Advisory.SCRIPT_TIMELOCK}), ), Vector( "TX-20.csv_relative", "coverage", - "Meant as a CSV-locked P2WSH output.", + "A P2WSH output whose witness script is CSV-locked (144 blocks after it " + "confirms). Unlike TX-19 the hold lives in the output's own script.", Expect.PARSES, input_amount=100_000, output_amount=99_000, num_outputs=2, owned_outputs=1, - vacuous=True, # same upstream defect as TX-20.cltv_height + advisories=frozenset({Advisory.SCRIPT_TIMELOCK}), ), # --------------------------------------------------------------- ownership @@ -897,6 +898,77 @@ def path(self) -> str: input_amount=200_000, output_amount=199_000, num_outputs=2, reject_code=RejectCode.FORGED_OUTPUT_OWNERSHIP, ), + + # ------------------------------------------ upstream-review follow-ups + Vector( + "XTRAS.PREV_TX_TXID_MISMATCH", "extras", + "Legacy input really spends 1,000,000 sats, but its previous tx was edited " + "to claim 201,000: the screen would show a 1,000-sat fee for an 800,000-sat " + "one. A legacy signature commits to no amount; only the previous tx's hash " + "catches it.", + Expect.REJECT_PARSER, + num_outputs=2, + reject_code=RejectCode.UTXO_MISMATCH, + ), + Vector( + "XTRAS.PREV_TX_TXID_MISMATCH_V2", "extras", + "BIP-370 twin of XTRAS.PREV_TX_TXID_MISMATCH.", + Expect.REJECT_PARSER, + num_outputs=2, + reject_code=RejectCode.UTXO_MISMATCH, + ), + Vector( + "XTRAS.OP_RETURN_DIRECT_PUSH", "extras", + "Negative control: a zero-value OP_RETURN whose 40-byte payload is pushed " + "directly, as Bitcoin Core writes it. Must be shown byte-for-byte.", + Expect.PARSES, + input_amount=200_000, output_amount=199_000, num_outputs=3, owned_outputs=1, + ), + Vector( + "XTRAS.OP_RETURN_DIRECT_PUSH_V2", "extras", + "BIP-370 twin of XTRAS.OP_RETURN_DIRECT_PUSH.", + Expect.PARSES, + input_amount=200_000, output_amount=199_000, num_outputs=3, owned_outputs=1, + ), + Vector( + "XTRAS.LEGACY_P2SH_WITNESS_ONLY", "multisig", + "Legacy P2SH multisig input described only by a witness_utxo: an amount a " + "legacy signature never commits to, with no previous tx to prove it.", + Expect.REJECT_PARSER, + input_amount=200_000, output_amount=199_000, num_outputs=2, + reject_code=RejectCode.INVALID_WITNESS_UTXO, + ), + Vector( + "TX-24.xpub_fingerprint_mismatch", "multisig", + "One cosigner's global xpub relabelled to a foreign fingerprint while its " + "derivation entries keep the real one: the psbt contradicts itself.", + Expect.REJECT_PARSER, + input_amount=200_000, output_amount=199_000, num_outputs=2, + reject_code=RejectCode.INCONSISTENT_FINGERPRINTS, + ), + Vector( + "TX-21.ms_foreign_quorum", "multisig", + "Change paid to a different 2-of-3 that still contains our key (one " + "cosigner swapped for a stranger's). The global xpubs do not derive the " + "stranger, so it is a payment.", + Expect.PARSES, + input_amount=200_000, output_amount=199_000, num_outputs=2, owned_outputs=0, + ), + Vector( + "TX-21.ms_foreign_quorum_no_xpubs", "multisig", + "The same foreign 2-of-3 with the global xpubs withheld. Nothing ties its " + "keys to the inputs' wallet, so it stays a payment -- even once a " + "descriptor is loaded, since that descriptor does not own it.", + Expect.PARSES, + input_amount=200_000, output_amount=199_000, num_outputs=2, owned_outputs=0, + ), + Vector( + "TX-21.ms_honest_change_no_xpubs", "multisig", + "Negative control: genuine multisig change from a coordinator that omits " + "global xpubs. A payment until the descriptor identifies it as change.", + Expect.PARSES, + input_amount=200_000, output_amount=199_000, num_outputs=2, owned_outputs=0, + ), ] VECTORS_BY_NAME = {v.name: v for v in VECTORS} diff --git a/tests/test_flows_psbt_malicious.py b/tests/test_flows_psbt_malicious.py index ca3564a89..7e3277ffd 100644 --- a/tests/test_flows_psbt_malicious.py +++ b/tests/test_flows_psbt_malicious.py @@ -145,3 +145,79 @@ def test_unparseable_psbt_is_rejected_at_scan(self): before_run=self.load_psbt_as_ur2("TX-04")), FlowStep(MainMenuView), ]) + + + def test_unidentified_multisig_change_is_a_payment_until_identified(self): + """ + With no global xpubs, genuine multisig change looks exactly like a different + wallet that shares our key (TX-21.ms_foreign_quorum_no_xpubs). Without the + descriptor it is shown as a payment, and the user is told a descriptor would + identify it. Continuing without one reviews it as the full spend it appears to be. + """ + def assert_unidentified(view): + assert view.controller.psbt_parser.unidentified_change_outputs == [0] + assert view.controller.psbt_parser.num_change_outputs == 0 + + self.run_sequence( + self.scan_and_select_seed("TX-21.ms_honest_change_no_xpubs") + [ + FlowStep(psbt_views.PSBTOverviewView, screen_return_value=0), + FlowStep(psbt_views.PSBTIdentifyChangeView, before_run=assert_unidentified, + button_data_selection=psbt_views.PSBTIdentifyChangeView.CONTINUE_AS_PAYMENT), + FlowStep(psbt_views.PSBTNoChangeWarningView), + ] + ) + + def test_loading_the_descriptor_identifies_the_change(self): + """"Load descriptor" goes to the descriptor loader, resuming the psbt flow.""" + from seedsigner.controller import Controller + from seedsigner.views.seed_views import LoadMultisigWalletDescriptorView + + def assert_resumes(view): + assert view.controller.resume_main_flow == Controller.FLOW__PSBT + + self.run_sequence( + self.scan_and_select_seed("TX-21.ms_honest_change_no_xpubs") + [ + FlowStep(psbt_views.PSBTOverviewView, screen_return_value=0), + FlowStep(psbt_views.PSBTIdentifyChangeView, + button_data_selection=psbt_views.PSBTIdentifyChangeView.LOAD_DESCRIPTOR), + FlowStep(LoadMultisigWalletDescriptorView, before_run=assert_resumes), + ] + ) + + def test_returning_with_a_descriptor_re_reads_the_psbt(self): + """ + Once a descriptor is loaded, "Return to transaction" discards the parse that + couldn't identify the change and restarts review, now with the change shown as + change. (Starts at MultisigWalletDescriptorView, as after a descriptor scan.) + """ + from embit.descriptor import Descriptor + + from seedsigner.controller import Controller + from seedsigner.models.psbt_parser import PSBTParser + from seedsigner.views.seed_views import MultisigWalletDescriptorView + + from psbt_suite_util import MULTISIG_DESCRIPTOR, SUITE_NETWORK, load_psbt + + seed = self.controller.storage.seeds[0] + psbt = load_psbt("TX-21.ms_honest_change_no_xpubs") + self.controller.psbt = psbt + self.controller.psbt_seed = seed + self.controller.psbt_parser = PSBTParser(psbt, seed=seed, network=SUITE_NETWORK) + assert self.controller.psbt_parser.unidentified_change_outputs == [0] + self.controller.multisig_wallet_descriptor = Descriptor.from_string(MULTISIG_DESCRIPTOR) + self.controller.resume_main_flow = Controller.FLOW__PSBT + # On a device the descriptor screen is on the back stack when RETURN skips it. + from seedsigner.views.view import Destination + self.controller.back_stack.append(Destination(MultisigWalletDescriptorView)) + + def assert_identified(view): + parser = view.controller.psbt_parser + assert parser.unidentified_change_outputs == [] + assert parser.num_change_outputs == 1 + + self.run_sequence([ + FlowStep(MultisigWalletDescriptorView, + button_data_selection=MultisigWalletDescriptorView.RETURN), + FlowStep(psbt_views.PSBTOverviewView, screen_return_value=0), + FlowStep(psbt_views.PSBTMathView, before_run=assert_identified), + ]) diff --git a/tests/test_psbt_refusal_screens.py b/tests/test_psbt_refusal_screens.py index fde3fee9f..d276c6c10 100644 --- a/tests/test_psbt_refusal_screens.py +++ b/tests/test_psbt_refusal_screens.py @@ -299,3 +299,23 @@ def test_shipped_json_is_plausible(self): data = json.loads(path.read_text(encoding="utf-8")) assert data["height"] > 900_000 assert data["timestamp"] > 1_700_000_000 + + +class TestIdentifyChangeScreenFits: + """PSBTIdentifyChangeView's text shares the warning box with a headline and two buttons.""" + + @pytest.mark.parametrize("text,buttons", [ + ("Load descriptor to identify change.", ["Load descriptor", "Continue as payment"]), + ("The loaded descriptor doesn't identify it. Shown as a payment.", ["Continue"]), + ]) + def test_text_fits(self, text, buttons): + screen = WarningScreen( + status_headline="Change Not Identified", + text=text, + button_data=[ButtonOption(b) for b in buttons], + show_back_button=True, + ) + text_area = [c for c in screen.components if c.__class__.__name__ == "TextArea"][-1] + lines = len(text_area.text_lines) + height = text_area.text_height_above_baseline * lines + text_area.line_spacing * (lines - 1) + assert height <= text_area.height, f"{lines} lines, {height}px in a {text_area.height}px box" diff --git a/tests/test_psbt_test_suite.py b/tests/test_psbt_test_suite.py index ac6bbdb2c..45b14381a 100644 --- a/tests/test_psbt_test_suite.py +++ b/tests/test_psbt_test_suite.py @@ -948,8 +948,16 @@ def test_committed_cltv_script_is_flagged(self): assert Advisory.SCRIPT_TIMELOCK in parse_vector(VECTORS_BY_NAME["TX-20.cltv_time"]).risk_warnings def test_uncommitted_script_is_ignored(self): - """TX-20.cltv_height's CLTV script does not hash to its p2wpkh output; it says nothing.""" - assert Advisory.SCRIPT_TIMELOCK not in parse_vector(VECTORS_BY_NAME["TX-20.cltv_height"]).risk_warnings + """A CLTV script the output does not commit to says nothing about the output.""" + from embit.psbt import PSBT + from embit.script import Script + + psbt = load_psbt("NORMAL-1_p2wpkh") + external = next(i for i, out in enumerate(psbt.outputs) if not out.bip32_derivations) + # <1,005,000> OP_CHECKLOCKTIMEVERIFY OP_DROP, attached to a p2wpkh output + psbt.outputs[external].witness_script = Script(bytes.fromhex("03c8550fb175")) + parser = PSBTParser(p=PSBT.parse(psbt.serialize()), seed=suite_seed(), network=SUITE_NETWORK) + assert Advisory.SCRIPT_TIMELOCK not in parser.risk_warnings def test_push_data_is_not_mistaken_for_an_opcode(self): from embit.script import Script @@ -963,3 +971,129 @@ def test_it_interrupts_rather_than_being_informational(self): from seedsigner.views.psbt_views import PSBTRiskWarningView assert RiskWarning.SCRIPT_TIMELOCK not in RiskWarning.INFORMATIONAL assert RiskWarning.SCRIPT_TIMELOCK in PSBTRiskWarningView.RISK_TEXT + + +class TestPreviousTxProof: + """ + A non_witness_utxo is the whole previous transaction, so it can be proven: it + must hash to the txid the input spends. Legacy signatures commit to no amount, + so this hash is the only thing standing between a lying amount and the fee. + """ + + def test_altered_previous_tx_is_refused(self): + """XTRAS.PREV_TX_TXID_MISMATCH would otherwise show a 1,000-sat fee for an 800,000-sat one.""" + with pytest.raises(InvalidPSBTError) as excinfo: + parse_vector(VECTORS_BY_NAME["XTRAS.PREV_TX_TXID_MISMATCH"]) + assert excinfo.value.code == RejectCode.UTXO_MISMATCH + + def test_editing_a_normal_legacy_prev_tx_is_caught(self): + psbt = load_psbt("NORMAL-3_legacy") + inp = psbt.inputs[0] + inp.non_witness_utxo.vout[inp.vout].value -= 1 + with pytest.raises(InvalidPSBTError) as excinfo: + PSBTParser(p=psbt, seed=suite_seed(), network=SUITE_NETWORK) + assert excinfo.value.code == RejectCode.UTXO_MISMATCH + + def test_spending_an_output_the_prev_tx_lacks_is_refused(self): + """A vout past the end of the previous tx used to escape as an IndexError.""" + from embit.psbt import PSBT + + psbt = load_psbt("NORMAL-3_legacy") + psbt.tx.vin[0].vout = 99 + psbt = PSBT.parse(psbt.serialize()) + psbt.inputs[0].vout = 99 + with pytest.raises(InvalidPSBTError) as excinfo: + PSBTParser(p=psbt, seed=suite_seed(), network=SUITE_NETWORK) + assert excinfo.value.code == RejectCode.UTXO_MISMATCH + + def test_honest_legacy_prev_tx_still_parses(self): + parser = parse_vector(VECTORS_BY_NAME["NORMAL-3_legacy"]) + assert parser.input_amount == 100_000_000 + + +class TestOpReturnPayload: + """The payload is read from its push opcode, never sliced at a fixed offset.""" + + MSG = b"Chancellor on the brink of third bailout" + + @pytest.mark.parametrize("name", ["XTRAS.OP_RETURN_DIRECT_PUSH", "XTRAS.OP_RETURN_DIRECT_PUSH_V2"]) + def test_direct_push_is_shown_exactly(self, name): + assert parse_vector(VECTORS_BY_NAME[name]).op_return_data == self.MSG + + @pytest.mark.parametrize("script,expected", [ + (b"j(" + MSG, MSG), # direct push (<= 75 bytes) + (b"jLP" + b"x" * 80, b"x" * 80), # OP_PUSHDATA1 + (b"jM," + b"y" * 300, b"y" * 300), # OP_PUSHDATA2 + (b"j", b""), # bare OP_RETURN + (b"jab", b"ab"), # truncated push: what is there + ]) + def test_payload_parsing(self, script, expected): + assert PSBTParser._op_return_payload(script) == expected + + +class TestFingerprintConsistency: + """A key's derivation entry and the global xpub deriving it must name the same master.""" + + def test_relabelled_global_xpub_is_refused(self): + with pytest.raises(InvalidPSBTError) as excinfo: + parse_vector(VECTORS_BY_NAME["TX-24.xpub_fingerprint_mismatch"]) + assert excinfo.value.code == RejectCode.INCONSISTENT_FINGERPRINTS + + def test_unknown_fingerprint_is_not_a_contradiction(self): + """Coordinators write 00000000 for a fingerprint they do not know.""" + from embit.psbt import DerivationPath + + psbt = load_psbt("TX-24.xpub_fingerprint_mismatch") + for xpub, origin in list(psbt.xpubs.items()): + if origin.fingerprint == bytes.fromhex("deadbeef"): + psbt.xpubs[xpub] = DerivationPath(bytes(4), origin.derivation) + # Refused only for a contradiction; an unknown fingerprint just leaves that + # cosigner unresolved, so the change waits on a descriptor to be identified. + parser = PSBTParser(p=psbt, seed=suite_seed(), network=SUITE_NETWORK) + assert parser.num_change_outputs + len(parser.unidentified_change_outputs) == 1 + + +class TestUnidentifiedMultisigChange: + """ + Without global xpubs, nothing in a psbt ties a multisig change script's other keys + to the inputs' wallet, so our key being in it proves nothing. Such outputs are + payments until a known-good descriptor identifies them. + """ + + @staticmethod + def _descriptor(): + from embit.descriptor import Descriptor + from psbt_suite_util import MULTISIG_DESCRIPTOR + return Descriptor.from_string(MULTISIG_DESCRIPTOR) + + def _parse(self, name, **kw): + return PSBTParser(p=load_psbt(name), seed=suite_seed(), network=SUITE_NETWORK, **kw) + + def test_honest_change_without_xpubs_is_unidentified(self): + parser = self._parse("TX-21.ms_honest_change_no_xpubs") + assert parser.num_change_outputs == 0 + assert parser.unidentified_change_outputs == [0] + assert parser.spend_amount == 199_000 + + def test_the_descriptor_identifies_it(self): + parser = self._parse("TX-21.ms_honest_change_no_xpubs", multisig_descriptor=self._descriptor()) + assert parser.num_change_outputs == 1 + assert parser.unidentified_change_outputs == [] + + def test_a_foreign_quorum_is_never_identified(self): + """Loading the real wallet's descriptor must not turn the foreign 2-of-3 into change.""" + parser = self._parse("TX-21.ms_foreign_quorum_no_xpubs", multisig_descriptor=self._descriptor()) + assert parser.num_change_outputs == 0 + assert parser.unidentified_change_outputs == [0] + + def test_with_xpubs_the_foreign_quorum_is_a_plain_payment(self): + parser = self._parse("TX-21.ms_foreign_quorum") + assert parser.num_change_outputs == 0 + assert parser.unidentified_change_outputs == [] + + def test_change_with_xpubs_needs_no_descriptor(self): + """Global xpubs resolve every cosigner, so identification doesn't wait on a descriptor.""" + psbt, _decoy = TestMultisigPolicy._honest_change() + parser = PSBTParser(p=psbt, seed=suite_seed(), network=SUITE_NETWORK) + assert parser.num_change_outputs == 1 + assert parser.unidentified_change_outputs == [] diff --git a/tests/test_untrusted_qr_hardening.py b/tests/test_untrusted_qr_hardening.py new file mode 100644 index 000000000..36a2b84fb --- /dev/null +++ b/tests/test_untrusted_qr_hardening.py @@ -0,0 +1,91 @@ +""" +Scanned QR payloads are untrusted input. Each of these used to escape as an +uncaught exception -- the System Error screen, or in the UR2 case a device that +appears frozen -- instead of being turned away as an invalid QR. Mirrors fixes +proposed upstream (SeedSigner #967, #968, #970, #971). +""" +import time + +import pytest + +from seedsigner.helpers import embit_utils +from seedsigner.models.decode_qr import DecodeQR, DecodeQRStatus +from seedsigner.models.qr_type import QRType +from seedsigner.models.settings_definition import SettingsConstants + + +def decode(data: str): + decoder = DecodeQR(wordlist_language_code=SettingsConstants.WORDLIST_LANGUAGE__ENGLISH) + return decoder, decoder.add_data(data) + + +class TestSignMessageQr: + + @pytest.mark.parametrize("payload", [ + "signmessage", + "signmessage m/84h/0h/0h/0/0", + "signmessage m/84h/0h/0h/0/0 nocolon", + ]) + def test_malformed_payload_is_invalid_not_a_crash(self, payload): + _decoder, status = decode(payload) + assert status == DecodeQRStatus.INVALID + + def test_message_keeps_spaces_and_a_second_format_marker(self): + decoder, status = decode("signmessage m/84h/0h/0h/0/0 ascii:hello world ascii:again") + assert status == DecodeQRStatus.COMPLETE + assert decoder.get_qr_data()["message"] == "hello world ascii:again" + + +class TestStandardSeedQr: + + def test_bad_checksum_is_invalid(self): + """'abandon' x12 is twelve valid words with an invalid checksum.""" + _decoder, status = decode("0000" * 12) + assert status == DecodeQRStatus.INVALID + + def test_valid_seedqr_still_decodes(self): + """'abandon' x11 + 'about' (word 3) is the canonical valid 12-word mnemonic.""" + decoder, status = decode("0000" * 11 + "0003") + assert status == DecodeQRStatus.COMPLETE + assert decoder.get_seed_phrase()[-1] == "about" + + def test_a_digit_run_inside_other_data_is_not_a_seedqr(self): + assert DecodeQR.detect_segment_type("settings::v1 " + "1" * 48) != QRType.SEED__SEEDQR + + def test_whole_payload_seedqr_is_detected(self): + assert DecodeQR.detect_segment_type("0000" * 11 + "0003") == QRType.SEED__SEEDQR + + +class TestParseDerivationPath: + + @pytest.mark.parametrize("path", ["", "m", "x", "m/", "m/84h", "m/48h/0h/0h/2h/0/0"]) + def test_unparseable_path_is_an_unclean_match(self, path): + assert embit_utils.parse_derivation_path(path)["clean_match"] is False + + def test_standard_path_still_parses(self): + details = embit_utils.parse_derivation_path("m/84h/0h/0h/0/5") + assert details["clean_match"] is True + assert details["index"] == 5 + + +class TestUR2SeqLenBound: + + @staticmethod + def _part(seq_num, seq_len): + from seedsigner.helpers.ur2.fountain_encoder import Part + return Part(seq_num=seq_num, seq_len=seq_len, message_len=32, checksum=0, data=b"\x00" * 32) + + def test_implausible_part_count_is_rejected_quickly(self): + from seedsigner.helpers.ur2.fountain_decoder import FountainDecoder, MAX_SEQ_LEN + + decoder = FountainDecoder() + started = time.monotonic() + assert decoder.receive_part(self._part(seq_num=MAX_SEQ_LEN * 10, seq_len=MAX_SEQ_LEN * 10)) is False + assert time.monotonic() - started < 1 + assert decoder.expected_part_indexes is None + + def test_plausible_part_count_is_accepted(self): + from seedsigner.helpers.ur2.fountain_decoder import FountainDecoder + + decoder = FountainDecoder() + assert decoder.validate_part(self._part(seq_num=1, seq_len=10)) is True From 8588683ba23d945f8fc42e1a8b82aff1de241a92 Mon Sep 17 00:00:00 2001 From: 3rd Iteration Date: Fri, 18 Sep 2026 13:53:04 -0400 Subject: [PATCH 4/4] test(screenshots): give the multisig PSBT global xpubs; add PSBTIdentifyChangeView The screenshot generator's multisig PSBT carries no PSBT_GLOBAL_XPUB, so since multisig change is only identified through global xpubs or a loaded descriptor, it had no change output and the PSBTChangeDetailsView_multisig_* screenshots crashed (get_change_data returned None), failing CI's "Generate screenshots". - The multisig screenshots now use a copy of that PSBT with global xpubs taken from its own wallet descriptor, like a coordinator that includes them. - The parser is built with the loaded descriptor, and the descriptor is loaded before the PSBT, so the "verified" screenshot parses the way the device would. - New screenshots for PSBTIdentifyChangeView (no descriptor / descriptor loaded), from the original xpub-less PSBT. Co-Authored-By: Claude Opus 5 --- tests/screenshot_generator/generator.py | 34 ++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/tests/screenshot_generator/generator.py b/tests/screenshot_generator/generator.py index 586d9f12f..b7d609ee5 100644 --- a/tests/screenshot_generator/generator.py +++ b/tests/screenshot_generator/generator.py @@ -124,6 +124,18 @@ def add_op_return_to_psbt(psbt: PSBT, raw_payload_data: bytes): MULTISIG_WALLET_DESCRIPTOR = """wsh(sortedmulti(1,[22bde1a9/48h/1h/0h/2h]tpubDFfsBrmpj226ZYiRszYi2qK6iGvh2vkkghfGB2YiRUVY4rqqedHCFEgw12FwDkm7rUoVtq9wLTKc6BN2sxswvQeQgp7m8st4FP8WtP8go76/{0,1}/*,[73c5da0a/48h/1h/0h/2h]tpubDFH9dgzveyD8zTbPUFuLrGmCydNvxehyNdUXKJAQN8x4aZ4j6UZqGfnqFrD4NqyaTVGKbvEW54tsvPTK2UoSbCC1PJY8iCNiwTL3RWZEheQ/{0,1}/*))#3jhtf6yx""" +# A coordinator that includes PSBT_GLOBAL_XPUB, which is what lets PSBTParser tie the +# multisig change's cosigner keys to the inputs' wallet. Without them the change stays +# a payment until a descriptor identifies it (see PSBTIdentifyChangeView). +def add_global_xpubs(base64_psbt: str, descriptor_str: str) -> str: + from embit.psbt import DerivationPath + psbt = PSBT.from_base64(base64_psbt) + for key in embit.descriptor.Descriptor.from_string(descriptor_str).keys: + psbt.xpubs[key.key] = DerivationPath(key.origin.fingerprint, key.origin.derivation) + return psbt.to_string() + +BASE64_MULTISIG_PSBT_WITH_XPUBS = add_global_xpubs(BASE64_MULTISIG_PSBT, MULTISIG_WALLET_DESCRIPTOR) + # Grab the most recent release version info for the "release build" splash screenshots. (latest_release_version_name, latest_release_version_timestamp) = VersionUtils._fetch_latest_seedsigner_release_tag() if not latest_release_version_name or not latest_release_version_timestamp: @@ -291,7 +303,7 @@ def mock_load_psbt(base64_psbt: str, seed: Seed = seed_12b): decoder.add_data(base64_psbt) with patch.object(controller, 'psbt', decoder.get_psbt()): with patch.object(controller, 'psbt_seed', seed): - with patch.object(controller, 'psbt_parser', PSBTParser(p=controller.psbt, seed=seed)): + with patch.object(controller, 'psbt_parser', PSBTParser(p=controller.psbt, seed=seed, multisig_descriptor=controller.multisig_wallet_descriptor)): yield @@ -303,6 +315,12 @@ def mock_single_sig_psbt_loaded(): @contextmanager def mock_multisig_psbt_loaded(): + with mock_load_psbt(BASE64_MULTISIG_PSBT_WITH_XPUBS): + yield + + + @contextmanager + def mock_multisig_psbt_without_xpubs_loaded(): with mock_load_psbt(BASE64_MULTISIG_PSBT): yield @@ -315,8 +333,16 @@ def mock_multisig_wallet_descriptor_loaded(): @contextmanager def mock_multisig_psbt_and_descriptor_loaded(): - with mock_multisig_psbt_loaded(): - with mock_multisig_wallet_descriptor_loaded(): + # Descriptor first: the parser is built with whatever descriptor is loaded. + with mock_multisig_wallet_descriptor_loaded(): + with mock_multisig_psbt_loaded(): + yield + + + @contextmanager + def mock_multisig_psbt_without_xpubs_and_descriptor_loaded(): + with mock_multisig_wallet_descriptor_loaded(): + with mock_multisig_psbt_without_xpubs_loaded(): yield @@ -507,6 +533,8 @@ def mock_version_to_most_recent_release(): ScreenshotConfig(psbt_views.PSBTUnsupportedScriptTypeWarningView), ScreenshotConfig(psbt_views.PSBTNoChangeWarningView), ScreenshotConfig(psbt_views.PSBTRiskWarningView, mock_context_manager=mock_psbt_with_risk_warnings_loaded), + ScreenshotConfig(psbt_views.PSBTIdentifyChangeView, screenshot_name="PSBTIdentifyChangeView_no_descriptor", mock_context_manager=mock_multisig_psbt_without_xpubs_loaded), + ScreenshotConfig(psbt_views.PSBTIdentifyChangeView, screenshot_name="PSBTIdentifyChangeView_descriptor_mismatch", mock_context_manager=mock_multisig_psbt_without_xpubs_and_descriptor_loaded), ScreenshotConfig(psbt_views.PSBTMathView, mock_context_manager=mock_multisig_psbt_loaded), ScreenshotConfig(psbt_views.PSBTAddressDetailsView, dict(address_num=0), mock_context_manager=mock_multisig_psbt_loaded),