Repository navigation
[security] Check input claims against the input's committed script - #1060
Merged
Merged
Conversation
Contributor
Author
|
testqrs.com now updated with tests for this PR. |
kdmukai
marked this pull request as ready for review
October 30, 2026 12:02
A false input claim, entries in both derivation path maps, and surplus output entries might each be an honest bug. They are now held in one list instead of raised where found. parse() raises the first one after _parse_outputs, so an output contradiction found later is still the one reported. A held input is set aside (its verified list emptied). A held output counts as a spend without its claims being evaluated. Input claim verification moves into _parse_inputs. The wrong-seed check moves after it and stands aside while a finding is held. Deletes get_input_fingerprints, which had no callers.
Re-deriving a claimed key proves our seed owns it, not that the input spends with it. Each verified entry must now be a key the input's committed script uses. Only the entries that pass are kept in verified_input_derivation_paths. An entry that fails raises PSBTInputOwnershipContradictionError. Taproot rebuilds the address with the input's merkle root, the same tweak embit signs with. A failing internal key claim raises the same error when the input supplies its merkle root. It is dropped when a taproot input omits the merkle root. A failing leaf key claim is dropped. An input this seed can sign only through a script path holds PSBTUnsupportedScriptPathError.
A claim of ours at the empty path (the master key), on an input or an output, or at a one-level path on an input, is held as PSBTUnsupportedDerivationPathError. No wallet writes an entry at these paths, though embit would sign an input built on the master key. The check runs after the claim loops, so a forged claim in the same input or output is still the one reported.
kdmukai
force-pushed
the
2026-10_psbt_input_claims
branch
from
October 30, 2026 13:17
04c58f6 to
865f249
Compare
Contributor
Author
|
Rebased to latest |
parse()'s docstring listed every held finding, far from the code that holds each one. Each step that holds findings now ends its docstring with a Holds: list, and parse() keeps only the principle: a milder finding is held aside while the remaining checks run and is raised only if they find nothing more serious. Holding is a side effect a caller cannot see, which is why it gets a list and the raises do not. Drops the "see parse()" pointers to the held findings. An input whose claims are set aside is now described as left with no verified derivation paths rather than as "not ours".
Twelve places in the tests changed an input's scriptPubKey and then dropped its non_witness_utxo, each with its own comment on why. The previous transaction still pays the old scriptPubKey, and editing it to match would change its txid, so the drop is required. set_input_locking_script does both and explains it once. The bare multisig test keeps its own edit: that input is not segwit, so the helper's witness-only reasoning does not hold there.
Collaborator
|
ACK and reviewed as of b297c86. Tested on device with testqrs.com. There was a lot more to this PR than I initially anticipated. |
6 tasks done
Contributor
Author
|
Description updated (no code changes in this PR):
|
8 of 23 tasks
|
post-merge ACK, great additions. |
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.
The problem:
The solution:
More precise description below by Claude, primarily intended to be consumed by other AIs
Measured at #1047's head and at this PR's head
PSBTInputOwnershipContradictionErrorPSBTUnsupportedScriptPathErrorm, or an input at the one-level pathm/5PSBTUnsupportedDerivationPathErrorFor the psbts that parse without this PR, embit's
sign_withwith the user's seed adds:m/5inputs: a usable signature for a utxo that key really controls.So no psbt in the table can move funds the user did not approve. With this PR, each is refused before review.
The wrong-seed row is a behavior change. The wrong-seed check reads which inputs are ours, which
_parse_inputsnow decides after #995's amount checks and #1047's script checks have run. So a wrong-seed psbt with one of those problems reports the problem: a bad script or a contradicted amount as "Likely an Attack!", and a missing utxo as "Transaction Problem".Not covered
An input falsely described as controlled by one of our keys. The script check reads the input's scriptPubKey from the psbt's own utxo fields. Nothing in the parse authenticates it. [security] Verify PSBT input amounts before displaying the fee #995's txid check ties a previous transaction only to the txid that the psbt itself names. Measured at this PR's head: a made-up input paying one of our keys, with a true claim on it, parses and counts as ours, both with a
witness_utxoalone and with a made-up previous transaction plus a rewritten txid.witness_utxorewritten to pay one of our keys. On segwit v0 that transaction can still confirm because BIP-143 leaves the user's signature on their real input unchanged (measured: the same sighash either way). Taproot signatures commit every input's scriptPubKey and amount. A legacy input's previous transaction has to match its real txid. So neither is exposed.Change at a one-level path. The one-level refusal covers inputs only. Change at
m/5that really pays that key parses as change (measured). Where change may go is left to [security] Check change derivation paths against the inputs #1073.Screenshots
Three new screens. Each ends the flow with "Discard transaction".
PSBTInputOwnershipContradictionView(Dire Warning)PSBTUnsupportedDerivationPathView(Warning)PSBTUnsupportedScriptPathView(Warning, titled with the existing translated string "Not Yet Implemented")Testing
pytest: 347 pass, with 12 new parser tests and 3 new flow tests. One existing test changes its expectation:test_a_psbt_with_no_utxos_is_rejected_rather_than_crashingkeeps the inputs' claims and now expectsPSBTMissingInputUtxoErrorinstead ofPSBTSeedCannotSignError(the wrong-seed behavior change above).Mutations: 32 deliberate breaks of the new code, each run against the full suite. 29 make at least one test fail. The three that pass, with their measured effect:
m/5is refused instead of parsing. Left unpinned: change paths belong to the follow-up PR.Other Notes
get_input_fingerprints, which had no callers.This pull request is categorized as a:
Checklist
I ran
pytestlocallyI included screenshots of any new or modified screens
Should be part of the PR description above.
I added or updated tests
Any new or altered functionality should be covered in a unit test. Any new or updated sequences require FlowTests.
I tested this PR hands-on on the following platform(s):
I have reviewed these notes:
Thank you! Please join our Devs' Telegram group to get more involved.