Skip to content

descriptor: reject tr() leaves that need no signature or repeat a key - #184

Open
fametrano wants to merge 6 commits into
diybitcoinhardware:masterfrom
fametrano:tr-leaf-sanity
Open

fametrano wants to merge 6 commits into
diybitcoinhardware:masterfrom
fametrano:tr-leaf-sanity

Conversation

@fametrano

Copy link
Copy Markdown

tr() still accepts leaves that Bitcoin Core rejects as not sane: tr(A,1), tr(A,older(10)) and tr(A,sha256(H)) are spendable on the script path without a signature, and tr(A,and_v(v:pk(B),pk(B))) repeats a key. The miniscript fragments now compute the s property, which BIP 379 defines as "satisfying this expression always requires a signature", and a leaf must have it. A leaf that repeats a key is rejected. As in Core, keys are compared at index 0, and only a whole-leaf multi_a() or sortedmulti_a() may repeat one. TapLeaf also refuses a miniscript built without taproot=True, which let multi() into a leaf. Core v32.1.0 (getdescriptorinfo) accepts and rejects the same tr() descriptors as the tests.

Built on #169: the branch carries its commits until #169 reaches master, and only the last commit is new. It applies notTanveer's review of #169, except the multipath length mismatch, which is on master too.

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.
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.
The tests/unittest.py shim, which run_tests.py uses, has no subTest.
Use plain loops instead.
A tr() leaf of type B could still be satisfied without a signature, as
older(10) or sha256(H) are, or repeat a key. Bitcoin Core rejects both.
The miniscript fragments now compute the s property, which BIP 379
defines as "satisfying this expression always requires a signature",
and TapLeaf requires it. Parsing a leaf rejects a repeated key,
comparing keys at index 0 of their first branch, as Core does. A
whole-leaf multi_a() or sortedmulti_a() is not checked, since Core
parses it outside miniscript and accepts repeated keys there.

TapLeaf also refuses a miniscript parsed without taproot=True, which
would otherwise accept multi() in a leaf. The literals 0 and 1 now keep
the taproot flag they are parsed with.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant