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

fix(compile): compile only for the requested script context#317
vadim-anfv wants to merge 1 commit into
bitcoindevkit:masterfrom
vadim-anfv:fix/compile-per-context

Conversation

@vadim-anfv

Copy link
Copy Markdown

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

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.
@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 57.75%. Comparing base (e7223e5) to head (c626394).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #317      +/-   ##
==========================================
+ Coverage   57.45%   57.75%   +0.30%     
==========================================
  Files          22       22              
  Lines        3695     3686       -9     
==========================================
+ Hits         2123     2129       +6     
+ Misses       1572     1557      -15     
Flag Coverage Δ
rust 57.75% <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.

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