Skip to content

descriptor: reject uncompressed keys in wpkh() and sh(wpkh()) - #179

Open
usefahmed07 wants to merge 2 commits into
diybitcoinhardware:masterfrom
usefahmed07:fix/wpkh-uncompressed-key
Open

usefahmed07 wants to merge 2 commits into
diybitcoinhardware:masterfrom
usefahmed07:fix/wpkh-uncompressed-key

Conversation

@usefahmed07

@usefahmed07 usefahmed07 commented Nov 10, 2026 •

Copy link
Copy Markdown

Fixes #178

BIP 382 only allows compressed public keys in wpkh(). Bitcoin Core
rejects them, while Descriptor.from_string() accepted them.

@fametrano fametrano left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@usefahmed07

Copy link
Copy Markdown
Author

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 fametrano left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

odudex
odudex previously approved these changes Nov 12, 2026

@odudex odudex left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

jdlcdl
jdlcdl previously approved these changes Nov 12, 2026
@jdlcdl

jdlcdl commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

ACK at d5a6ee4, with intent to merge 2 commits into "hardened" after pr161
ACK at 651450d, with intent to merge 2 commits into "hardened" after pr167

Thank you usefahmed, fametrano, odudex and tanveer.

Comment thread src/embit/descriptor/descriptor.py Resolved
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)).
@usefahmed07
usefahmed07 dismissed stale reviews from jdlcdl and odudex via 651450d November 14, 2026 11:39
@usefahmed07
usefahmed07 force-pushed the fix/wpkh-uncompressed-key branch from d5a6ee4 to 651450d Compare November 14, 2026 11:39

@notTanveer notTanveer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 651450d

@fametrano fametrano left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/embit/descriptor/descriptor.py Resolved
Comment thread tests/tests/test_descriptor.py Resolved

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Descriptor.from_string() accepts uncompressed keys in wpkh() and sh(wpkh())

5 participants