Repository navigation
Conversation
fametrano
left a comment
There was a problem hiding this comment.
ACK 1ee84ab
All 15 tr() descriptors I tried that hold an uncompressed key are now refused: hex or WIF, as internal key or inside pk(), pkh(), multi_a(), sortedmulti_a(), and_v() or or_d(). The compressed, x-only and xpub controls still parse. getdescriptorinfo of Bitcoin Core v32.1.0 refuses and accepts exactly the same strings. Each case and the outputs at base, at head and from Core are in https://gist.github.com/fametrano/42b8419bf887fc7d256ad77379245709/c3a475203e560c186e44f82689f0e76e3a5e0fa1.
| # BIP 386: tr() only accepts compressed or x-only public keys | ||
| if not getattr(key.key, "compressed", True): | ||
| raise DescriptorError("Uncompressed keys are not allowed in tr()") |
There was a problem hiding this comment.
The check added to __init__ already refuses these keys, in parsed strings and in objects made with Descriptor(...), so this one and the taptree loop below can go.
| # BIP 386: tr() only accepts compressed or x-only public keys | |
| if not getattr(key.key, "compressed", True): | |
| raise DescriptorError("Uncompressed keys are not allowed in tr()") |
| for k in taptree.keys: | ||
| if not getattr(k.key, "compressed", True): | ||
| raise DescriptorError( | ||
| "Uncompressed keys are not allowed in tr()" | ||
| ) |
There was a problem hiding this comment.
| for k in taptree.keys: | |
| if not getattr(k.key, "compressed", True): | |
| raise DescriptorError( | |
| "Uncompressed keys are not allowed in tr()" | |
| ) |
1ee84ab to
1accfe9
Compare
|
Dropped the redundant 1: 1ee84ab ! 1: 1accfe9 descriptor: reject uncompressed keys in tr() (closes #180)
@@ src/embit/descriptor/descriptor.py: class Descriptor(DescriptorBase):
@property
def script_len(self):
## tests/tests/test_descriptor.py ##
@@ tests/tests/test_descriptor.py: class DescriptorTest(TestCase):
+ "04c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee51ae"
+ "168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a"
+ )
++ UWIF = "5HpjE2Hs7vjU4SN3YyPQCdhzCu92WoEeuE6PWNuiPyTu3ESGnzn"
+ C = "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"
+ X = "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"
+ # BIP 386: uncompressed keys are not allowed in tr()
+ for d in [
+ "tr(%s)" % U,
++ "tr(%s)" % UWIF,
+ "tr(%s,pk(%s))" % (C, U),
+ "tr(%s,multi_a(1,%s))" % (C, U),
+ "tr(%s,{pk(%s),pk(%s)})" % (C, C, U),
@@ tests/tests/test_descriptor.py: class DescriptorTest(TestCase):
+ ]:
+ self.assertRaises(DescriptorError, Descriptor.from_string, d)
+
++ # direct construction with uncompressed key must also fail
++ ukey = Key(ec.PublicKey.parse(bytes.fromhex(U)))
++ self.assertRaises(DescriptorError, Descriptor, key=ukey, taproot=True)
++
+ # compressed and x-only keys are valid
+ for d in [
+ "tr(%s)" % C, |
fametrano
left a comment
There was a problem hiding this comment.
reACK 1accfe9
Thanks. With only the __init__ check left, the probe in my earlier gist gives the same output. The two assertions the test gains, on tr(UWIF) and Descriptor(key=ukey, taproot=True), each fail on master.
|
BIP-386, in the section before Test Vectors, clearly states: Modified Key ExpressionKey Expressions within a tr() expression must only create x-only public keys. Uncompressed public keys are not allowed, but compressed public keys would be implicitly converted to x-only public keys. ...and I believe this PR implements and proves it in its tests.
I have tested this rebased onto "hardened" with conflicts resolved as noted in the changed files (non-blocking comments for repo-maintainer) as well as use of unhexlify() in tests... Adds 1 more passing test for Cpython and micropython. tACK at 96bc89b below, against "hardened" with 2 conflicts -- each resolved by taking both. Awaiting more ACKs approvals, then a near-term merge to "hardened" |
…re#180) BIP 386 requires all key expressions under tr() to produce x-only public keys. Uncompressed public keys and uncompressed WIF private keys under tr()—whether parsed from strings or constructed directly via Descriptor(..., taproot=True)—are refused with DescriptorError. Signed-off-by: Yudis-bit <Yudis-bit@proton.me>
1accfe9 to
96bc89b
Compare
|
Switched to 1: 1accfe9 ! 1: 96bc89b descriptor: reject uncompressed keys in tr() (closes #180)
@@ src/embit/descriptor/descriptor.py: class Descriptor(DescriptorBase):
# make sure all keys are either taproot or not
for k in self.keys:
k.taproot = taproot
++ # BIP-386: uncompressed keys are not allowed in tr()
+ if self.taproot and not getattr(k.key, "compressed", True):
+ raise DescriptorError("Uncompressed keys are not allowed in tr()")
@@ src/embit/descriptor/descriptor.py: class Descriptor(DescriptorBase):
def script_len(self):
## tests/tests/test_descriptor.py ##
+@@
+ from unittest import TestCase
+-from binascii import hexlify
++from binascii import hexlify, unhexlify
+ from embit.descriptor import Descriptor, Key
+ from embit.descriptor.arguments import KeyHash, Number
+ from embit.descriptor.miniscript import OPERATORS, WRAPPERS
@@ tests/tests/test_descriptor.py: class DescriptorTest(TestCase):
with self.assertRaises(DescriptorError):
Descriptor.from_string(d)
@@ tests/tests/test_descriptor.py: class DescriptorTest(TestCase):
+ self.assertRaises(DescriptorError, Descriptor.from_string, d)
+
+ # direct construction with uncompressed key must also fail
-+ ukey = Key(ec.PublicKey.parse(bytes.fromhex(U)))
++ ukey = Key(ec.PublicKey.parse(unhexlify(U)))
+ self.assertRaises(DescriptorError, Descriptor, key=ukey, taproot=True)
+
+ # compressed and x-only keys are valid |
BIP 386 requires all key expressions under tr() to produce x-only public keys. Uncompressed 65-byte public keys under tr(), whether used as the internal key or inside script leaves like pk() and multi_a(), are now refused with DescriptorError.
Closes #180