Merge pull request #1060 from kdmukai/2026-10_psbt_input_claims
What changed, and why it matters
This commit hardens SeedSigner's PSBT (Bitcoin transaction) parser so it no longer trusts a coordinator's claim that an input belongs to your seed. Before, the device only checked that your seed could derive the claimed key. Now it also rebuilds the input's actual locking script and verifies your key is really used there. This closes a path where a malicious or compromised coordinator could trick a user into signing a transaction by attaching one of the user's real keys to someone else's input, potentially making a spend look like self-spend or change. The patch also adds handling for unsupported derivation paths, taproot script-path spends, and a 'held findings' system so the most serious problem is reported first.
Reviewers should confirm that _input_spends_with_key covers all supported policy types and that no code path can bypass the new check. The multisig branch relies on _verify_input_scripts already tying the witness/redeem script to the scriptPubKey; verify that invariant holds. Also check that the held-finding ordering cannot be manipulated by an attacker to suppress a more serious finding, and that the new UI screens correctly block continuation.
Security signals we found
New attack-level exception: PSBTInputOwnershipContradictionError when an input claims the seed's key but the committed script does not use it
Input ownership now verified by rebuilding the scriptPubKey from the claimed key rather than trusting PSBT bip32 derivations
Taproot key-path spends verified by re-applying the merkle-root tweak to the internal key and comparing to the committed output
Unsupported derivation paths (master key, one-level input paths) now refused with PSBTUnsupportedDerivationPathError
Taproot script-path-only inputs now refused with PSBTUnsupportedScriptPathError
Held-finding mechanism ensures more serious output-side attacks are reported before milder input-side issues
Tests explicitly demonstrate a 'true claim planted on another party's input' being rejected
Evidence from the diff
The change moves and expands input-derivation verification from _verify_claimed_derivation_paths into _parse_inputs. For each input, it re-derives the seed’s claimed keys, then checks them against the committed scriptPubKey via a new _input_spends_with_key helper. For single-sig it rebuilds the scriptPubKey from the public key; for taproot it applies the merkle-root tweak; for multisig it checks the supplied witness/redeem script. A true claim on an input whose script does not use the key now raises PSBTInputOwnershipContradictionError (attack level). Unsupported master-key / one-level derivation paths and script-path-only taproot inputs are held as milder findings. Output verification is refactored to hold surplus-derivation findings rather than abort immediately, and the parser now reports the most serious finding first. Tests cover planted true claims on foreign inputs, decoy multisig entries, key-path taproot with script trees, and script-path-only inputs.
Changed components
src/seedsigner/models/psbt_parser.pysrc/seedsigner/views/psbt_views.pytests/test_psbt_parser.pytests/test_flows_psbt.pytests/psbt_testing_util.pytests/screenshot_generator/generator.pyInspect captured patch +990 / −140
### src/seedsigner/models/psbt_parser.py
@@ -53,7 +53,7 @@ class PSBTInputOwnershipClaimError(PSBTVerificationError):
The same type of false claim as the output case above, but a forged input claim simply
renders the psbt unsignable (embit re-derives the real key and will refuse to sign on
- a mismatch) so there's no point in continuing.
+ a mismatch).
"""
pass
@@ -109,6 +109,17 @@ class PSBTOutputOwnershipContradictionError(PSBTVerificationError):
pass
+class PSBTInputOwnershipContradictionError(PSBTVerificationError):
+ """
+ The psbt's account of which keys control an input contradicts the script that input
+ commits to. It claims one of this seed's keys on the input. Our seed really does
+ derive that key, but the committed script does not use it.
+
+ We treat this deception as an attack.
+ """
+ pass
+
+
class PSBTInputAmountVerificationError(PSBTVerificationError):
"""
An input's declared amount is unproven or false, so the fee displayed cannot be trusted.
@@ -179,6 +190,30 @@ class PSBTExtraneousInputScriptError(PSBTVerificationError):
pass
+class PSBTUnsupportedDerivationPathError(PSBTVerificationError):
+ """
+ An input or output claims one of this seed's keys at a derivation path too short for
+ any wallet to use:
+ * the empty path, which is the master key itself. That key is a derivation root
+ rather than a key any wallet spends from or receives at.
+ * on an input, a path of one level, too short to hold both a branch and an
+ address index.
+
+ We don't try to decide whether this is an attack or a mistake.
+ """
+ pass
+
+
+class PSBTUnsupportedScriptPathError(PSBTVerificationError):
+ """
+ This seed can sign an input only through a taproot script path spend, because the
+ keys of ours that the input claims are keys in its script tree leaves.
+
+ Script path spends are not yet supported.
+ """
+ pass
+
+
class PSBTSeedCannotSignError(PSBTVerificationError):
"""
The selected seed holds no key that could sign any input.
@@ -276,11 +311,17 @@ def __init__(self, p: PSBT, seed: Seed, network: str = SettingsConstants.MAINNET
# Contains one entry per input in psbt.inputs and per output in psbt.outputs. Each
# entry lists every derivation path the seed genuinely owns there, in the order
- # the psbt lists them. An input or output that does not claim any of our keys
- # gets an empty list.
+ # the psbt lists them. On an input, the key at each listed path is also one the
+ # input's committed script spends with. An input or output that does not claim
+ # any of our keys gets an empty list, as does an input carrying a held finding.
self.verified_input_derivation_paths: List[List[DerivationPath]] = []
self.verified_output_derivation_paths: List[List[DerivationPath]] = []
+ # The findings held until the outputs have been read, in the order they were
+ # found, and the index of each output that carries one.
+ self.held_findings: List[PSBTVerificationError] = []
+ self.held_output_indices: List[int] = []
+
self.root = None
if self.seed is not None:
@@ -321,21 +362,19 @@ def parse(self):
1. _fill_missing_fingerprints: backfills all-zero fingerprints, but only where
the seed provably derives the key.
- 2. _verify_claimed_derivation_paths: each input and output that claims to be
- controlled by the seed declares a derivation path that must be verified.
+ 2. _verify_claimed_output_derivation_paths: each output that claims to pay the
+ seed declares a derivation path that must be verified.
- 3. _reject_if_seed_cannot_sign: rejects the psbt if none of the inputs can be
- signed by the seed. A mismatch rather than an attack, caught here so the flow
- can say so before showing a transaction.
-
- 4. _verify_input_amounts_and_scripts: verifies each input's claimed amount, then
+ 3. _verify_input_amounts_and_scripts: verifies each input's claimed amount, then
totals them as verified_input_amount. Each input must also supply every
script it commits to and no others.
- 5. _parse_inputs: every input must resolve to the same policy otherwise a
- RuntimeError is raised (TODO: replace the RuntimeError with a
- PSBTVerificationError subclass so the View can deliberately catch this
- scenario and route accordingly).
+ 4. _parse_inputs: determines which inputs this seed can sign, and the wallet
+ policy. An input's claims on this seed are verified. Each verified claim must
+ also be a key that the input's committed script uses. Every input must
+ resolve to the same policy otherwise a RuntimeError is raised (TODO: replace
+ the RuntimeError with a PSBTVerificationError subclass so the View can
+ deliberately catch this scenario and route accordingly).
A policy is one of:
- single-sig: the script type alone. Says nothing about keys.
@@ -347,6 +386,10 @@ def parse(self):
policy with no cosigner information pass as a match between inputs.
Outputs deliberately compare shape alone; see _is_change_candidate.
+ 5. _reject_if_seed_cannot_sign: rejects the psbt if none of the inputs can be
+ signed by the seed. A mismatch rather than an attack, caught here so the flow
+ can say so before showing a transaction.
+
6. _parse_outputs: organizes the output data (amounts, destination_addresses,
etc.) and verifies the ownership of the outputs that come back to this seed
via:
@@ -358,6 +401,13 @@ def parse(self):
our seed provably owns. Also rejects a psbt whose outputs spend more than its
inputs bring in.
+ Held findings:
+ The parse reports the most serious problem it finds. A finding we treat as an
+ attack stops the parse at the step that finds it, since nothing found later can
+ outrank it. Parsing may uncover other milder findings along the way. Those are
+ held aside while the remaining checks run. A held finding is raised only if those
+ remaining checks find nothing more serious.
+
Optimization via child_key_derivation_cache:
Parsing traverses a derivation path down to an individual address one level at a
time, over and over, and where that traversal begins depends on the wallet.
@@ -393,10 +443,9 @@ def parse(self):
# Try to fix missing fingerprints before parsing
self._fill_missing_fingerprints(child_key_derivation_cache)
- # Work out what this seed actually owns before anything below reads the psbt's
- # claims about it.
- self._verify_claimed_derivation_paths(child_key_derivation_cache)
- self._reject_if_seed_cannot_sign()
+ # Work out which outputs this seed actually owns before anything below reads the
+ # psbt's claims about them.
+ self._verify_claimed_output_derivation_paths(child_key_derivation_cache)
# Single source of truth for input amounts: each is verified before it is totaled
self._verify_input_amounts_and_scripts()
@@ -405,10 +454,17 @@ def parse(self):
if rt == False:
return False
+ self._reject_if_seed_cannot_sign()
+
rt = self._parse_outputs(child_key_derivation_cache)
if rt == False:
return False
+ if self.held_findings:
+ # The checks to this point did not raise any attack-level exceptions, but a
+ # milder finding was held. The psbt is still rejected.
+ raise self.held_findings[0]
+
# Every total is known now, so settle this once rather than per view.
self.is_high_fee = self.has_high_fee()
@@ -513,11 +569,40 @@ def _verify_input_amounts_and_scripts(self):
def _parse_inputs(self, child_key_derivation_cache: dict):
"""
- Determines the wallet policy. Every input must resolve to the same policy,
+ Verifies each input's claims on this seed and determines the wallet policy.
+ Perceived attacks are raised immediately. Milder errors are held, and processing
+ of the inputs continues uninterrupted. Every input must resolve to the same policy,
otherwise a RuntimeError is raised.
+
+ First we re-derive each key the input claims for our seed, which confirms that the
+ key is ours. But the script an input commits to is what decides who can spend it;
+ the coordinator could attach our key to an input that someone else owns. So we
+ then confirm that the committed script does indeed use our key.
+
+ We need to be certain which inputs are ours because they determine what a valid
+ change output should look like.
+
+ Holds:
+ * PSBTInputOwnershipClaimError: An input carries a false claim on this seed.
+ * PSBTMixedDerivationPathTypesError: An input has entries in both derivation
+ path maps.
+ * PSBTUnsupportedDerivationPathError: An input claims one of our keys at a
+ derivation path too short for any wallet to use.
+ * PSBTUnsupportedScriptPathError: This seed can sign an input only through a
+ taproot script path spend.
"""
self.num_inputs = len(self.psbt.inputs)
+ self.verified_input_derivation_paths = []
for inp in self.psbt.inputs:
+ # Verify every entry on this input that claims our fingerprint
+ try:
+ verified_derivation_paths = PSBTParser._get_seed_derivation_paths(inp, self.root, child_key_derivation_cache)
+ except (PSBTInputOwnershipClaimError, PSBTMixedDerivationPathTypesError, PSBTUnsupportedDerivationPathError) as e:
+ # Held rather than raised, and this input is left with no verified
+ # derivation paths.
+ self.held_findings.append(e)
+ verified_derivation_paths = []
+
script_pubkey = inp.script_pubkey
inp_policy = PSBTParser._get_policy(inp, script_pubkey, self.psbt.xpubs, child_key_derivation_cache)
@@ -531,6 +616,63 @@ def _parse_inputs(self, child_key_derivation_cache: dict):
# which is allowed by BIP-174 and BIP-78.
raise RuntimeError("Mixed inputs in the transaction")
+ # Now check each verified claim against the input's committed script. We read
+ # the entries from the input's own maps so that each taproot entry's leaf
+ # hashes come with it.
+ script_committed_derivation_paths = []
+ has_leaf_key_claim = False
+
+ for public_key, derivation_path_obj in inp.bip32_derivations.items():
+ if derivation_path_obj not in verified_derivation_paths:
+ # We check only the claims on our seed that verified above
+ continue
+
+ seed_public_key = PSBTParser._derive_with_cache_via_derivation_path(self.root, derivation_path_obj, child_key_derivation_cache).get_public_key()
+ if not PSBTParser._input_spends_with_key(inp, inp_policy, script_pubkey, seed_public_key):
+ # The psbt said this input is controlled by our key at that path, but
+ # the input's committed script does not use that key. We treat this
+ # deception as an attack.
+ raise PSBTInputOwnershipContradictionError(f"Input claims this seed at {bip32.path_to_str(derivation_path_obj.derivation)} but its committed script does not use that key")
+
+ script_committed_derivation_paths.append(derivation_path_obj)
+
+ for public_key, (leaf_hashes, derivation_path_obj) in inp.taproot_bip32_derivations.items():
+ if derivation_path_obj not in verified_derivation_paths:
+ # We check only the claims on our seed that verified above
+ continue
+
+ seed_public_key = PSBTParser._derive_with_cache_via_derivation_path(self.root, derivation_path_obj, child_key_derivation_cache).get_public_key()
+ if PSBTParser._input_spends_with_key(inp, inp_policy, script_pubkey, seed_public_key):
+ script_committed_derivation_paths.append(derivation_path_obj)
+
+ elif leaf_hashes:
+ # This entry lists the script tree leaves its key appears in. Signing
+ # with a key in a leaf takes a script path spend, which we do not
+ # support yet, so this entry is dropped.
+ has_leaf_key_claim = True
+
+ elif inp_policy["type"] == "p2tr" and inp.taproot_merkle_root is None:
+ # The psbt claims our key as this input's internal key. The input may
+ # commit to that key tweaked by a script tree, but the psbt did not
+ # supply the tree's merkle root, so we cannot rebuild the tweak. An
+ # omitted optional field is not a contradiction, so this entry is
+ # dropped.
+ pass
+
+ else:
+ # The psbt said this input is controlled by our key at that path, but
+ # the input's committed script does not use that key. We treat this
+ # deception as an attack.
+ raise PSBTInputOwnershipContradictionError(f"Input claims this seed at {bip32.path_to_str(derivation_path_obj.derivation)} but its committed script does not use that key")
+
+ if script_committed_derivation_paths == [] and has_leaf_key_claim:
+ # None of our claims on this input passed. At least one of them is a key
+ # in a script tree leaf, so this seed could only sign the input through a
+ # script path spend. Held rather than raised.
+ self.held_findings.append(PSBTUnsupportedScriptPathError("Input can only be signed through a taproot script path spend"))
+
+ self.verified_input_derivation_paths.append(script_committed_derivation_paths)
+
@staticmethod
def _verify_input_scripts(inp: InputScope, script_pubkey: script.Script):
@@ -614,6 +756,57 @@ def _verify_input_scripts(inp: InputScope, script_pubkey: script.Script):
raise PSBTExtraneousInputScriptError("Input supplied a witness script its scriptPubKey does not commit to")
+ @staticmethod
+ def _input_spends_with_key(inp: InputScope, inp_policy: dict, script_pubkey: script.Script, public_key: PublicKey) -> bool:
+ """
+ Answers whether public_key is one of the keys that the input actually spends
+ with.
+
+ Single sig: rebuild the scriptPubKey from the key and compare it to the input's
+ committed scriptPubKey.
+
+ Taproot: a key path spend uses the internal key tweaked by the input's merkle root
+ (an empty one when the psbt supplies none). That is the same tweak embit signs
+ with, so we rebuild the scriptPubKey from the key tweaked that way. A key in a
+ script tree leaf rebuilds some other scriptPubKey, so it gets False here.
+
+ Multisig: look for the key among the pubkeys in the supplied script.
+ _verify_input_scripts has already tied that script to the scriptPubKey, directly
+ for p2wsh and legacy p2sh, and through the redeem script for nested segwit. So its
+ pubkeys are the ones the input really spends with.
+ """
+ policy_type = inp_policy["type"]
+
+ if policy_type == "p2tr":
+ tweaked_public_key = public_key.taproot_tweak(inp.taproot_merkle_root or b"")
+ OP_1 = b"\x51" # segwit version byte
+ OP_PUSHBYTES_32 = b"\x20"
+ return OP_1 + OP_PUSHBYTES_32 + tweaked_public_key.xonly() == script_pubkey.data
+
+ if policy_type in ("p2pkh", "p2sh-p2wpkh", "p2wpkh"):
+ return PSBTParser._build_singlesig_script(policy_type, public_key).data == script_pubkey.data
+
+ if policy_type in ("p2wsh", "p2sh-p2wsh"):
+ multisig_script = inp.witness_script
+ elif policy_type == "p2sh":
+ multisig_script = inp.redeem_script
+ else:
+ # Safety catch-all: any new script types will need explicit handling
+ # above. Note that embit reports unrecognized script types as `None`,
+ # which is also caught here.
+ raise RuntimeError(f"Unsupported policy type: {policy_type}")
+
+ return PSBTParser._multisig_script_contains_key(multisig_script, public_key)
+
+
+ def _hold_output_finding(self, output_index: int, finding: PSBTVerificationError):
+ """
+ Holds a finding along with the index of the output that carries it.
+ """
+ self.held_findings.append(finding)
+ self.held_output_indices.append(output_index)
+
+
def _parse_outputs(self, child_key_derivation_cache: dict):
"""
Sorts each output into change coming back to this seed, an external spend, or
@@ -623,6 +816,13 @@ def _parse_outputs(self, child_key_derivation_cache: dict):
Most of the work here is sorting through the psbt's claims about which, if any,
outputs are paying a key that can be derived from our seed, and then doing all
possible independent verifications for the given output data.
+
+ Perceived attacks are raised immediately. Milder errors are held, and processing
+ of the outputs continues uninterrupted.
+
+ Holds:
+ * PSBTSurplusDerivationPathsError: An output claims more derivation path entries
+ than it can use.
"""
"""********************* How output ownership is determined *********************
@@ -687,8 +887,9 @@ def _parse_outputs(self, child_key_derivation_cache: dict):
# Is this output change? If this output's policy is superficially similar to
# the spending wallet's policy (e.g. they're both 2-of-3 p2wsh), then it's a
- # candidate for being change.
- if self._is_change_candidate(out, out_policy):
+ # candidate for being change. An output carrying a held finding is counted as
+ # a spend instead.
+ if i not in self.held_output_indices and self._is_change_candidate(out, out_policy):
# Begin the extensive work to fully verify whether this output is indeed
# change.
@@ -722,10 +923,10 @@ def _parse_outputs(self, child_key_derivation_cache: dict):
# Sanity check; a single sig output shouldn't have multiple derivation
# paths.
if len(out.bip32_derivations) > 1:
- raise PSBTSurplusDerivationPathsError("Single-key output claims more than one derivation path")
+ self._hold_output_finding(i, PSBTSurplusDerivationPathsError("Single-key output claims more than one derivation path"))
# Rebuild the scriptPubKey from the key at the claimed derivation path
- if len(out.bip32_derivations.values()) == 1:
+ elif len(out.bip32_derivations.values()) == 1:
singlesig_derivation_path = list(out.bip32_derivations.values())[0]
seed_public_key = PSBTParser._derive_with_cache_via_derivation_path(self.root, singlesig_derivation_path, child_key_derivation_cache).get_public_key()
rebuilt_script_pubkey = PSBTParser._build_singlesig_script(self.policy["type"], seed_public_key)
@@ -749,9 +950,9 @@ def _parse_outputs(self, child_key_derivation_cache: dict):
# internal key claims:
internal_key_claims = sum(1 for leaf_hashes, _ in taproot_entries if not leaf_hashes)
if internal_key_claims > 1:
- raise PSBTSurplusDerivationPathsError("Taproot output claims more than one internal key")
+ self._hold_output_finding(i, PSBTSurplusDerivationPathsError("Taproot output claims more than one internal key"))
- if len(taproot_entries) == 1 and internal_key_claims == 1:
+ elif len(taproot_entries) == 1 and internal_key_claims == 1:
leaf_hashes, singlesig_derivation_path = taproot_entries[0]
seed_public_key = PSBTParser._derive_with_cache_via_derivation_path(self.root, singlesig_derivation_path, child_key_derivation_cache).get_public_key()
rebuilt_script_pubkey = PSBTParser._build_singlesig_script(self.policy["type"], seed_public_key)
@@ -774,7 +975,12 @@ def _parse_outputs(self, child_key_derivation_cache: dict):
verified_derivation_paths = self.verified_output_derivation_paths[i]
- if rebuilt_script_pubkey.data == vout[i].script_pubkey.data:
+ if i in self.held_output_indices:
+ # The surplus check above held a finding, so we cannot tell which of
+ # this output's entries describes it. It is counted as a spend.
+ pass
+
+ elif rebuilt_script_pubkey.data == vout[i].script_pubkey.data:
# The scriptPubKey we created using our own seed matched what this
# output is actually committing to.
@@ -786,7 +992,7 @@ def _parse_outputs(self, child_key_derivation_cache: dict):
if verified_derivation_paths != [singlesig_derivation_path]:
# Shouldn't be able to reach here: the surplus check above
- # allows only one entry, and the ownership scan refuses a
+ # allows only one entry, and the ownership scan sets aside a
# scope populating both derivation path maps, so the scan can
# only have verified this same path.
raise RuntimeError(f"Output {i} verified at a path it does not pay")
@@ -839,28 +1045,31 @@ def _parse_outputs(self, child_key_derivation_cache: dict):
# before this so they can be surfaced first.
if len(out.bip32_derivations) > self.policy["n"]:
# We don't try to decide if this is an attack or a
- # mistake. We just abort the parse.
- raise PSBTSurplusDerivationPathsError("Multisig output claims more derivation paths than its script has keys")
-
- # We now know that our key is in the committed script; this
- # output does pay to a multisig that our seed is part of. But
- # note that we do not know yet if this is truly change coming
- # back to our wallet or if it is paying out to a different
- # multisig that happens to include our seed. Final change
- # verification can only happen if and when the user loads
- # their "known-good" multisig descriptor.
- is_presumed_change = True
-
- # One thing we can rule out now: if the psbt supplied global
- # xpubs (see _get_cosigners), we can compare this output's
- # cosigners to the inputs' cosigners. Real change should have
- # the same cosigners; if this output's cosigners differ or
- # fail to resolve at all, we classify this output as NOT
- # change.
- input_cosigners = self.policy.get("cosigners")
- output_cosigners = out_policy.get("cosigners")
- if input_cosigners is not None and input_cosigners != output_cosigners:
- is_presumed_change = False
+ # mistake. The finding is held and the output is counted
+ # as a spend.
+ self._hold_output_finding(i, PSBTSurplusDerivationPathsError("Multisig output claims more derivation paths than its script has keys"))
+
+ else:
+ # We now know that our key is in the committed script;
+ # this output does pay to a multisig that our seed is part
+ # of. But note that we do not know yet if this is truly
+ # change coming back to our wallet or if it is paying out
+ # to a different multisig that happens to include our
+ # seed. Final change verification can only happen if and
+ # when the user loads their "known-good" multisig
+ # descriptor.
+ is_presumed_change = True
+
+ # One thing we can rule out now: if the psbt supplied
+ # global xpubs (see _get_cosigners), we can compare this
+ # output's cosigners to the inputs' cosigners. Real change
+ # should have the same cosigners; if this output's
+ # cosigners differ or fail to resolve at all, we classify
+ # this output as NOT change.
+ input_cosigners = self.policy.get("cosigners")
+ output_cosigners = out_policy.get("cosigners")
+ if input_cosigners is not None and input_cosigners != output_cosigners:
+ is_presumed_change = False
elif verified_derivation_paths != [] and self.policy["type"] != "p2tr":
# The psbt claims one of this seed's keys on this output, yet the
@@ -1311,28 +1520,6 @@ def _get_cosigners(pubkeys, derivations, xpubs, child_key_derivation_cache: dict
return sorted(cosigners)
- @staticmethod
- def get_input_fingerprints(psbt: PSBT) -> List[str]:
- """
- Exctracts the fingerprint from each input's derivation path.
-
- TODO: It's unclear if these derivations/fingerprints would ever be missing.
- Research on PSBT standard and known wallet coordinator implementations
- needed.
- """
- fingerprints = set()
- for input in psbt.inputs:
- for pub, derivation_path in input.bip32_derivations.items():
- fingerprints.add(hexlify(derivation_path.fingerprint).decode())
-
- for pub, (leaf_hashes, derivation_path) in input.taproot_bip32_derivations.items():
- # TODO: Support spends from leaves; depends on support in embit
- if len(leaf_hashes) > 0:
- raise Exception("Signing script path spends is not yet implemented")
- fingerprints.add(hexlify(derivation_path.fingerprint).decode())
- return list(fingerprints)
-
-
@staticmethod
def has_matching_input_fingerprint(psbt: PSBT, seed: Seed, network: str = SettingsConstants.MAINNET):
"""
@@ -1441,9 +1628,12 @@ def _get_seed_derivation_paths(scope: InputScope | OutputScope, root: bip32.HDKe
derives from our seed. What those entries mean for the psbt is determined
elsewhere.
- The path itself is still whatever the psbt supplied: it can be any length or
- shape, since any path that derives from the seed will pass. Whether the path is
- one the user's wallet would ever look at is a separate question.
+ The path itself is still whatever the psbt supplied, so a last check refuses one
+ too short for any wallet to use: the empty path, which is the master key itself,
+ and on an input a path of one level. Each raises
+ PSBTUnsupportedDerivationPathError. Any longer path that derives from the seed
+ passes, whatever its shape. Whether the path is one the user's wallet would ever
+ look at is a separate question.
"""
seed_fingerprint = root.my_fingerprint
verified_derivation_paths = []
@@ -1473,34 +1663,52 @@ def _check_claim(public_key: PublicKey, derivation_path_obj: DerivationPath, is_
if scope.bip32_derivations and scope.taproot_bip32_derivations:
raise PSBTMixedDerivationPathTypesError("Scope declares both ecdsa and taproot derivation paths")
+ # Also checked after the loops, for the same reason
+ for verified_derivation_path in verified_derivation_paths:
+ if len(verified_derivation_path.derivation) == 0:
+ # A path with no levels is the master key itself. That key is a derivation
+ # root, never a spending key. No wallet writes an entry at that path. We
+ # refuse the psbt rather than skip the entry, on inputs and outputs alike
+ # (embit would sign an input built on it).
+ raise PSBTUnsupportedDerivationPathError("The psbt claims this seed's master key, which is not a spending key")
+
+ if len(verified_derivation_path.derivation) == 1 and isinstance(scope, InputScope):
+ # A one-level path is too short to hold both a branch and an address
+ # index. No wallet spends from a path that short.
+ raise PSBTUnsupportedDerivationPathError(f"Input claims this seed at {bip32.path_to_str(verified_derivation_path.derivation)}, a path too short for a wallet")
+
return verified_derivation_paths
- def _verify_claimed_derivation_paths(self, child_key_derivation_cache: dict):
+ def _verify_claimed_output_derivation_paths(self, child_key_derivation_cache: dict):
"""
- Verifies every derivation path entry that claims this seed's fingerprint. The
- result, stored in verified_[input|output]_derivation_paths, is the list of
- verified DerivationPath entries for each input/output scope (empty where no entry
- claimed this seed).
+ Verifies every derivation path entry on an output that claims this seed's
+ fingerprint. The result, stored in verified_output_derivation_paths, is the list
+ of verified DerivationPath entries for each output (empty where no entry claimed
+ this seed).
The coordinator-supplied fingerprints cannot be trusted as-is. We must derive and
verify the ownership of each one that claims to belong to this seed.
- Outputs are verified before inputs; a false claim on an output (e.g. fake-change
- forgery) is likely an attack whereas a false claim on an input is merely
- unsignable.
+ Outputs are verified before the inputs' claims are, later in the parse; a false
+ claim on an output (e.g. fake-change forgery) is likely an attack whereas a false
+ claim on an input is merely unsignable.
- Raises PSBT[Output|Input]OwnershipClaimError on the first false claim detected.
- """
- self.verified_output_derivation_paths = [
- PSBTParser._get_seed_derivation_paths(out, self.root, child_key_derivation_cache)
- for out in self.psbt.outputs
- ]
+ Raises PSBTOutputOwnershipClaimError on the first false claim detected.
- self.verified_input_derivation_paths = [
- PSBTParser._get_seed_derivation_paths(inp, self.root, child_key_derivation_cache)
- for inp in self.psbt.inputs
- ]
+ Holds:
+ * PSBTMixedDerivationPathTypesError: An output has entries in both derivation
+ path maps.
+ * PSBTUnsupportedDerivationPathError: An output claims the master key itself.
+ """
+ self.verified_output_derivation_paths = []
+ for i, out in enumerate(self.psbt.outputs):
+ try:
+ verified_derivation_paths = PSBTParser._get_seed_derivation_paths(out, self.root, child_key_derivation_cache)
+ except (PSBTMixedDerivationPathTypesError, PSBTUnsupportedDerivationPathError) as e:
+ self._hold_output_finding(i, e)
+ verified_derivation_paths = []
+ self.verified_output_derivation_paths.append(verified_derivation_paths)
def _reject_if_seed_cannot_sign(self):
@@ -1513,21 +1721,21 @@ def _reject_if_seed_cannot_sign(self):
(embit's sign_with is marginally more permissive: it also signs an input whose
script names the master key directly, with no derivation. That runs against how HD
wallets are built. The master key is a derivation root, not a spending key, so no
- standard wallet produces such a psbt. We deliberately ignore this case.
-
- Similarly, it's not worth the effort to verify that each key is included in its
- input's script. A psbt that excludes a key in that way would be nonsensical but
- harmless: the excluded key cannot spend the input, so nothing of this seed's is
- at risk.)
+ standard wallet produces such a psbt. We deliberately ignore this case.)
"""
- # An input claims a key at a derivation path and _verify_claimed_derivation_paths
- # proved the seed derives it (single-sig: one such key; multisig: one per
- # cosigner, ours among them). One verified input path is enough for the psbt to
- # be signable.
+ # An input claims a key at a derivation path. _parse_inputs proved that the seed
+ # derives that key and that the input's committed script uses it (single-sig: one
+ # such key; multisig: one per cosigner, ours among them). One verified input path
+ # is enough for the psbt to be signable.
for verified_derivation_paths in self.verified_input_derivation_paths:
if len(verified_derivation_paths) > 0:
return
+ if self.held_findings:
+ # The held finding is the one to report rather than "wrong seed". parse()
+ # raises it once the outputs have been read.
+ return
+
# There's nothing for this seed to sign
raise PSBTSeedCannotSignError()
### src/seedsigner/views/psbt_views.py
@@ -4,11 +4,12 @@
from seedsigner.models.psbt_parser import (PSBTExtraneousInputScriptError,
PSBTInputAmountVerificationError, PSBTInputOwnershipClaimError,
- PSBTInputScriptMismatchError, PSBTMalformedOpReturnError,
- PSBTMissingInputScriptError, PSBTMissingInputUtxoError,
+ PSBTInputOwnershipContradictionError, PSBTInputScriptMismatchError,
+ PSBTMalformedOpReturnError, PSBTMissingInputScriptError, PSBTMissingInputUtxoError,
PSBTMixedDerivationPathTypesError, PSBTNegativeFeeError, PSBTOutputOwnershipClaimError,
PSBTOutputOwnershipContradictionError, PSBTParser, PSBTSeedCannotSignError,
- PSBTSurplusDerivationPathsError)
+ PSBTSurplusDerivationPathsError, PSBTUnsupportedDerivationPathError,
+ PSBTUnsupportedScriptPathError)
from seedsigner.models.settings import SettingsConstants
from seedsigner.gui.components import FontAwesomeIconConstants, GUIConstants, SeedSignerIconConstants
from seedsigner.gui.screens.screen import (RET_CODE__BACK_BUTTON, ButtonListScreen, ButtonOption, LargeIconStatusScreen, WarningScreen, DireWarningScreen, QRDisplayScreen)
@@ -134,6 +135,10 @@ def __init__(self):
self.set_redirect(Destination(PSBTMalformedOpReturnView, clear_history=True))
return
+ except PSBTUnsupportedDerivationPathError:
+ self.set_redirect(Destination(PSBTUnsupportedDerivationPathView, clear_history=True))
+ return
+
except PSBTMissingInputScriptError:
self.set_redirect(Destination(PSBTMissingInputScriptView, clear_history=True))
return
@@ -150,6 +155,14 @@ def __init__(self):
self.set_redirect(Destination(PSBTOutputOwnershipContradictionView, clear_history=True))
return
+ except PSBTInputOwnershipContradictionError:
+ self.set_redirect(Destination(PSBTInputOwnershipContradictionView, clear_history=True))
+ return
+
+ except PSBTUnsupportedScriptPathError:
+ self.set_redirect(Destination(PSBTUnsupportedScriptPathView, clear_history=True))
+ return
+
except PSBTNegativeFeeError:
self.set_redirect(Destination(PSBTNegativeFeeView, clear_history=True))
return
@@ -439,8 +452,7 @@ def run(self):
verified_derivation_path = change_data.get("verified_derivation_path")
is_change_derivation_path = PSBTParser.is_change_branch(verified_derivation_path)
- # TODO: Refuse a path too short to carry a branch and an address index; until then
- # this can raise on a malformed psbt.
+ # TODO: Refuse a path too short to carry a branch and an address index
derivation_path_addr_index = verified_derivation_path[-1]
if is_change_derivation_path:
@@ -690,6 +702,36 @@ def run(self):
+class PSBTUnsupportedDerivationPathView(View):
+ """
+ Reached when a psbt claims one of this seed's keys at a derivation path too short for
+ any wallet to use, such as the seed's master key itself (see
+ PSBTUnsupportedDerivationPathError).
+
+ We do not try to decide whether this is an attack or a mistake; no standard wallet
+ writes a claim at a path that short either way. We do not allow the user to continue,
+ but only give this the "Warning" level.
+ """
+ DISCARD = ButtonOption("Discard transaction")
+
+ def run(self):
+ self.run_screen(
+ WarningScreen,
+ title=_("Transaction Problem"),
+ status_headline=None,
+ # TRANSLATOR_NOTE: The transaction/psbt has an error but does not seem to be malicious.
+ text=_("This transaction uses a key of yours that this device will not sign with."),
+ button_data=[self.DISCARD],
+ show_back_button=False,
+ )
+
+ # We're done with this PSBT. Route back to MainMenuView, which clears all
+ # ephemeral data (except in-memory seeds).
+ # Set clear_history to disable returning via BACK button.
+ return Destination(MainMenuView, clear_history=True)
+
+
+
class PSBTOutputOwnershipContradictionView(View):
"""
Reached when the psbt's account of who an output pays contradicts the script that
@@ -718,6 +760,34 @@ def run(self):
+class PSBTInputOwnershipContradictionView(View):
+ """
+ Reached when the psbt claims one of this seed's keys on an input whose committed
+ script does not use that key (see PSBTInputOwnershipContradictionError).
+
+ We view this as an attack. We do not allow the user to continue and give this the
+ "Dire Warning" level.
+ """
+ DISCARD = ButtonOption("Discard transaction")
+
+ def run(self):
+ self.run_screen(
+ DireWarningScreen,
+ title=_("Suspicious Transaction"),
+ status_headline=_("Likely an Attack!"),
+ # TRANSLATOR_NOTE: The transaction/psbt contains a deception that we consider an attack.
+ text=_("This transaction misrepresents which keys own an input."),
+ button_data=[self.DISCARD],
+ show_back_button=False,
+ )
+
+ # We're done with this PSBT. Route back to MainMenuView, which clears all
+ # ephemeral data (except in-memory seeds).
+ # Set clear_history to disable returning via BACK button.
+ return Destination(MainMenuView, clear_history=True)
+
+
+
class PSBTNegativeFeeView(View):
"""
Reached when a psbt's outputs spend more than its inputs bring in (see
@@ -828,6 +898,33 @@ def run(self):
+class PSBTUnsupportedScriptPathView(View):
+ """
+ Reached when this seed can sign an input only through a taproot script path spend
+ (see PSBTUnsupportedScriptPathError).
+
+ Script path spends are not yet supported, so this seed cannot sign the input. We do
+ not allow the user to continue, but only give this the "Warning" level.
+ """
+ DISCARD = ButtonOption("Discard transaction")
+
+ def run(self):
+ self.run_screen(
+ WarningScreen,
+ title=_("Not Yet Implemented"),
+ status_headline=None,
+ text=_("This transaction needs a taproot script path signature."),
+ button_data=[self.DISCARD],
+ show_back_button=False,
+ )
+
+ # We're done with this PSBT. Route back to MainMenuView, which clears all
+ # ephemeral data (except in-memory seeds).
+ # Set clear_history to disable returning via BACK button.
+ return Destination(MainMenuView, clear_history=True)
+
+
+
class PSBTAddressVerificationFailedView(View):
"""
Reached from PSBTChangeDetailsView when a multisig change or self-transfer output
### tests/psbt_testing_util.py
@@ -258,6 +258,22 @@ def claim_seed_owns_key(scope: InputScope | OutputScope, claimed_derivation_path
scope.bip32_derivations[public_key] = derivation_path
+def set_input_locking_script(inp: InputScope, script_pubkey: Script):
+ """
+ Changes the locking script (the scriptPubKey) of the coin a segwit input spends.
+ Lets a test make the input commit to a different script or key.
+
+ Edits the witness_utxo and drops the non_witness_utxo. The non_witness_utxo is the
+ previous transaction, which still pays the old scriptPubKey, so it would contradict
+ the edit. Editing it to match is not an option either: that changes the txid it
+ hashes to, so it would no longer be the transaction this input claims to spend. The
+ witness_utxo alone describes a segwit input's coin, which is what a coordinator
+ would normally send anyway.
+ """
+ inp.witness_utxo.script_pubkey = script_pubkey
+ inp.non_witness_utxo = None
+
+
def op_return_script(payload: bytes) -> Script:
"""
Build an OP_RETURN scriptPubKey carrying `payload`, using the minimal push encoding
### tests/screenshot_generator/generator.py
@@ -454,10 +454,13 @@ def mock_version_to_most_recent_release():
ScreenshotConfig(psbt_views.PSBTSurplusDerivationPathsView),
ScreenshotConfig(psbt_views.PSBTMixedDerivationPathTypesView),
ScreenshotConfig(psbt_views.PSBTMalformedOpReturnView),
+ ScreenshotConfig(psbt_views.PSBTUnsupportedDerivationPathView),
ScreenshotConfig(psbt_views.PSBTOutputOwnershipContradictionView),
+ ScreenshotConfig(psbt_views.PSBTInputOwnershipContradictionView),
ScreenshotConfig(psbt_views.PSBTMissingInputScriptView),
ScreenshotConfig(psbt_views.PSBTInputScriptMismatchView),
ScreenshotConfig(psbt_views.PSBTExtraneousInputScriptView),
+ ScreenshotConfig(psbt_views.PSBTUnsupportedScriptPathView),
ScreenshotConfig(psbt_views.PSBTAddressVerificationFailedView, dict(is_change=True), screenshot_name="PSBTAddressVerificationFailedView_multisig_change"),
ScreenshotConfig(psbt_views.PSBTAddressVerificationFailedView, dict(is_change=False), screenshot_name="PSBTAddressVerificationFailedView_multisig_selftransfer"),
ScreenshotConfig(psbt_views.PSBTOutputOwnershipClaimFailedView),
### tests/test_flows_psbt.py
@@ -4,8 +4,9 @@
from embit.psbt import PSBT, DerivationPath
from base import FlowTest, FlowStep
-from psbt_testing_util import (PSBTTestData, claim_seed_owns_key, create_op_return_output,
- create_output, foreign_public_key, root_for_seed)
+from psbt_testing_util import (NUMS_INTERNAL_KEY, PSBTTestData, claim_seed_owns_key,
+ create_op_return_output, create_output, foreign_public_key, p2tr_with_script_tree,
+ root_for_seed, set_input_locking_script, tapleaf_hash)
from seedsigner.controller import Controller
from seedsigner.views.view import MainMenuView
@@ -396,6 +397,27 @@ def test_malformed_op_return_terminates_signing_flow(self):
])
+ def test_master_key_claim_terminates_signing_flow(self):
+ """
+ The psbt claims this seed on an output at a derivation path with no levels, which
+ is the seed's master key. That key is a derivation root rather than one any wallet
+ receives at. No standard wallet writes an entry at that path.
+
+ It ends the flow at its own warning before any transaction detail is rendered.
+ """
+ psbt = self._psbt_with_change()
+ claim_seed_owns_key(psbt.outputs[0], "m", root_for_seed(PSBTTestData.seed).get_public_key())
+
+ self._load_psbt_for_signing(psbt)
+
+ self.run_sequence([
+ FlowStep(psbt_views.PSBTSelectSeedView, screen_return_value=0),
+ FlowStep(psbt_views.PSBTOverviewView, is_redirect=True),
+ FlowStep(psbt_views.PSBTUnsupportedDerivationPathView, button_data_selection=psbt_views.PSBTUnsupportedDerivationPathView.DISCARD),
+ FlowStep(MainMenuView),
+ ])
+
+
def test_missing_input_script_terminates_signing_flow(self):
"""
The psbt leaves out the witness script that a p2wsh input commits to.
@@ -467,6 +489,62 @@ def test_extraneous_input_script_terminates_signing_flow(self):
])
+ def test_input_ownership_contradiction_terminates_signing_flow(self):
+ """
+ The psbt adds a second claim of ours to the user's own input, at a path whose key
+ the input's script does not use. That is framed as an attack.
+
+ The flow should stop at PSBTInputOwnershipContradictionView, before any
+ transaction detail is rendered.
+ """
+ decoy_derivation_path = "m/84h/1h/0h/0/9"
+ decoy_public_key = root_for_seed(PSBTTestData.seed).derive(decoy_derivation_path).get_public_key()
+
+ psbt = self._psbt_with_change()
+ claim_seed_owns_key(psbt.inputs[0], decoy_derivation_path, decoy_public_key)
+
+ self._load_psbt_for_signing(psbt)
+
+ self.run_sequence([
+ FlowStep(psbt_views.PSBTSelectSeedView, screen_return_value=0),
+ FlowStep(psbt_views.PSBTOverviewView, is_redirect=True),
+ FlowStep(psbt_views.PSBTInputOwnershipContradictionView, button_data_selection=psbt_views.PSBTInputOwnershipContradictionView.DISCARD),
+ FlowStep(MainMenuView),
+ ])
+
+
+ def test_unsupported_script_path_terminates_signing_flow(self):
+ """
+ The psbt's only input has our key in its taproot script tree's one leaf, behind
+ an unspendable internal key. This seed can sign it only through a script path
+ spend, which is not yet supported.
+
+ The flow should stop at PSBTUnsupportedScriptPathView, before any transaction
+ detail is rendered.
+ """
+ leaf_derivation_path = "m/86h/1h/0h/0/0"
+ leaf_public_key = root_for_seed(PSBTTestData.seed).derive(leaf_derivation_path).get_public_key()
+ merkle_root = tapleaf_hash(leaf_public_key)
+
+ psbt = PSBT.parse(a2b_base64(PSBTTestData.SINGLE_SIG_TAPROOT_1_INPUT))
+ psbt.outputs.append(create_output(PSBTTestData.SINGLE_SIG_TAPROOT_CHANGE, 10_000))
+
+ inp = psbt.inputs[0]
+ set_input_locking_script(inp, p2tr_with_script_tree(NUMS_INTERNAL_KEY, merkle_root))
+ inp.taproot_merkle_root = merkle_root
+ inp.taproot_bip32_derivations.clear()
+ claim_seed_owns_key(inp, leaf_derivation_path, leaf_public_key, is_taproot=True, leaf_hashes=[merkle_root])
+
+ self._load_psbt_for_signing(psbt)
+
+ self.run_sequence([
+ FlowStep(psbt_views.PSBTSelectSeedView, screen_return_value=0),
+ FlowStep(psbt_views.PSBTOverviewView, is_redirect=True),
+ FlowStep(psbt_views.PSBTUnsupportedScriptPathView, button_data_selection=psbt_views.PSBTUnsupportedScriptPathView.DISCARD),
+ FlowStep(MainMenuView),
+ ])
+
+
def test_wrong_seed_routes_back_to_seed_selection_flow(self):
"""
The wrong seed for a psbt redirects before any transaction detail is rendered and
### tests/test_psbt_parser.py
@@ -14,17 +14,19 @@
from seedsigner.models.psbt_parser import (OPCODES, PSBTExtraneousInputScriptError,
PSBTInputAmountVerificationError, PSBTInputOwnershipClaimError,
- PSBTInputScriptMismatchError, PSBTMalformedOpReturnError,
- PSBTMissingInputScriptError, PSBTMissingInputUtxoError,
+ PSBTInputOwnershipContradictionError, PSBTInputScriptMismatchError,
+ PSBTMalformedOpReturnError, PSBTMissingInputScriptError, PSBTMissingInputUtxoError,
PSBTMixedDerivationPathTypesError, PSBTNegativeFeeError, PSBTOutputOwnershipClaimError,
PSBTOutputOwnershipContradictionError, PSBTParser, PSBTSeedCannotSignError,
- PSBTSurplusDerivationPathsError)
+ PSBTSurplusDerivationPathsError, PSBTUnsupportedDerivationPathError,
+ PSBTUnsupportedScriptPathError)
from seedsigner.models.seed import Seed
from seedsigner.models.settings_definition import SettingsConstants
from psbt_testing_util import (NUMS_INTERNAL_KEY, PSBTTestData, claim_seed_owns_key,
create_op_return_output, create_op_return_psbt, create_output, foreign_public_key,
- op_return_script, p2tr_with_script_tree, root_for_seed, tapleaf_hash)
+ op_return_script, p2tr_with_script_tree, root_for_seed, set_input_locking_script,
+ tapleaf_hash)
@@ -274,14 +276,7 @@ def test_missing_fingerprint_handling(self):
derivation=bip32.parse_path(odd_parity_derivation_path)
))
taproot_input.taproot_internal_key = x_only_public_key
- taproot_input.witness_utxo.script_pubkey = script.p2tr(x_only_public_key)
-
- # Re-keying the input invalidates the non_witness_utxo, which still pays to the
- # original script. Editing it to match is not an option either: that changes the
- # txid it hashes to, so it would no longer be the tx this input claims to spend.
- # Drop it. Taproot is segwit, so a witness-only input is what a coordinator would
- # normally send anyway.
- taproot_input.non_witness_utxo = None
+ set_input_locking_script(taproot_input, script.p2tr(x_only_public_key))
# The zeroed-fingerprint fallback check must recognize this input as the seed's,
# even though embit's internal parity byte for the pubkey is wrong. Taproot
@@ -1343,10 +1338,7 @@ def test__parse__verified_derivation_paths_empty_for_not_owned_input(self):
foreign_input.bip32_derivations.clear()
# Alter the input so it's owned by the other party
- foreign_input.witness_utxo.script_pubkey = script.p2wpkh(foreign_public_key())
-
- # We can't let this copy's original non_witness_utxo contradict the witness_utxo we just altered.
- foreign_input.non_witness_utxo = None
+ set_input_locking_script(foreign_input, script.p2wpkh(foreign_public_key()))
psbt.inputs.append(foreign_input)
@@ -1391,11 +1383,11 @@ def test__parse__rejects_a_forged_claim_on_an_output(self):
def test__parse__forged_output_claim_outranks_forged_input_claim(self):
"""
- The scan stops at the first false claim, so scan order decides which error the
- psbt is reported with. A false output claim is the fake-change forgery and must
- be the one reported even when the same psbt also carries a false input claim --
- otherwise an attacker could plant a throwaway input claim just to be routed to
- the milder input-scope warning.
+ A false output claim is the fake-change forgery and must be the one reported even
+ when the same psbt also carries a false input claim; otherwise an attacker could
+ plant a throwaway input claim just to be routed to the milder input-scope
+ warning. The scan checks outputs first and stops at the first false output
+ claim, so the input claim is never reached.
"""
psbt = self._psbt_with_change()
claim_seed_owns_key(psbt.inputs[0], "m/84h/1h/0h/0/0", foreign_public_key())
@@ -1406,6 +1398,151 @@ def test__parse__forged_output_claim_outranks_forged_input_claim(self):
self._parse(psbt)
+ def test__parse__held_findings_wait_for_an_output_contradiction(self):
+ """
+ Each psbt below carries a finding milder than an attack, along with a change
+ output that pays our key while its entry claims a stranger's fingerprint. That
+ contradiction is only found once the outputs are read, after the milder finding.
+ So the parse should hold the milder finding, read the outputs, and report
+ PSBTOutputOwnershipContradictionError:
+ * p2wpkh input: a throwaway false claim
+ * p2wpkh input: entries in both derivation path maps
+ * p2wpkh input: a claim on this seed's master key
+ * p2tr input: our only key in a script tree leaf
+ * p2wpkh output: entries in both derivation path maps
+ * p2wpkh output: a claim on this seed's master key
+ * p2wpkh output: more derivation path entries than it can use
+ * p2tr output: more than one internal key claim
+ * p2wsh output: more derivation path entries than its script has keys
+
+ Each finding on an output is placed on a second output, listed ahead of the change.
+ """
+ def claim_a_stranger_on_the_change(psbt: PSBT):
+ """
+ Re-lists each of our entries on the change output under a stranger's
+ fingerprint, keeping its path, so the output still pays our key. Callers list
+ the change output last.
+ """
+ change_output = psbt.outputs[-1]
+ our_fingerprint = self._root().my_fingerprint
+ stranger_fingerprint = root_for_seed(PSBTTestData.recipient_seed).my_fingerprint
+
+ # Our entries in the non-taproot map
+ for public_key, derivation_path_obj in list(change_output.bip32_derivations.items()):
+ if derivation_path_obj.fingerprint == our_fingerprint:
+ change_output.bip32_derivations[public_key] = DerivationPath(stranger_fingerprint, derivation_path_obj.derivation)
+
+ # Our entries in the taproot map
+ for public_key, (leaf_hashes, derivation_path_obj) in list(change_output.taproot_bip32_derivations.items()):
+ if derivation_path_obj.fingerprint == our_fingerprint:
+ change_output.taproot_bip32_derivations[public_key] = (leaf_hashes, DerivationPath(stranger_fingerprint, derivation_path_obj.derivation))
+
+ # A true claim on a key this seed owns, for the taproot map
+ taproot_derivation_path = "m/86h/1h/0h/1/9"
+ taproot_public_key = self._root().derive(taproot_derivation_path).get_public_key()
+
+ # A true claim on a second key this seed owns, for the non-taproot map
+ decoy_derivation_path = "m/84h/1h/0h/1/9"
+ decoy_public_key = self._root().derive(decoy_derivation_path).get_public_key()
+
+ # p2wpkh input: a throwaway false claim
+ psbt = self._psbt_with_change()
+ claim_seed_owns_key(psbt.inputs[0], "m/84h/1h/0h/0/0", foreign_public_key())
+ claim_a_stranger_on_the_change(psbt)
+ with pytest.raises(PSBTOutputOwnershipContradictionError):
+ self._parse(psbt)
+
+ # p2wpkh input: entries in both derivation path maps
+ psbt = self._psbt_with_change()
+ claim_seed_owns_key(psbt.inputs[0], taproot_derivation_path, taproot_public_key, is_taproot=True)
+ claim_a_stranger_on_the_change(psbt)
+ with pytest.raises(PSBTOutputOwnershipContradictionError):
+ self._parse(psbt)
+
+ # p2wpkh input: a claim on this seed's master key
+ psbt = self._psbt_with_change()
+ claim_seed_owns_key(psbt.inputs[0], "m", self._root().get_public_key())
+ claim_a_stranger_on_the_change(psbt)
+ with pytest.raises(PSBTOutputOwnershipContradictionError):
+ self._parse(psbt)
+
+ # p2tr input: our only key in a script tree leaf
+ leaf_derivation_path = "m/86h/1h/0h/0/0"
+ leaf_public_key = self._root().derive(leaf_derivation_path).get_public_key()
+ merkle_root = tapleaf_hash(leaf_public_key)
+ psbt = self._psbt_with_change(PSBTTestData.SINGLE_SIG_TAPROOT_1_INPUT, PSBTTestData.SINGLE_SIG_TAPROOT_CHANGE)
+ set_input_locking_script(psbt.inputs[0], p2tr_with_script_tree(NUMS_INTERNAL_KEY, merkle_root))
+ psbt.inputs[0].taproot_merkle_root = merkle_root
+ psbt.inputs[0].taproot_bip32_derivations.clear()
+ claim_seed_owns_key(psbt.inputs[0], leaf_derivation_path, leaf_public_key, is_taproot=True, leaf_hashes=[merkle_root])
+ claim_a_stranger_on_the_change(psbt)
+ with pytest.raises(PSBTOutputOwnershipContradictionError):
+ self._parse(psbt)
+
+ # p2wpkh output: entries in both derivation path maps
+ psbt = self._psbt_with_change()
+ other_output = create_output(PSBTTestData.SINGLE_SIG_NATIVE_SEGWIT_CHANGE, 10_000)
+ claim_seed_owns_key(other_output, taproot_derivation_path, taproot_public_key, is_taproot=True)
+ psbt.outputs.insert(0, other_output)
+ claim_a_stranger_on_the_change(psbt)
+ with pytest.raises(PSBTOutputOwnershipContradictionError):
+ self._parse(psbt)
+
+ # p2wpkh output: a claim on this seed's master key
+ psbt = self._psbt_with_change()
+ other_output = create_output(PSBTTestData.SINGLE_SIG_NATIVE_SEGWIT_CHANGE, 10_000)
+ claim_seed_owns_key(other_output, "m", self._root().get_public_key())
+ psbt.outputs.insert(0, other_output)
+ claim_a_stranger_on_the_change(psbt)
+ with pytest.raises(PSBTOutputOwnershipContradictionError):
+ self._parse(psbt)
+
+ # p2wpkh output: more derivation path entries than it can use
+ psbt = self._psbt_with_change()
+ other_output = create_output(PSBTTestData.SINGLE_SIG_NATIVE_SEGWIT_CHANGE, 10_000)
+ claim_seed_owns_key(other_output, decoy_derivation_path, decoy_public_key)
+ psbt.outputs.insert(0, other_output)
+ claim_a_stranger_on_the_change(psbt)
+ with pytest.raises(PSBTOutputOwnershipContradictionError):
+ self._parse(psbt)
+
+ # p2tr output: more than one internal key claim
+ psbt = self._psbt_with_change(PSBTTestData.SINGLE_SIG_TAPROOT_1_INPUT, PSBTTestData.SINGLE_SIG_TAPROOT_CHANGE)
+ other_output = create_output(PSBTTestData.SINGLE_SIG_TAPROOT_CHANGE, 10_000)
+ claim_seed_owns_key(other_output, taproot_derivation_path, taproot_public_key, is_taproot=True)
+ psbt.outputs.insert(0, other_output)
+ claim_a_stranger_on_the_change(psbt)
+ with pytest.raises(PSBTOutputOwnershipContradictionError):
+ self._parse(psbt)
+
+ # p2wsh output: more derivation path entries than its script has keys
+ psbt = self._psbt_with_change(PSBTTestData.MULTISIG_NATIVE_SEGWIT_1_INPUT, PSBTTestData.MULTISIG_NATIVE_SEGWIT_CHANGE)
+ other_output = deepcopy(psbt.outputs[0])
+ claim_seed_owns_key(other_output, "m/48h/1h/0h/2h/1/9", foreign_public_key("m/48h/1h/0h/2h/1/9"), seed=PSBTTestData.recipient_seed)
+ psbt.outputs.insert(0, other_output)
+ claim_a_stranger_on_the_change(psbt)
+ with pytest.raises(PSBTOutputOwnershipContradictionError):
+ self._parse(psbt)
+
+
+ def test__parse__reports_the_first_held_finding(self):
+ """
+ The psbt carries two findings milder than an attack: a false claim on its input,
+ found while the inputs are read, and a second derivation path entry on its change
+ output, found later while the outputs are read. The parse should report the one
+ it found first, PSBTInputOwnershipClaimError.
+ """
+ decoy_derivation_path = "m/84h/1h/0h/1/9"
+ decoy_public_key = self._root().derive(decoy_derivation_path).get_public_key()
+
+ psbt = self._psbt_with_change()
+ claim_seed_owns_key(psbt.inputs[0], "m/84h/1h/0h/0/0", foreign_public_key())
+ claim_seed_owns_key(psbt.outputs[0], decoy_derivation_path, decoy_public_key)
+
+ with pytest.raises(PSBTInputOwnershipClaimError):
+ self._parse(psbt)
+
+
def test__parse__rejects_a_forged_taproot_claim(self):
"""
A false taproot claim is rejected the same way as an ecdsa one: the input-scope
@@ -1585,6 +1722,26 @@ def test__parse__rejects_a_seed_that_owns_no_input(self):
assert psbt.sign_with(root) == 0
+ def test__parse__reports_a_bad_input_script_ahead_of_the_wrong_seed(self):
+ """
+ The user picks the wrong seed for a psbt whose input also supplies the wrong
+ script. The bad script is a problem with the psbt itself, whichever seed signs it.
+ So the parse should report PSBTInputScriptMismatchError rather than
+ PSBTSeedCannotSignError.
+ """
+ psbt = self._psbt_with_change(PSBTTestData.MULTISIG_NATIVE_SEGWIT_1_INPUT, PSBTTestData.MULTISIG_NATIVE_SEGWIT_CHANGE)
+
+ # With its scripts intact, the psbt is reported as one the wrong seed cannot sign
+ with pytest.raises(PSBTSeedCannotSignError):
+ PSBTParser(psbt, PSBTTestData.recipient_seed, network=SettingsConstants.REGTEST)
+
+ # The script's content is irrelevant, so an arbitrary script will do
+ psbt.inputs[0].witness_script = script.Script(b"\x51") # OP_TRUE
+
+ with pytest.raises(PSBTInputScriptMismatchError):
+ PSBTParser(psbt, PSBTTestData.recipient_seed, network=SettingsConstants.REGTEST)
+
+
def test__parse__accepts_a_cosigner_seed_on_a_multisig(self):
"""
Each cosigner holding a key on the device signs the same psbt in turn, so a seed
@@ -1598,20 +1755,81 @@ def test__parse__accepts_a_cosigner_seed_on_a_multisig(self):
assert psbt_parser.verified_input_derivation_paths[0] != []
+ def test__parse__refuses_a_claim_at_a_derivation_path_too_short_for_a_wallet(self):
+ """
+ A derivation path entry with no levels at all points at the seed's master key.
+ That key is a derivation root, not one any wallet spends from or receives at. No
+ wallet writes an entry at that path, though embit would sign an input built on it
+ anyway. A path of one level is too short to hold both a branch and an address
+ index. No wallet spends from a path that short either.
+
+ So the parse should refuse the psbt with PSBTUnsupportedDerivationPathError:
+ * an input claiming the master key
+ * an output claiming the master key
+ * an input claiming a key at a one-level path
+
+ A forged claim should report as PSBTOutputOwnershipClaimError instead, whether it
+ is at the empty path itself or listed after a true claim on the master key.
+ """
+ root = self._root()
+ master_public_key = root.get_public_key()
+ one_level_public_key = root.derive("m/5").get_public_key()
+
+ # input: claim the master key, on an input that the master key really does
+ # control
+ psbt = self._psbt_with_change()
+ psbt.inputs[0].bip32_derivations.clear()
+ set_input_locking_script(psbt.inputs[0], script.p2wpkh(master_public_key))
+ claim_seed_owns_key(psbt.inputs[0], "m", master_public_key)
+
+ # embit is willing to sign it
+ assert deepcopy(psbt).sign_with(root) > 0
+
+ with pytest.raises(PSBTUnsupportedDerivationPathError):
+ self._parse(psbt)
+
+ # output: claim the master key, with the input left honest
+ psbt = self._psbt_with_change()
+ claim_seed_owns_key(psbt.outputs[0], "m", master_public_key)
+ with pytest.raises(PSBTUnsupportedDerivationPathError):
+ self._parse(psbt)
+
+ # input: claim a key at a one-level path, on an input that key really does
+ # control
+ psbt = self._psbt_with_change()
+ psbt.inputs[0].bip32_derivations.clear()
+ set_input_locking_script(psbt.inputs[0], script.p2wpkh(one_level_public_key))
+ claim_seed_owns_key(psbt.inputs[0], "m/5", one_level_public_key)
+ with pytest.raises(PSBTUnsupportedDerivationPathError):
+ self._parse(psbt)
+
+ # output: claim the master key over someone else's key. The forged claim is the
+ # more serious finding, so that is the one reported.
+ psbt = self._psbt_with_change()
+ claim_seed_owns_key(psbt.outputs[0], "m", foreign_public_key())
+ with pytest.raises(PSBTOutputOwnershipClaimError):
+ self._parse(psbt)
+
+ # output: a true claim on the master key, then a forged claim listed after it
+ psbt = self._psbt_with_change()
+ claim_seed_owns_key(psbt.outputs[0], "m", master_public_key)
+ claim_seed_owns_key(psbt.outputs[0], "m/84h/1h/0h/1/9", foreign_public_key())
+ with pytest.raises(PSBTOutputOwnershipClaimError):
+ self._parse(psbt)
+
+
def test_a_psbt_with_no_utxos_is_rejected_rather_than_crashing(self):
"""
- A psbt with no inputs is malformed and cannot be signed. `parse` should raise
- PSBTSeedCannotSignError. Note that diagnosing the malformation is not this check's
- job.
+ The psbt's inputs leave out the utxos they spend, so the psbt is malformed and
+ cannot be signed. `parse` should raise PSBTMissingInputUtxoError.
"""
psbt = self._psbt_with_change()
for psbt_input in psbt.inputs:
psbt_input.witness_utxo = None
psbt_input.non_witness_utxo = None
psbt_input._utxo = None
- psbt_input.bip32_derivations.clear()
- with pytest.raises(PSBTSeedCannotSignError):
+ with pytest.raises(PSBTMissingInputUtxoError):
self._parse(psbt)
@@ -2648,6 +2866,9 @@ def test__parse__refuses_an_unsupported_script_type(self):
the output's policy shape would match the input's (`None` == `None`) and so the
parse would consider it as possible change. Rather than continue, we expect the
catch-all safety check to spot the unsupported script type and raise RuntimeError.
+
+ Both the input's script check and the output's rebuild carry that catch-all; the
+ input's is the one reached first.
"""
root = self._root()
@@ -2895,11 +3116,7 @@ def _add_foreign_nested_segwit_input(self, psbt: PSBT, derivation_path: str = "m
# scriptPubKey that commits to that redeem script.
public_key = foreign_public_key(derivation_path)
foreign_input.redeem_script = script.p2wpkh(public_key)
- foreign_input.witness_utxo.script_pubkey = script.p2sh(foreign_input.redeem_script)
-
- # Drop the copied non_witness_utxo, which describes our own coin and contradicts
- # the witness_utxo altered above.
- foreign_input.non_witness_utxo = None
+ set_input_locking_script(foreign_input, script.p2sh(foreign_input.redeem_script))
psbt.inputs.append(foreign_input)
return foreign_input
@@ -3066,3 +3283,234 @@ def test__parse__checks_input_scripts_whoever_the_input_belongs_to(self):
foreign_input.redeem_script = script.p2wpkh(foreign_public_key("m/49h/1h/0h/0/1"))
with pytest.raises(PSBTInputScriptMismatchError):
self._parse(psbt)
+
+
+
+class TestPSBTParserInputOwnership(PSBTParserOwnershipTestBase):
+ """
+ A psbt annotates its inputs with claims about which keys control them. Our seed may
+ really derive a claimed key, but it's the script the input commits to that decides
+ which keys can spend it.
+
+ These tests cover claims of ours that the committed script does not use. They also
+ cover the taproot claims whose check needs the input's merkle root.
+ """
+ def test__parse__refuses_a_true_claim_planted_on_another_partys_input(self):
+ """
+ A coordinator that holds our account xpub can derive our keys itself. So it can
+ write a TRUE claim (our fingerprint along with a key our seed really derives) onto
+ another party's input, which our key has no part in.
+
+ The claim verifies, because it is true. But the input's committed script does not
+ use that key, so the parse should refuse the psbt with
+ PSBTInputOwnershipContradictionError.
+ """
+ planted_derivation_path = "m/84h/1h/7h/0/0"
+ planted_public_key = self._root().derive(planted_derivation_path).get_public_key()
+
+ psbt = self._psbt_with_change()
+
+ # Another party's input: a copy of ours, repointed at their key and carrying no
+ # derivation path entries
+ foreign_input = deepcopy(psbt.inputs[0])
+ foreign_input.bip32_derivations.clear()
+ set_input_locking_script(foreign_input, script.p2wpkh(foreign_public_key()))
+ psbt.inputs.append(foreign_input)
+
+ # With no claim on it, the other party's input is simply not ours
+ psbt_parser = self._parse(psbt)
+ assert psbt_parser.verified_input_derivation_paths[1] == []
+
+ # Plant the true claim
+ claim_seed_owns_key(foreign_input, planted_derivation_path, planted_public_key)
+
+ with pytest.raises(PSBTInputOwnershipContradictionError):
+ self._parse(psbt)
+
+
+ def test__parse__refuses_a_decoy_entry_on_a_multisig_input(self):
+ """
+ The psbt adds a decoy entry to the user's own multisig input, along with the
+ seed's real cosigner entry. The decoy claims a key our seed does own, at a path
+ whose key the input's script has no use for.
+
+ The real entry is still in place, but the decoy is a claim the committed script
+ contradicts. So the parse should refuse the psbt with
+ PSBTInputOwnershipContradictionError.
+ """
+ decoy_derivation_path = "m/48h/1h/0h/2h/0/500"
+ decoy_public_key = self._root().derive(decoy_derivation_path).get_public_key()
+
+ psbt = self._psbt_with_change(PSBTTestData.MULTISIG_NATIVE_SEGWIT_1_INPUT, PSBTTestData.MULTISIG_NATIVE_SEGWIT_CHANGE)
+ claim_seed_owns_key(psbt.inputs[0], decoy_derivation_path, decoy_public_key)
+
+ with pytest.raises(PSBTInputOwnershipContradictionError):
+ self._parse(psbt)
+
+
+ def test__parse__keeps_both_keys_of_a_seed_holding_two_cosigner_slots(self):
+ """
+ A multisig can use one seed in two of its cosigner slots, each at its own
+ derivation path. It is a poor wallet, since that seed can spend alone, but it is
+ a valid one.
+
+ The user's 2-of-3 input is rebuilt with this seed in two slots plus one
+ stranger's key. Both of our keys are in the input's committed script, so the
+ parse should keep both derivation paths.
+ """
+ slot_a_derivation_path = "m/48h/1h/0h/2h/0/0"
+ slot_b_derivation_path = "m/48h/1h/1h/2h/0/0"
+
+ psbt = self._psbt_with_change(PSBTTestData.MULTISIG_NATIVE_SEGWIT_1_INPUT, PSBTTestData.MULTISIG_NATIVE_SEGWIT_CHANGE)
+ inp = psbt.inputs[0]
+ inp.bip32_derivations.clear()
+
+ # Our two keys, each claimed under our fingerprint
+ cosigner_public_keys = []
+ for derivation_path in (slot_a_derivation_path, slot_b_derivation_path):
+ public_key = self._root().derive(derivation_path).get_public_key()
+ cosigner_public_keys.append(public_key)
+ claim_seed_owns_key(inp, derivation_path, public_key)
+
+ # The stranger's key, claimed under their fingerprint
+ stranger_public_key = foreign_public_key("m/48h/1h/0h/2h/0/0")
+ cosigner_public_keys.append(stranger_public_key)
+ claim_seed_owns_key(inp, "m/48h/1h/0h/2h/0/0", stranger_public_key, seed=PSBTTestData.recipient_seed)
+
+ # Rebuild the input's script and the scriptPubKey that commits to it
+ inp.witness_script = script.multisig(2, cosigner_public_keys)
+ set_input_locking_script(inp, script.p2wsh(inp.witness_script))
+
+ # embit signs with both of our keys
+ assert deepcopy(psbt).sign_with(self._root()) == 2
+
+ psbt_parser = self._parse(psbt)
+ assert [entry.derivation for entry in psbt_parser.verified_input_derivation_paths[0]] == [
+ bip32.parse_path(slot_a_derivation_path),
+ bip32.parse_path(slot_b_derivation_path),
+ ]
+
+
+ def test__parse__keeps_a_key_path_spend_from_an_address_built_over_a_script_tree(self):
+ """
+ A taproot address can commit to its internal key tweaked by a script tree's
+ merkle root and still be spent through the key path. The psbt supplies that
+ merkle root on the input, so the parse should rebuild the address from our
+ internal key and keep its derivation path.
+
+ BIP-371 also lets an input list the keys in its script tree leaves. With a key of
+ ours listed in the tree's leaf as well, the parse should still keep just the
+ internal key's derivation path.
+ """
+ internal_derivation_path = "m/86h/1h/0h/0/0"
+ internal_public_key = self._root().derive(internal_derivation_path).get_public_key()
+
+ # A script tree of one leaf, holding another of our keys. A one-leaf tree's
+ # merkle root is that leaf's hash.
+ leaf_derivation_path = "m/86h/1h/0h/0/1"
+ leaf_public_key = self._root().derive(leaf_derivation_path).get_public_key()
+ merkle_root = tapleaf_hash(leaf_public_key)
+
+ psbt = self._psbt_with_change(PSBTTestData.SINGLE_SIG_TAPROOT_1_INPUT, PSBTTestData.SINGLE_SIG_TAPROOT_CHANGE)
+ inp = psbt.inputs[0]
+ set_input_locking_script(inp, p2tr_with_script_tree(internal_public_key, merkle_root))
+ inp.taproot_merkle_root = merkle_root
+
+ # embit signs this input through its key path
+ assert deepcopy(psbt).sign_with(self._root()) == 1
+
+ psbt_parser = self._parse(psbt)
+ assert [entry.derivation for entry in psbt_parser.verified_input_derivation_paths[0]] == [bip32.parse_path(internal_derivation_path)]
+
+ # List our key in the leaf as well
+ claim_seed_owns_key(inp, leaf_derivation_path, leaf_public_key, is_taproot=True, leaf_hashes=[merkle_root])
+
+ psbt_parser = self._parse(psbt)
+ assert [entry.derivation for entry in psbt_parser.verified_input_derivation_paths[0]] == [bip32.parse_path(internal_derivation_path)]
+
+
+ def test__parse__refuses_an_internal_key_claim_that_its_merkle_root_contradicts(self):
+ """
+ The input's address commits to our internal key with no script tree, but the psbt
+ supplies a merkle root for it anyway. Our key tweaked by that merkle root is not
+ the key the input commits to. The psbt has supplied everything that check needs,
+ so the parse should refuse the psbt with PSBTInputOwnershipContradictionError.
+ """
+ psbt = self._psbt_with_change(PSBTTestData.SINGLE_SIG_TAPROOT_1_INPUT, PSBTTestData.SINGLE_SIG_TAPROOT_CHANGE)
+ psbt.inputs[0].taproot_merkle_root = tapleaf_hash(foreign_public_key())
+
+ with pytest.raises(PSBTInputOwnershipContradictionError):
+ self._parse(psbt)
+
+
+ def test__parse__drops_an_internal_key_claim_when_the_merkle_root_is_left_out(self):
+ """
+ The input's address commits to our internal key tweaked by a script tree, but the
+ psbt leaves out the input's merkle root, which is an optional field. Without it we
+ cannot rebuild the address, so the claim is neither confirmed nor contradicted.
+
+ The parse should drop the claim, leaving that input with no verified derivation
+ paths. With another input of ours, the psbt should still parse.
+ """
+ internal_derivation_path = "m/86h/1h/0h/0/0"
+ internal_public_key = self._root().derive(internal_derivation_path).get_public_key()
+ merkle_root = tapleaf_hash(foreign_public_key())
+
+ psbt = self._psbt_with_change(PSBTTestData.SINGLE_SIG_TAPROOT_1_INPUT, PSBTTestData.SINGLE_SIG_TAPROOT_CHANGE)
+
+ # A second input: a copy of ours, at an address built over the script tree, with
+ # no merkle root supplied
+ script_tree_input = deepcopy(psbt.inputs[0])
+ set_input_locking_script(script_tree_input, p2tr_with_script_tree(internal_public_key, merkle_root))
+ assert script_tree_input.taproot_merkle_root is None
+ psbt.inputs.append(script_tree_input)
+
+ psbt_parser = self._parse(psbt)
+ assert [entry.derivation for entry in psbt_parser.verified_input_derivation_paths[0]] == [bip32.parse_path(internal_derivation_path)]
+ assert psbt_parser.verified_input_derivation_paths[1] == []
+
+
+ def test__parse__refuses_a_taproot_map_claim_on_a_non_taproot_input(self):
+ """
+ The psbt claims one of our keys in the taproot map of the user's own p2wpkh
+ input, at a path whose key the input's script does not use. Only a taproot
+ input commits to a key tweaked by a merkle root, so a missing merkle root
+ explains nothing here. The parse should refuse the psbt with
+ PSBTInputOwnershipContradictionError, as it would the same claim in the
+ non-taproot map.
+ """
+ claimed_derivation_path = "m/86h/1h/0h/0/9"
+ claimed_public_key = self._root().derive(claimed_derivation_path).get_public_key()
+
+ # Our claim is the input's only entry, written into the taproot map
+ psbt = self._psbt_with_change()
+ psbt.inputs[0].bip32_derivations.clear()
+ claim_seed_owns_key(psbt.inputs[0], claimed_derivation_path, claimed_public_key, is_taproot=True)
+ assert psbt.inputs[0].taproot_merkle_root is None
+
+ with pytest.raises(PSBTInputOwnershipContradictionError):
+ self._parse(psbt)
+
+
+ def test__parse__refuses_an_input_this_seed_can_sign_only_through_a_script_path(self):
+ """
+ The input's address is built for script path spends only. Its internal key is the
+ provably unspendable NUMS point. Our key is in its script tree's one leaf.
+ Script path spends are not yet supported, so the parse should refuse the psbt with
+ PSBTUnsupportedScriptPathError.
+ """
+ leaf_derivation_path = "m/86h/1h/0h/0/0"
+ leaf_public_key = self._root().derive(leaf_derivation_path).get_public_key()
+ merkle_root = tapleaf_hash(leaf_public_key)
+
+ psbt = self._psbt_with_change(PSBTTestData.SINGLE_SIG_TAPROOT_1_INPUT, PSBTTestData.SINGLE_SIG_TAPROOT_CHANGE)
+ inp = psbt.inputs[0]
+ set_input_locking_script(inp, p2tr_with_script_tree(NUMS_INTERNAL_KEY, merkle_root))
+ inp.taproot_merkle_root = merkle_root
+
+ # Our key is now claimed only as the key in the leaf
+ inp.taproot_bip32_derivations.clear()
+ claim_seed_owns_key(inp, leaf_derivation_path, leaf_public_key, is_taproot=True, leaf_hashes=[merkle_root])
+
+ with pytest.raises(PSBTUnsupportedScriptPathError):
+ self._parse(psbt)Why this scored 81/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.