Repository navigation
fix(psbt): harden change branch detection and path validation (fixes #1076) - #1077
muskan-creates352 wants to merge 1 commit into
Conversation
|
NACK. #1073 closes the gap behind this TODO at parse time, before any screen is shown. Recommend closing this PR and Issue #1076. Analysis and reply by Claude: What
How #1073 handles it: its change path rules require every change derivation path to hold both a branch and an address index, come back to a base path the inputs spend from, use the receive (0) or change (1) branch, and use a non-hardened address index. A path that fails any of these raises Notes on this PR's approach:
|
Description
Problem or Issue being addressed
PSBTParser.is_change_branch(), passingNoneasderivation_pathresulted in an unhandledTypeError: object of type 'NoneType' has no len().PSBTChangeDetailsView.run(),verified_derivation_path[-1]directly indexed the derivation path without validating its presence or length, leading to potentialIndexError/TypeErrorcrashes when encountering change outputs with malformed, empty, or truncated paths (leaving an unaddressed# TODO: Refuse a path too short to carry a branch and an address index).Fixes #1076
Solution
PSBTParser.is_change_branch(src/seedsigner/models/psbt_parser.py):derivation_pathis a non-empty sequence (listortuple) of length >= 2 before inspectingderivation_path[-2] == 1. ReturnsFalsesafely forNone, empty, or truncated inputs.PSBTChangeDetailsView(src/seedsigner/views/psbt_views.py):verified_derivation_pathand checks whether it contains at least 2 elements.Destination(PSBTUnsupportedDerivationPathView, clear_history=True)instead of raising an uncaught exception.test__is_change_branch__handles_invalid_and_edge_case_pathsintests/test_psbt_parser.pytestingNone,[],[0], invalid types, and valid change/receive paths.test_change_details_with_invalid_derivation_path_redirects_to_unsupported_derivationintests/test_flows_psbt.pyverifying graceful redirection toPSBTUnsupportedDerivationPathView.Additional Information
Zero breaking changes. All valid PSBT change outputs and self-transfers continue to parse and display as expected.
Screenshots
N/A (Redirection to existing
PSBTUnsupportedDerivationPathView).This pull request is categorized as a:
Checklist
I ran pytest locally
All tests passed before submitting the PR
I couldn't run the tests
N/A
I included screenshots of any new or modified screens
Yes
No
N/A
I added or updated tests
Yes
No, I’m a fool
N/A
I tested this PR hands-on on the following platform(s):
I have reviewed these notes:
I understand