Repository navigation
descriptor: reject uncompressed keys in wpkh() and sh(wpkh()) - #179
usefahmed07 wants to merge 2 commits into
Conversation
BIP 382 only allows compressed public keys in wpkh(). Bitcoin Core rejects them, while Descriptor.from_string() accepted them.
fametrano
left a comment
There was a problem hiding this comment.
Concept ACK
#178 lists pkh() and sh(pk()) as the cases to keep, and the new test adds wsh(pk(U)) to them. That line should not go in as written: wsh() is segwit v0 as well, BIP 382 requires every key under wsh() to be compressed (L50), and wsh(pk(04...)) is one of its invalid test vectors (L98-L99).
With the key U from #178, Bitcoin Core v32.1.0 getdescriptorinfo rejects wsh(pk(U)) and sh(wsh(pk(U))) with "pk(): Uncompressed keys are not allowed", and rejects wsh(multi(1,U)) too. embit master accepts all three, and this branch leaves them accepted: the wsh() path goes through Miniscript.read_from and never reaches the new check.
The same check belongs where keys are parsed under wsh(), miniscript included, and that test line should assert DescriptorError.
Thanks, fixed. The check now also runs for keys parsed under wsh() and sh(wsh()), miniscript included, and the wsh(pk(U)) test line asserts DescriptorError. Added sh(wsh(pk(U))) and wsh(multi(1,U)) as well. |
fametrano
left a comment
There was a problem hiding this comment.
ACK d5a6ee4
Every uncompressed-key case under wpkh() and wsh() now raises, and Bitcoin Core v32.1.0 getdescriptorinfo rejects each: the new test lines, plus wsh(sortedmulti(1,U,C)), wsh(pkh(U)), wsh(thresh(1,pk(U))) and wsh(and_v(v:pk(U),older(10))). pkh(U), sh(pk(U)) and sh(multi(1,U)) stay accepted, as in Core. Tests: 124 passed, 17 skipped.
Outside this PR: tr(U), tr(C,pk(U)) and tr(C,multi_a(1,U)) are still accepted, while Core rejects them. That could be a separate issue.
BIP 382 requires every key under wsh() to be compressed, miniscript included. Bitcoin Core rejects wsh(pk(U)), sh(wsh(pk(U))) and wsh(multi(1,U)), while Descriptor.from_string() accepted them. Check the keys of the parsed miniscript when wsh is set, and assert DescriptorError for these cases in the test instead of accepting wsh(pk(U)).
d5a6ee4 to
651450d
Compare
fametrano
left a comment
There was a problem hiding this comment.
ACK 651450d
A segwit v0 descriptor built in code with an uncompressed key is now refused as well: Descriptor(key=Key.from_string(U)) and Descriptor(Miniscript.from_string("pk(U)")) were accepted before this push. No test builds one. btclib-org's bip32-descriptors refuses both when built too.
Fixes #178