Miniscript

From claude-dev-suite/claude-dev-suite · View interactive version

Miniscript is an AI agent skill from the GitHub repository claude-dev-suite/claude-dev-suite. Miniscript: structured subset of Bitcoin Script with fragment types, satisfaction analysis, malleability resistance. Policy → Miniscript → Script compilation. Used in descriptors (wsh + tr) and modern wallets to express spending conditions safely. USE WHEN: composing complex spending conditions, der

How to use this skill

Skill file

Miniscript

Miniscript is a structured subset of Bitcoin Script with these

properties:

  1. Composable — fragments combine cleanly, no parser ambiguity.
  2. Analyzable — every miniscript has a known correctness, malleability,

and resource analysis.

  1. Satisfiable — given a set of available signatures/preimages,

you can derive the cheapest valid witness automatically.

  1. Round-trip with Script — every miniscript has a unique Script

serialization and (almost) every Script can be parsed as miniscript.

Two flavours

legacy multisig (OP_CHECKMULTISIG).

OP_CHECKSIGADD instead of OP_CHECKMULTISIG. Different fragment

semantics in some places (different limits, no OP_CHECKMULTISIG).

Policy language (compiler input)

Higher-level than miniscript; expresses the what, not the how.

pk(K)               # signature from K required
pkh(K)              # legacy hash-locked key
older(n)            # nSequence relative timelock (BIP112)
after(n)            # nLockTime absolute timelock (BIP65)
sha256(H), hash256(H), ripemd160(H), hash160(H)   # preimage reveal
and(A, B)           # both A and B
or(A, B)            # either A or B
or_b(A, B), or_d(...), or_c(...), or_i(...)       # variants
thresh(k, A1, ..., An)   # k of n
multi(k, K1, ..., Kn)    # threshold sig (uses native multisig in legacy)

Probabilities can be annotated: or(99@A, 1@B) makes A the dominant

spend path; the compiler uses this for shape choice (which branch

goes where in the taptree, which fragment is cheaper).

Miniscript fragments (selection)

Each fragment has a type in {B, V, K, W} and modifier letters

{z, o, n, d, u}:

Modifiers describe properties (z = no inputs consumed, o = consumes

exactly one, n = "non-zero" satisfaction, d = "dissatisfiable",

u = unique satisfaction).

Some example fragments:

Compilation example

Policy:

or(99@pk(Hot), and(pk(Cold), older(1008)))

Compiler emits a miniscript like:

or_d(pk(Hot), and_v(v:pk(Cold), older(1008)))

Translates to Script (legacy):

<Hot> CHECKSIG
IFDUP NOTIF
  <Cold> CHECKSIGVERIFY
  <1008> CSV
ENDIF

The same policy in tr() lands in the script tree as a tapscript

fragment and is reachable via the script-path. Key-path stays free for

the cooperative case (e.g., MuSig2(Hot, Cold)).

Satisfaction algorithm

Given a miniscript M and a set of available `(sig, preimage,

timelock-OK)` flags, the satisfier returns:

Crucial for fee-optimal spending: if the witness has multiple OR

branches, the satisfier picks the one that fits available data.

Resource analysis

Each fragment has known:

Wallets use this to estimate fees accurately even before the script

is satisfied.

Tapscript miniscript differences

unchanged), but witness sizing differs.

Implementations

Common bugs

isn't valid — won't satisfy correctly. Always go via the policy

compiler.

annotations → suboptimal taptree weighting.

See also

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.