The BIP-379 currently has a TBD in the test vector section.
I have extracted a bunch of test vectors from the rust-miniscript project, either directly or by slightly modifying test code to dump them into text/TSV files.
They have been very helpful for re-implementation in another language, so I think they should be made easily available here.
BIP-379: add test vectors from rust-miniscript #2240
pull guggero wants to merge 1 commits into bitcoin:master from guggero:bip379-test-vectors changing 18 files +76242 −1-
guggero commented at 9:11 AM on August 6, 2026: contributor
- jonatack added the label Proposed BIP modification on Aug 6, 2026
- jonatack added the label Pending acceptance on Aug 6, 2026
-
jonatack commented at 6:29 AM on August 7, 2026: member
Concept ACK. It may be handy to provide a file here that runs/verifies the test vectors.
- guggero force-pushed on Aug 7, 2026
-
guggero commented at 8:58 AM on August 7, 2026: contributor
Concept ACK. It may be handy to provide a file here that runs/verifies the test vectors.
That's a great idea. I've added that in the latest push. Output looks like this:
$ cd bip-0379; go run main.go Checking the BIP379 test vectors in . against github.com/btcsuite/btcd/descriptors/miniscript. Testing vectors in valid_from_alloy.txt [positive]: 5896/5896 done (type column not compared) Testing vectors in valid_8f1e8_from_alloy.txt [positive]: 3492/3492 done (type column not compared) Testing vectors in malleable_from_alloy.txt [positive/negative]: 7024/7024 + 7024/7024 done Testing vectors in conflict_from_alloy.txt [positive]: 1773/1773 done (1586 of them are rejected by the sanity checks) Testing vectors in edge_cases.txt [positive]: 42/42 done Testing vectors in opcodes.txt [positive]: 18185/18185 done (type and op count columns not compared) Testing vectors in invalid.txt [negative]: 5574/5574 done Testing vectors in props_from_rust.tsv [positive]: 8198/8198 done (op_count and exec_stack columns not compared) Testing vectors in props_from_rust_tap.tsv [positive/negative]: 6728/6728 + 1470/1470 done (op_count and exec_stack columns not compared) Testing vectors in scripts_from_rust.tsv [positive]: 8198/8198 done Testing vectors in scripts_from_rust_tap.tsv [positive/negative]: 6728/6728 + 1470/1470 done Testing vectors in redeem.json [positive/negative]: 12/12 + 34/34 done (each spend is executed in the script engine) All 81848 vectors passed (0 skipped). -
murchandamus commented at 10:25 PM on August 17, 2026: member
cc Authors: @sipa, @apoelstra, @sanket1729, @darosior, @achow101
-
sipa commented at 8:16 PM on August 19, 2026: member
I tried to run these tests through the Bitcoin Core miniscript implementation, but quickly hit the problem that the typing rules are inplemented inconsistently. This isn't a problem in production, because the differences are all within expressions that are invalid (for the correctness-related typing rules) or malleable (for the malleability-related typing rules) anyway, but it does mean that exact type tests like the ones in
malleable_from_alloy.txtenforce than strictly needed.In fact, rust-miniscript, Bitcoin Core, and the BIP text are all inconsistent with each other, in minor irrelevant ways. If we want to go the direction of having strict test vectors (which I support), I think we also need to first align all implementations and specifications. My suggestion would be to make everything match the BIP text. I have an (LLM written) patch for Bitcoin Core to make it do that (which passes all its unit & fuzz tests) which I'm happy to PR, but someone else will need to do the same for rust-bitcoin. It differs from the BIP in one rule: the
threshrule for the "unique dissatisfiable"erule in the BIP is that all children ares, while rust-miniscript (and Bitcoin Core, so far) additionally (and superfluously) require that all children aree. -
jonatack commented at 8:57 PM on August 19, 2026: member
My suggestion would be to make everything match the BIP text.
(non-author) approach ACK
-
guggero commented at 6:52 AM on August 22, 2026: contributor
Thanks a lot for testing the test vectors with Bitcoin Core, @sipa.
I'm also in favor of attempting to align everything with the BIP text.
but someone else will need to do the same for rust-bitcoin
Will attempt that soon-ish.
EDIT: Here's the BIP amendment PR and the
rust-miniscriptPR. - guggero force-pushed on Aug 22, 2026
-
guggero commented at 12:45 PM on August 22, 2026: contributor
I I've pushed up a fixup commit (3526e43) that addresses #2240 (comment) (and also fixes the Golang import issues I didn't realize were there).
-
apoelstra commented at 2:01 PM on August 22, 2026: contributor
concept ACK. Great effort. I'm sure a LLM can fill in the documented gaps in a followup PR.
I didn't look at the test vectors or the Go code, but the markdown updates look good to me.
Will review https://github.com/rust-bitcoin/rust-miniscript/pull/1032 more carefully.
- guggero referenced this in commit a320fe8d7e on Aug 26, 2026
-
guggero commented at 6:29 AM on August 26, 2026: contributor
I've updated the test vectors in a fixup commit to match the discussion in #2267 and the proposed changes in https://github.com/rust-bitcoin/rust-miniscript/pull/1037.
- guggero referenced this in commit acbc7b000b on Aug 30, 2026
- guggero force-pushed on Sep 8, 2026
- guggero renamed this:
BIP-379: add test vectors from rust-miniscript
BIP-379: add test vectors from rust-miniscript and btcd
on Sep 8, 2026 - guggero renamed this:
BIP-379: add test vectors from rust-miniscript and btcd
BIP-379: add test vectors from rust-miniscript
on Sep 8, 2026 - guggero force-pushed on Sep 8, 2026
- guggero force-pushed on Sep 8, 2026
-
murchandamus commented at 5:08 PM on September 9, 2026: member
Thanks for the reviews and updates to the implementations, great to see that y’all are on it.
-
fametrano commented at 12:06 PM on October 2, 2026: contributor
The harness compares sat_witness_elements and sat_size, and both count as rust-miniscript does. The BIP does not say what they count. An implementation that counts as Bitcoin Core does fails every sat_witness_elements row and 21% of sat_size rows.
I ran the vectors at 47047eb through btclib-wallet's miniscript module, which reproduces the resource numbers in Core's miniscript_tests.cpp. Once malleable expressions carry no "s", "f" or "e", as #2267 says, it agrees on every row for validity, types, timelock mixing, malleability, requires_sig, script_size and both script tables. It also disagrees on 10% of the opcodes.txt ops and on op_count and exec_stack, none of which the harness compares.
Two examples.
pk(A)has sat_witness_elements 2 where Core counts 1: the vector counts the witness script, which the BIP's 100-element rule excludes. In the Tapscript table,thresh(1,pk(A),s:pk(B))has sat_size 132, two 66-byte signatures, and no valid witness is that large. Two valid signatures make the count 2, not 1. Under BIP342 a failed non-empty signature fails the script, so the key that does not sign gives an empty signature. The largest witness is then 67, which is what Core gives. Other differences come from dissatisfactions Core does not count, such as a hash's.Could the Files table say what each of these columns counts, or could the harness skip sat_witness_elements and sat_size as it does op_count and exec_stack?
- guggero force-pushed on Oct 6, 2026
-
guggero commented at 12:08 PM on October 6, 2026: contributor
Thanks for running the vectors against
btclib, that's very useful independent validation.There were two separate issues:
threshwas a bug. The extraction sized k+1 satisfied sub expressions instead of k (fixed upstream in rust-bitcoin/rust-miniscript#1040). The regenerated tables now give 67 forthresh(1,pk(A),s:pk(B)), the same as you got.- The rest is how the columns are counted. They follow
rust-miniscript:sat_witness_elementsadds one for the witness script, andop_count/sat_sizemaximize over all satisfactions, malleable ones included. Core never dissatisfies a hash fragment. Changing only that rule in the Go implementation reproduces your figures: 9.6% ofopcodes.txtops and 20–22% ofsat_sizerows.
I went with your first suggestion and updated the PR:
- A new "Resource Columns" section defines each column and states the difference from Core.
exec_stackand the Tapscriptop_countare marked informative only. - New
limits[_tap].txthas within/over vectors at each limit (201 ops, 3,600 bytes, 100 witness elements, 1,000 Tapscript stack elements), with no hash fragments. Core and the Go implementation agree on all ten verdicts.rust-miniscriptrejects the 100-elementwithinvector, because it counts the witness script against that limit. - The harness now compares types, op counts and the limit verdicts. It skips only
exec_stackand the Tapscriptop_count. - Everything now comes from unmodified
rust-miniscriptmaster (698b97f).
-
fametrano commented at 10:14 PM on October 6, 2026: contributor
ACK 217afc1416d1d51f97ac3c3b1c70a306ce7ce242
I ran the vectors through btclib-wallet's miniscript module (not redeem.json, and not the Go harness). Parsing, types, scripts and the ten limit verdicts agree. The resource columns differ only by the two rules the new section describes, apart from
exec_stackand the Tapscriptop_count, which the section already sets aside.Two wording nits. The Files table says every line of
conflict_from_alloy.txtmixes timelock kinds on one path, but 187 of the 1,773 do not, for exampleand_v(v:multi(2,A,B,C),andor(multi(2,D,E,F),after(500000001),after(1))), whichprops_from_rust.tsvmarksmixed_timelocks=false. Andedge_cases.txtis not "the only hand-written file":limits.txtandlimits_tap.txtare too. - guggero force-pushed on Oct 7, 2026
-
guggero commented at 9:07 AM on October 7, 2026: contributor
Thanks for the feedback, @fametrano! I've updated the text to fix the nits you mentioned.
-
fametrano commented at 8:45 PM on October 7, 2026: contributor
reACK c923f2e961c0bae99a7b777cc15bb91601ed3bd9
Only
bip-0379.mdandmain.gochanged since 217afc1, and the vector files are identical, so my earlier run still holds. Both nits are fixed, and the newconflictInsane = 1586is the 1,773 lines minus the 187 sane ones I found. -
bip379: add test vectors from rust-miniscript 91fdd5d3aa
- guggero force-pushed on Nov 10, 2026
-
jonatack commented at 4:09 PM on November 10, 2026: member
cc authors @sipa, @apoelstra, @sanket1729, @darosior, @achow101 for acceptance
-
sanket1729 commented at 7:53 PM on November 10, 2026: contributor
Approach and concept ACK.
-
apoelstra commented at 10:11 PM on November 10, 2026: contributor
concept ACK from me
-
fametrano commented at 11:29 PM on November 10, 2026: contributor
reACK 91fdd5d3aa9e9131c4109cf84891241d8dce7f3a
Only
go.modandgo.sumchanged since c923f2e. The vectors,main.goandbip-0379.mdare identical, so my earlier run still holds. -
murchandamus commented at 1:51 AM on November 14, 2026: member
I see that you have conceptual support from Pieter, Sanket, and Andrew, but it seems like at least Pieter’s PR is not yet merged. I also see that Andrew said the markdown changes look good to him. @guggero: What’s your read on the situation, should this BIP update wait until the implementation updates have landed to ensure the BIP update is solid, or could it go in independently?
If the former, perhaps we could turn this into a draft until the relevant implementation PRs land. If the latter, could we perhaps get more obvious acceptance signals from the owners than Concept ACKs?
-
guggero commented at 8:50 AM on November 15, 2026: contributor
I would go out on a limb here and say that this can probably be merged independently.
The main discussion item of this PR (the type of malleable expressions) was resolved by #2267, and the vectors follow that. They agree with the current BIP text and with
rust-miniscript@698b97f(apart from the onelimits.txtvector it rejects, as documented in Provenance).Bitcoin Core still reports
s,fandeon malleable expressions. Once those are dropped, as #2267 says an API should, Core agrees with every type in the vectors, so this is not a bug and can be handled in the test code. Pieter's PR is independent of that. It makes Core's typing rules match the BIP's tables literally, but with that rule applied it doesn't change Core's results on these vectors. So neither PR has to wait for the other.EDIT: corrected the part about bitcoin/bitcoin#36028 after running the test vectors through Core. Added the cross-check table(s).
<details>
<summary>Cross-check between different implementations (LLM-generated)</summary>
Summary
- All three implementations agree with every vector on parsing and rejection, sanity,
timelock mixing,
script_size,non_malleable,requires_sig, the script encoding in both contexts, and theredeem.jsonspends. The only exception is one limit vector in rust-miniscript (item 6 below). - Bitcoin Core and btclib-wallet produce identical values for every resource column, and so they fail on exactly the same rows. Every one of those rows is a difference in how a quantity is counted, and the BIP text already describes it. No vector is wrong.
- Bitcoin Core also reports
s,fandeon malleable expressions. The vectors leave them out, as #2267 asks of APIs. Once Core's types drop them, Core and btclib-wallet fail exactly the same 16,573 vectors, with the same values. - bitcoin/bitcoin#36028 doesn't change any of this. Applied on current master, it
leaves the results identical once
s/f/eare dropped. Comparing raw types, it adds 558 failures. Details are under item 1.
What was compared
Source Version Test vectors this PR, 91fdd5d3BIP text this PR, 91fdd5d3rust-miniscript 698b97f, the commit named in ProvenanceBitcoin Core master a527a0077a0f, and the same with bitcoin/bitcoin#36028 (2631ece7b5) applied on topbtclib-wallet cab4c7b(main)Each implementation read every expression with its own parser, with the keys substituted as the Conventions section describes. These were the checks:
- Types: compared as sorted letters.
- Resource columns: every column of
props_from_rust[_tap].tsvand the<ops>ofopcodes.txtwere compared exactly,exec_stackand the Tapscriptop_countincluded. - Limit vectors: a
withinvector has to parse as sane, and anovervector has to be rejected. redeem.json: each implementation built the witness with its own non-malleable satisfier, signed withSIGHASH_ALL, and the spend of the P2WSH output was executed. rust-miniscript used libbitcoinconsensus, Bitcoin Core its own interpreter with the standard flags, and btclib-wallet its own script engine.
Results per file
A ✓ means every vector of the file passes. Otherwise the cell gives the number of failing vectors.
File Vectors rust-miniscript Core Core + #36028 btclib-wallet valid_from_alloy.txt5,896 ✓ ✓ ✓ ✓ valid_8f1e8_from_alloy.txt3,492 ✓ 1,732 (type) 2,070 (type) ✓ malleable_from_alloy.txt7,024 + 7,024 not sane ✓ 7,024 (type) 7,024 (type) ✓ conflict_from_alloy.txt1,773 + 1,586 not sane ✓ ✓ ✓ ✓ edge_cases.txt42 ✓ ✓ ✓ ✓ opcodes.txt18,185 ✓ 9,192 (8,756 type, 1,741 ops) 9,412 1,741 (ops) invalid.txt5,574 ✓ ✓ ✓ ✓ limits.txt8 1 ✓ ✓ ✓ limits_tap.txt2 ✓ ✓ ✓ ✓ props_from_rust.tsv8,198 ✓ 8,151 8,151 8,151 props_from_rust_tap.tsv6,728 + 1,470 PARSE_ERR✓ 6,681 6,681 6,681 scripts_from_rust.tsv8,198 ✓ ✓ ✓ ✓ scripts_from_rust_tap.tsv6,728 + 1,470 ERR✓ ✓ ✓ ✓ redeem.json12 + 34 ✓ ✓ ✓ ✓ Failing, of 81,860 1 32,780 33,338 16,573 Here is what makes the props rows fail, counted per column. Core (with or without #36028) and btclib-wallet have the same counts:
Column props_from_rust.tsvprops_from_rust_tap.tsvCause op_count691 (8.4%) 5,004 (4,883 multi_a+ 121 hash)items 4 and 5 sat_witness_elements(after adding one, see item 3)1,345 (16.4%) 1,209 (18.0%) item 4 sat_size1,623 (19.8%) 1,474 (21.9%) item 4 exec_stack8,015 6,660 item 5 everything else 0 0 Differences
# Topic Vectors and BIP text rust-miniscript Bitcoin Core btclib-wallet Proposed resolution 1 s/f/ein the type of a malleable expressionleft out; the BIP says an API should report them false left out reports them left out Core: drop them when comparing against the vectors. BIP: say so in Conventions. 2 sat_witness_elementscounts the witness scriptyes, "plus one" yes no no BIP: explain why the column is one higher, and that such implementations compare their count plus one. 3 Malleable satisfactions in op_count,sat_witness_elementsandsat_sizecounted, as the BIP describes counted not counted not counted BIP: make the summary sentence say exactly which columns agree. 4 Tapscript op_countofmulti_a0; the BIP says the column has no meaning 0 counts the opcodes counts the opcodes BIP: name the difference. Don't compare this column. 5 exec_stackrust-miniscript's estimate, as the BIP describes same peak stack size including the witness same as Core BIP: name what Core reports instead. Don't compare this column. 6 limits.txtwitness_elementswithin100 elements, the witness script excluded rejects it accepts it accepts it rust-miniscript: fix the off-by-one. The existing note in Provenance stays until then. 1.
s,fandeon malleable expressions, and bitcoin/bitcoin#36028#2267, which was merged, added this to the Malleability section: "Implementors of APIs which unconditionally return values for these properties should always return false for malleable expressions." The vectors follow it, and so do rust-miniscript (since rust-bitcoin/rust-miniscript#1037) and btclib-wallet. Bitcoin Core's type computation still reports these letters on malleable expressions. For example,
andor(jc:pk_k(A),after(500000001),0)has typedoBin the vectors, but Core reportsBodes. That accounts for every type failure in Core: 1,732 lines ofvalid_8f1e8_from_alloy.txt, all 7,024 ofmalleable_from_alloy.txtand 8,756 ofopcodes.txt. Once Core's type dropss,fandewhenevermis absent, Core agrees with every type in every file.bitcoin/bitcoin#36028 applies cleanly to current master, and Core's own
miniscript_testsstill pass with it. It changes four rules to match the BIP's tables literally:d:always getsoande;or_balways getse;threshgetsewhen all its children ares.
Each of these changes only the type of an expression that is invalid or malleable anyway. On the vectors:
- Comparing raw types, Core with #36028 fails more vectors: 33,338 instead of
32,780. All 249 expressions whose type changes are malleable, and they all gain an
ethat the vectors leave out. For example,and_b(multi(2,A,B,C),a:or_b(j:multi(2,D,E,F),a:multi(2,G,I,J)))goes fromBndustoBndues, while the vectors sayBdnu. - With
s/f/edropped from malleable types, Core produces exactly the same results with and without #36028.
So #36028 neither resolves nor causes any difference with the vectors. What makes Core agree is the rule from #2267 (malleable means no
s,fore). This can be applied in Core's test code, as sipa suggested in #2267 ("the actual logic implementing this can be pushed to the tests, so no internal code changes are needed"), or in Core's type accessor. #36028 is still useful on its own merits, because it makes Core's raw typing rules read like the BIP's tables. But this PR doesn't need to wait for it.2.
sat_witness_elementsis one higher than Core's countThe column is rust-miniscript's
max_satisfaction_witness_elements. It counts the witness script as one of the witness elements, in both contexts. Core'sGetStackSize()and btclib-wallet'smax_stack_itemscount only the elements that satisfy the script, which is also the number the 100-element P2WSH standardness limit applies to. Forpk(A), the witness is<sig> <script>, so the column says 2, while Core and btclib-wallet say 1.So every row that has a satisfaction is exactly one higher than Core's value. An implementation that counts like Core has to add one to its own count before comparing. The BIP already says "plus one", but not why, or what such an implementation should do; the proposed wording adds both. After adding one, the rows that still differ are the ones described in item 3.
3. Malleable satisfactions in
op_count,sat_witness_elementsandsat_sizeAs the Resource Columns section says, these columns are the maximum over every satisfaction the fragment rules allow, malleable ones included. One such satisfaction dissatisfies a hash fragment with a 32-byte value that is not the preimage. Core and btclib-wallet count only non-malleable satisfactions, and those never dissatisfy a hash fragment. Every differing row contains a hash fragment, Core and btclib-wallet are always the lower value, and the two agree with each other in every row.
opcodes.txt:or_d(c:pk_k(A),or_d(sha256(926a…),multi(2,B,C,D)))has<ops>15, but Core and btclib-wallet say 12. The vectors count the path that dissatisfiespk_k(A)andsha256, then executes theCHECKMULTISIGwith its 3 keys. Without dissatisfyingsha256,multiis never reached.props_from_rust.tsv:or_b(sha256(926a…),ac:pk_k(A))hassat_size106, a 73-byte signature plus 33 bytes of non-preimage. Core and btclib-wallet say 34, the 33-byte preimage plus an empty dissatisfaction ofpk_k(A).
The rates match what the BIP says ("roughly one in ten op counts and one in five
sat_sizevalues"):- op counts: 8.4% of
props_from_rust.tsvand 9.6% ofopcodes.txt; sat_size: 19.8% and 21.9%.
The one sentence I'd change is "an implementation that counts like Core reproduces every other column". It doesn't hold for
exec_stackor for the Tapscriptop_count(items 4 and 5). It also doesn't say thatsat_witness_elementskeeps differing in these rows after adding one (16.4% and 18.0%).4. Tapscript
op_countThe column counts a
multi_aas no ops at all, and the BIP already says the column has no meaning in Tapscript. Core and btclib-wallet count its opcodes:multi_a(1,A)is 0 in the vectors and 2 in both of them. That accounts for 4,883 rows. The remaining 121 rows of the 5,004 are the hash-fragment rows of item 3.main.goalready skips this column, and other implementations should skip it too.5.
exec_stackThe column is rust-miniscript's estimate of how many elements the script pushes above its witness, and the BIP says so. Core's
GetExecStackSize()and btclib-wallet'smax_exec_stack_itemsreport the peak stack size during execution, witness elements included, which is what the 1,000-element limit bounds. For example,and_b(after(1),a:and_b(after(1),ac:pk_k(A)))is 3 in the vectors and 4 in both of them. No offset maps one quantity onto the other: even after subtracting the witness elements, the difference ranges from −2 to +2 in P2WSH and from −4 to 0 in Tapscript.main.goalready skips this column, and other implementations should skip it too.6. rust-miniscript rejects the
witness_elementswithinvectorIn
limits.txt,withinis a chain ofand_v(v:pk(K1),…)with 100 keys, so its satisfaction has 100 elements.overhas 101 keys. The BIP's Resource Limits section, like Core's policy, excludes the witness script from the 100-element limit. However, rust-miniscript'sSegwitv0::check_local_policy_validitycomparesmax_satisfaction_witness_elements(), which includes the script, against 100. It therefore rejects a satisfaction with exactly 100 elements. The code is unchanged on current master (d57bb31). Core and btclib-wallet acceptwithinand rejectover. The vector is correct, and the BIP already documents this behaviour in Provenance. The fix belongs in rust-miniscript: compare the count minus one.</details>
- All three implementations agree with every vector on parsing and rejection, sanity,
timelock mixing,
-
apoelstra commented at 2:38 PM on November 15, 2026: contributor
Cross-check between different implementations (LLM-generated)
For finding 2 (rust-miniscript
max_satisfaction_witness_elementscounts the witness script as a witness element) the bot proposes just documenting the difference.But I think we should fix rust-miniscript to not count the witness script.
Finding 6 is related (when checking limits, rust-miniscript counts the witness script against the 100 limit), and there the bot suggests fixing rust-miniscript, which I agree with.
Both of these seem to stem from the same confusion on my part about whether the witness script counts as a witness element.
The other four findings I agree are uninteresting and (at most) just need a mention that the implementations differ.
-
murchandamus commented at 11:05 PM on November 16, 2026: member
Okay, thanks for the explanation. Sounds like this is ready to go.
- murchandamus merged this on Nov 16, 2026
- murchandamus closed this on Nov 16, 2026
- murchandamus removed the label Pending acceptance on Nov 16, 2026
-
murchandamus commented at 11:11 PM on November 16, 2026: member
I noticed that BIP379: Miniscript was still in Draft status, but clearly multiple implementations support it on Mainnet. I therefore created a follow-up to advance it to Deployed in #2359.