Repository navigation
Conversation
TapLeaf never called verify(), so tr() accepted leaves that Bitcoin Core rejects, such as and_v(pk(B),1), and so did a TapLeaf built in code. Verify the miniscript when the leaf is built and require its type to be B, as Descriptor.__init__ does for wsh.
bitcoisas
left a comment
There was a problem hiding this comment.
tACK b8a3496
Tested on its own and merged with #167. The full test suite passes in both cases (124 and 125 passed, the same 17 skipped). This mirrors what Descriptor.init already does for wsh, and since derive/branch/to_public rebuild the leaf, they go through the same check, as wsh does...
With both PRs, tr(I,and_n(or_i(0,older(10)),pk(B))) is rejected and tr(I,andor(dv:older(1),pk(A),pk(B))) is still accepted. On this branch alone the first one still gets through, since the and_n rule itself is fixed in #167. Glad to see the dv:older case already covered in test_leaf_miniscript_is_type_checked; that was the guard I was suggesting there. :)
|
concept ACK I understand this as a change from "trust me bro, it's a miniscript tapleaf" to "it's a validated miniscript tapleaf" If you have references, please point me to BIPs that can confirm my understanding. With better understanding and another approval, intending for this to go atop branch "hardened" after pr167 is merged there. |
odudex
left a comment
There was a problem hiding this comment.
Fix is correct.
Things that could be improved, none blocking:
- One test case doesn't exercise the change. multi(1,A,B) inside tr() was already rejected by Multi.init before this PR. It's harmless as a regression guard, but its comment implies the new check catches it.
- Exception type differs from wsh. For a non-B top level, wsh raises DescriptorError and this raises MiniscriptError with the same message. MiniscriptError subclasses DescriptorError, so callers catching the base class are unaffected.
- No CHANGELOG entry, same as the andor PR. A one-line ### Fixed entry fits unless this came in as a security report.
|
Yes, with one limit: a leaf is now type-checked and has to be of type B, as a BIP 386 allows as a leaf "Any Script Expression that is allowed at the level this Tree Expression is in", which includes the BIP 379 Miniscript expressions. BIP 379 says an expression that fails a fragment's requirements "is not valid Miniscript", and that type B is "required for the top level expression". If you want odudex's three points addressed before you take it, I will push them. |
Thank you fametrano for replying, just seeing it this morning. Yes, please do push latest commits (we'll look to re-approve quickly), so that this pr is as complete as possible. I intend to merge this into "hardened" but leave it as an open pr against "master", so I'd like for all commits to be together in both branches eventually. |
Descriptor.__init__ raises DescriptorError when a wsh script is not of type B. Raise the same error for a tapscript leaf.
Multi.__init__ already rejects multi in tr(), before the leaf is type-checked, and test_multi_variants covers it. Keep only the cases the leaf check catches.
|
Pushed the three points from odudex's review: a non-B leaf now raises |
|
Ack at 6255583 |
| ] | ||
| for leaf in invalid: | ||
| for tree in (leaf, "{%s,pk(%s)}" % (leaf, b), "{pk(%s),%s}" % (b, leaf)): | ||
| with self.subTest(tree=tree): |
There was a problem hiding this comment.
self.subTest isn't in the tests/unittest.py shim, so this breaks run_tests.py on micropython.
There was a problem hiding this comment.
The three subTest blocks are plain loops in 508c05b, so run_tests.py now runs through the tests/unittest.py shim under CPython.
The tests/unittest.py shim, which run_tests.py uses, has no subTest. Use plain loops instead.
notTanveer
left a comment
There was a problem hiding this comment.
tACK 508c05b
a few things that could still be improved, none blocking:
- TapLeaf doesn't check miniscript.taproot, so a leaf built in code without taproot=True is checked with wsh rules. TapLeaf(Miniscript.from_string("multi(1,A,B)")) is accepted and compiles to a script ending in OP_CHECKMULTISIG, which can never be spent in tapscript. one if not miniscript.taproot: raise DescriptorError(...) at taptree.py:10 fixes it.
- type B is needed but not enough. these still parse here, Core (ddb94fd3e1) rejects all of them:
tr(A,1) not sane: witnesses without signature exist
tr(A,older(10)) not sane: witnesses without signature exist
tr(A,sha256(H)) not sane: witnesses without signature exist
tr(A,and_v(v:pk(B),pk(B))) not sane: contains duplicate public keys
the first three are anyone-can-spend on the script path. not for this PR, but worth an issue. - the wsh check this copies also has the branch length check, tr doesn't get it:
tr(X/<0;1>/,pk(X/<0;1;2>/))
embit: accepted, then derive(0, branch_index=2) -> ArgumentError: Invalid branch index
Core: tr(): Multipath internal key mismatches multipath subscripts lengths
same on master, so not a regression. probably belongs in Descriptor.init over self.keys. - CHANGELOG could say that this is stricter, so descriptors that used to load now raise. tr(A,s:pk(B)), tr(A,pk_k(B)) and tr(A,older(0)) load on master and raise here. Core rejects them too so the change is right, but Krux/SeedSigner/Specter should know before they bump.
Thank you tanveer for improvement comments. I'll note that I have already merged the changes as they were at 508c05b into "hardened", so if more commits appear here, I can pick and merge them into "hardened" -- or another PR can be made to apply to your comments. I'll leave it up to you, fametrano. |
Another PR, then: #184, on top of #169, which stays as you merged it. It adds Core's signature and duplicate-key checks on leaves, and the |
embit accepts
tr()leaves that are not valid miniscript, such astr(A,and_v(pk(B),1))andtr(A,v:pk(B)), which Bitcoin Core v31.1.0 rejects.Descriptor.__init__type-checks a wsh miniscript, but nothing checks a tapscript leaf.TapLeafnow callsverify()and requires typeB, as for wsh; the tapscript rules (multi_ainstead ofmulti,uond:) were already in embit. I compared the test's leaves on Core (getdescriptorinfo) and on embit (Descriptor.from_string): the new test fails on master and the suite passes (124 passed, 17 skipped).Core also rejects
tr(A,and_n(or_i(0,older(10)),pk(B))), which embit still accepts: itsand_ncheck takesdoruinstead of both. #167 fixes that.