Repository navigation
Conversation
The trailing `if sc.data == vout.script_pubkey.data` check at the end of _parse_outputs() is the sole path that sets is_change = True for multisig types (p2wsh, p2sh-p2wsh, legacy p2sh). Those branches set `sc` but contain no is_change assignment of their own. Removing this check would silently break multisig change detection. For single-sig types (pkh, p2tr), is_change is already set inside the elif branch — the trailing check fires redundantly and arrives at the same result. Pins current behavior across all seven script types. A future refactor that unifies the if/elif chain and moves is_change into each branch must keep this test passing. Part of SeedSigner#931.
nkatha23
force-pushed
the
tests/psbt-parser-duplicate-sc-data-check
branch
from
June 5, 2026 08:14
207d925 to
9e056be
Compare
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
_parse_outputs() in psbt_parser.py contains a structural defect in its if/elif chain. For multisig output types (p2wsh, p2sh-p2wsh, legacy p2sh), the branches set sc but never assign is_change = True internally. A trailing unconditional check after the entire chain is the sole path through which multisig outputs are ever classified as change. For single-sig types (pkh, p2tr), is_change is set inside the branch and then the trailing check fires again redundantly. This code path had no test pinning it, a future refactor could remove or restructure the trailing check and silently break multisig change detection.
Added test_parse_outputs_trailing_sc_data_check to TestPSBTParser. The test builds a single-output PSBT for each of the seven supported script types (three multisig, four single-sig) and asserts num_change_outputs == 1. The docstring explicitly names the trailing check, explains why it is load-bearing for multisig and redundant for single-sig, and describes what a correct post-fix refactor would look like.