Skip to content

Resync psbt_faker corpus and close the PSBT gaps it exposes - #447

Merged
3rdIteration merged 4 commits into
devfrom
feat/psbt-faker-resync
Sep 18, 2026
Merged

3rdIteration merged 4 commits into
devfrom
feat/psbt-faker-resync

Conversation

@3rdIteration

@3rdIteration 3rdIteration commented Sep 18, 2026 •

Copy link
Copy Markdown
Owner

Summary

Re-vendors the regenerated psbt_faker adversarial corpus (97 vectors, with the fixed BIP-371 taproot encoding). tests/psbt_suite_util.py now has an expected result for every vector, and five parser gaps it exposed are closed.

Parser changes (models/psbt_parser.py)

Vector(s) Before Now
TX-21.claims_us_pays_other(_V2), TX-21.ms_repointed_keys/spk, TX-22.ms_decoy_first/last Parsed as an ordinary payment Refused as FORGED_OUTPUT_OWNERSHIP: a genuine key of ours on an output whose script doesn't pay it
TX-21.pays_us_claims_other(_V2), taproot_claims_other, ms_fp_relabeled Parsed Refused as new MISLABELED_OUTPUT_OWNERSHIP: output pays our key but is labelled as another wallet's
TX-22.surplus_paths, taproot_surplus_internal_key Parsed Refused as new SURPLUS_DERIVATIONS
TX-22.mixed_path_maps(_input) Parsed Refused as new MIXED_DERIVATION_MAPS
TX-20.cltv_time No warning New SCRIPT_TIMELOCK warning (CLTV/CSV in the output's committed script)
TX-22.ms_decoy_last with a descriptor loaded verify_multisig_output returned True Every derivation entry is checked; embit's Descriptor.owns stops at the first match

Each new refusal code has a REJECT_PRESENTATION screen, and SCRIPT_TIMELOCK has warning text.

Test changes

  • Updated table entries that the new bytes made wrong: TX-09.*, TX-11.v1_bech32 and TX-16.foreign_fingerprint now parse. TX-14.cross_net and XTRAS.NETWORK_HRP_MISMATCH are now real traps and are refused as FORGED_INPUT_OWNERSHIP.
  • The unparseable-scan flow test now uses TX-04, because TX-16.foreign_fingerprint parses now.
  • Added TestOutputClaimsMatchScripts, TestMultisigPolicy (against the suite's 2-of-3 descriptor) and TestScriptTimelock.
  • test_real_refusal_message_fits now skips codes that render fixed prose; test_table_prose_fits covers those.

Known limitations

  • TX-20.cltv_height and csv_relative are vacuous upstream: their scriptPubKey is still p2wpkh, so the CLTV/CSV script isn't committed. They're marked vacuous=True.
  • TX-13.threshold and TX-13.reorder are only caught when a multisig descriptor is loaded.

Test plan

  • pytest tests/test_psbt_test_suite.py tests/test_flows_psbt_malicious.py tests/test_psbt_refusal_screens.py tests/test_psbt_parser.py: 660 passed
  • Full pytest tests: the only failures are Satochip/Satodime smartcard tests. They come from a local pysatochip 0.17.0 (missing card_get_ndef_v2) and flaky simulator ordering, and they pass when run on their own.

Follow-up: upstream PR review (commits e2fe07a, d5d5d92)

Ported from open upstream SeedSigner PRs and their review threads. Each has a new psbt_faker vector:

Change Upstream Before After
A non_witness_utxo must hash to the txid its input spends SeedSigner#995 / SeedSigner#977 XTRAS.PREV_TX_TXID_MISMATCH showed a 1,000-sat fee for an 800,000-sat one Refused (UTXO_MISMATCH)
A legacy p2sh input can't rely on a witness_utxo alone SeedSigner#995 Accepted Refused (INVALID_WITNESS_UTXO)
Multisig change with no global xpubs review thread on SeedSigner#1032 A different m-of-n containing our key was shown as change Shown as a payment unless a loaded descriptor identifies it. New PSBTIdentifyChangeView: "Load descriptor to identify change" or "Continue as payment". Returning with a descriptor re-reads the psbt
OP_RETURN payload read from its push opcode SeedSigner#965 / SeedSigner#1003 hancellor on the brink… Shown exactly
Global-xpub vs derivation fingerprint consistency SeedSigner#1040 Accepted Refused (new INCONSISTENT_FINGERPRINTS)
Untrusted-QR crashes: SeedQR checksum and detection, signmessage bounds, parse_derivation_path, UR2 seq_len bound SeedSigner#967 / SeedSigner#968 / SeedSigner#971 / SeedSigner#970 System Error screen, or a UR2 frame could hang the device Rejected as an invalid QR / unsupported path

TX-20 and XTRAS.MIXED_INPUT_TYPES were re-vendored after generator fixes in psbt_faker: wrong CLTV/CSV opcode values, P2WSH built as a hash160, and a placeholder txid. All three TX-20 vectors now carry a committed timelock and warn.

Test isolation fix: test_psbt_refusal_screens.py imported the GUI before tests/base.py installed its renderer and button doubles. Any flow test collected after it hung forever: on an unconfigured Renderer, or on real buttons waiting for input. The full suite only passed because of alphabetical ordering. Every order now passes.

Tests: PSBT, QR and flow suites 769 passed. On the full suite, the only failures are the known Satochip/Satodime smartcard tests (local pysatochip 0.17.0 and simulator flakiness).

🤖 Generated with Claude Code

3rdIteration and others added 4 commits September 18, 2026 08:22
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 <noreply@anthropic.com>
… 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 <noreply@anthropic.com>
…ia descriptor

From a review of open upstream SeedSigner PRs and their discussions:

- Previous-tx proof (upstream SeedSigner#995/SeedSigner#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 SeedSigner#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 (SeedSigner#965/SeedSigner#1003): direct pushes lost
  their first byte on screen.
- INCONSISTENT_FINGERPRINTS (SeedSigner#1040): a global xpub whose fingerprint disagrees
  with the keys it derives.
- Untrusted-QR crashes (SeedSigner#967/SeedSigner#968/SeedSigner#970/SeedSigner#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 <noreply@anthropic.com>
…ifyChangeView

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 <noreply@anthropic.com>
@3rdIteration
3rdIteration merged commit bae7c9f into dev Sep 18, 2026
26 of 32 checks passed
@3rdIteration
3rdIteration deleted the feat/psbt-faker-resync branch September 18, 2026 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant