Skip to content

fix(compile): compile only for the requested script context - #317

Open
vadim-anfv wants to merge 1 commit into
bitcoindevkit:masterfrom
vadim-anfv:fix/compile-per-context
Open

vadim-anfv wants to merge 1 commit into
bitcoindevkit:masterfrom
vadim-anfv:fix/compile-per-context

Conversation

@vadim-anfv

Copy link
Copy Markdown
Contributor

The policy is compiled for all three script contexts one after another, before --type is looked at, and any of those failing aborts the command. So a policy that is valid for the type you asked for is rejected because it is invalid for one of the other two.

Here a 9-of-16 multisig is compiled with --type tr and fails on the legacy context: CHECKMULTISIG takes at most 15 keys, and what the compiler falls back to goes past MAX_SCRIPT_ELEMENT_SIZE, the 520-byte consensus limit. Taproot has no such limit.

$ cargo run --all-features -- compile "thresh(9,pk(a),pk(b),pk(c),pk(d),pk(e),pk(f),pk(g),pk(h),pk(i),pk(j),pk(k),pk(l),pk(m),pk(n),pk(o),pk(p))" --type tr

thread 'main' panicked at miniscript-12.3.7/src/policy/compiler.rs:506:52:
Terminal creation must always succeed: ContextError(MaxRedeemScriptSizeExceeded)

The fix moves the compilation into the matching branch, so only the requested context is compiled.

Changelog notice

  • Fixed compile rejecting policies that are valid for the requested script type

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

Bugfixes:

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.08%. Comparing base (5afbc8a) to head (eb8ca3f).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #317      +/-   ##
==========================================
+ Coverage   57.78%   58.08%   +0.30%     
==========================================
  Files          22       22              
  Lines        3733     3724       -9     
==========================================
+ Hits         2157     2163       +6     
+ Misses       1576     1561      -15     
Flag Coverage Δ
rust 58.08% <100.00%> (+0.30%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Compiling for all three contexts let the narrowest one reject a policy
that is valid for the requested type: a 9-of-16 multisig, fine as
taproot multi_a, failed even for --type tr because legacy hit the
520-byte consensus limit on script elements.
@vadim-anfv
vadim-anfv force-pushed the fix/compile-per-context branch from c626394 to eb8ca3f Compare September 17, 2026 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant