Test change at an extra level under the base path
What changed, and why it matters
This commit only adds a new test case to the project's test suite. It does not change any production code. The new test checks that the existing PSBT parser correctly rejects a specific kind of suspicious change output (one placed at a deeper derivation path than expected). Because no actual parser logic is modified, this commit by itself does not fix or introduce a security vulnerability.
No action required for this commit alone. If reviewing the broader codebase, verify that the production PSBT parser's base-path equality check is already present and robust, since this test assumes it exists.
Security signals we found
Adds defensive test coverage for PSBT change-output derivation-path validation
Relates to preventing a coordinator with an account xpub from routing change to an unexpected deeper path
Evidence from the diff
The diff modifies tests/test_psbt_parser.py, expanding test__parse__refuses_change_to_a_base_path_this_transaction_does_not_spend_from to cover an additional variant: a change output whose derivation path extends the input’s base path by an extra level (e.g., …/7/1/0 instead of just altering the last level). The production parsing rule already compares base paths for equality; this commit adds test coverage to ensure a prefix-only comparison would be caught. No implementation code was changed.
Changed components
tests/test_psbt_parser.pyInspect captured patch +17 / −3
### tests/test_psbt_parser.py
@@ -3699,9 +3699,13 @@ def test__parse__refuses_change_to_a_base_path_this_transaction_does_not_spend_f
"""
Change may only come back to a base path that one of our inputs spends from.
- The psbt pays change to our key at the input's base path with its last level
- changed to 7h. The parse should refuse the change with
- PSBTChangeDerivationPathError, naming the change's path.
+ The psbt pays change to our key at a different base path. Two variants are
+ tested:
+ * the input's base path with its last level changed.
+ * the input's base path with an extra level added to the end.
+
+ The parse should refuse each with a PSBTChangeDerivationPathError. The problematic
+ derivation path should be included in the exception object.
"""
for input_base64, change_hex in self.WALLETS:
input_derivation_path = self._input_derivation_path(input_base64)
@@ -3718,6 +3722,16 @@ def test__parse__refuses_change_to_a_base_path_this_transaction_does_not_spend_f
self._parse(psbt)
assert exc_info.value.derivation_path == bip32.parse_path(change_at_other_base_path)
+ # The input's base path with an extra level added to the end
+ input_base_path_levels = input_derivation_path.split("/")[:-2]
+ change_at_extended_base_path = "/".join(input_base_path_levels + ["7", "1", "0"])
+
+ repoint_change(psbt, change_at_extended_base_path)
+
+ with pytest.raises(PSBTChangeDerivationPathError) as exc_info:
+ self._parse(psbt)
+ assert exc_info.value.derivation_path == bip32.parse_path(change_at_extended_base_path)
+
def test__parse__accepts_change_to_any_base_path_this_transaction_spends_from(self):
"""Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.