Repository navigation
fix(descriptor): handle pk() descriptors in derive_from_psbt_input - #596
henrypeters wants to merge 2 commits into
Conversation
busayo-od
left a comment
There was a problem hiding this comment.
Thanks for working on this! I noticed that #457 introduces validation that rejects Bare descriptors during wallet creation and loading. Given that derive_from_psbt_input is currently only called during wallet finalization using descriptors from the wallet's keychain index, would this case still be reachable through supported Wallet usage once 457 is applied?
|
Thanks for the pointer to #457 . Since that PR is still open and not yet merged into master, |
Summary
derive_from_psbt_inputfalls back to a script comparison strategy whena PSBT input carries no key origin data and the descriptor has no wildcard.
This fallback uses a
matchonDescriptorTypewith three arms:script_pubkeycomparison — forPkh,Wpkh,ShWpkh,Trredeem_scriptcomparison — forSh,ShSortedMultiwitness_scriptcomparison — forWsh,ShWsh, etc.DescriptorType::Bare— which covers barepk()descriptors — wasincorrectly placed in arm 2, which checks against
psbt_input.redeem_script.A bare
pk()descriptor does not use a redeem script — it produces ascript_pubkeydirectly. This meantpsbt_input.redeem_scriptwas alwaysNonefor these inputs, the guard condition always failed, and the functionalways returned
Nonefor anypk()descriptor without key origin data.This silently broke signing and finalization for wallets using bare
pk()descriptors whenever the PSBT lacked BIP32 derivation metadata.
Fix
I moved
DescriptorType::Barefrom arm 2 to arm 1, where it is matched bycomparing
descriptor.script_pubkey()against the UTXO'sscript_pubkey— the correct approach for bare
pk()descriptors.Also removes the
// TODO: add pk() herecomment that identified this gap.Testing
Added a test using a bare
pk()descriptor confirming thatderive_from_psbt_inputreturnsSome(descriptor)instead ofNonewhen the UTXO's
script_pubkeymatches.