Miniscript

A structured dialect of Bitcoin Script that can be analysed and signed generically.

Basically

Miniscript lets you write and combine clear rules for spending Bitcoin. Wallet software can check those rules and prepare signatures without running any code.

Key Takeaways

  • Miniscript is a structured form of Bitcoin Script that makes spending conditions readable, composable, and statically analysable. You can determine the maximum witness size, required signers, and timelock constraints without executing anything.
  • Miniscript uses three layers: a human-friendly policy language compiles to Miniscript, which compiles to raw Bitcoin Script. Wallets can therefore reason about scripts generically without understanding every opcode combination.
  • Miniscript works with output descriptors and Taproot to create portable, interoperable wallet policies. Any compatible wallet can spend from a Miniscript-described output without custom signing logic.

What Is Miniscript?

Miniscript is a language for writing Bitcoin spending conditions so software can analyse them automatically. Raw Bitcoin Script is a stack-based language with over 100 opcodes, but finding which keys are needed or the maximum transaction weight can require simulating every execution path. Miniscript defines a structured subset of Script, so software can calculate these properties directly from the expression tree.

Pieter Wuille, Andrew Poelstra, and Sanket Kanjalkar developed Miniscript from work at Blockstream to formalise the most common Script patterns. Miniscript does not create a new scripting system and maps one-to-one onto valid Bitcoin Script, so every expression compiles to Script the Bitcoin network already understands. Its design limits the possibilities enough to make analysis tractable.

Miniscript gives wallets and applications a principled framework for UTXOs with non-trivial spending conditions, replacing ad-hoc Script construction. You can use it for multisig setups, time-locked vaults, inheritance schemes, and other cases where multiple parties or conditions control access to funds.

How It Works

Miniscript uses three layers, each with a different purpose. The layers turn a human-readable policy into an enforceable on-chain script.

Layer 1: Policy Language

The policy language is what humans write. It expresses spending conditions through intuitive combinators that describe how keys, hash locks, and time locks fit together.

The policy language stays deliberately simple, with keys (pk), hash locks (sha256, hash256), time locks (after, older), and logical combinators (and, or, thresh). A compiler turns the policy into an optimised Miniscript expression.

Layer 2: Miniscript

Miniscript is the intermediate representation between the conditions you want and their execution in Script. Each Miniscript fragment has a defined type that describes how it behaves on the Script stack.

The types enforce composition rules and stop you combining fragments in ways that would produce invalid Script. The type system catches errors at compile time rather than at spend time, which is Miniscript’s core safety guarantee.

Layer 3: Bitcoin Script

Each Miniscript fragment translates deterministically to Bitcoin Script opcodes. The expression multi(2, A, B, C) therefore has a fixed Script representation.

The deterministic mapping and known stack behaviour let wallets calculate the exact witness size before signing. You get accurate fee estimates for complex spending conditions, which raw Script analysis cannot provide reliably.

Static Analysis

Miniscript’s structure makes several forms of static analysis practical. Software can inspect spending conditions without executing them, which is impractical with raw Script.

Output Descriptors and Wallet Integration

Output descriptors make Miniscript most useful by giving wallets a standard way to describe address generation, including key derivation paths. A Miniscript-aware descriptor fully specifies both the spending policy and the key derivation.

Any wallet that supports Miniscript descriptors can import the string, understand the spending policy, derive the correct addresses, construct valid PSBTs, and determine which signatures are needed. You can move complex wallet configurations between compatible wallets without vendor lock-in.

Taproot Integration

Taproot (BIP 341) introduced a tree-based script structure that commits multiple spending paths to a single output. Miniscript now supports Tapscript, the script version used inside Taproot trees, making the combination especially useful for outputs with several spending conditions.

The related guide, Taproot and Schnorr Signatures Explained, looks at how Taproot restructures Bitcoin transactions. It gives you a deeper look at the transaction structure behind these spending paths.

Multisig Wallets

Traditional multisig requires all participating wallets to agree on a single script template. Adding a timelock recovery path or changing the threshold means writing custom Script and hoping every wallet can sign it. Miniscript standardises the setup: a 2-of-3 with a time-locked recovery key becomes a descriptor string that any compatible wallet can handle.

Inheritance and Estate Planning

Miniscript enables time-gated recovery policies. Your primary key can control the funds normally, while a trusted family member or attorney can recover the coins with an alternative key after a year of inactivity. Consensus enforces the timelock, not a third party.

Institutional Custody

Enterprises managing Bitcoin often need complex governance, including board approval thresholds, emergency recovery paths, and compliance-mandated spending limits. Miniscript lets them formally specify these policies, analyse them for correctness, and implement them across different signing devices without custom firmware.

Vault Constructions

Vaults restrict how quickly funds can move, giving you a window to detect and respond to theft. Miniscript can express vault-like policies with timelocks and multi-key requirements, while static analysis guarantees that unexpected execution paths cannot bypass the policy.

Wallet and Tooling Support

Miniscript support has been growing across the Bitcoin ecosystem. Support still differs between wallets and signing devices, so you need to check the tools you plan to use.

Script Size Limits

Complex Miniscript policies can produce large scripts. Bitcoin consensus limits script sizes to 10,000 bytes for P2WSH and 10,000 bytes per Tapscript leaf, and it also constrains stack element counts. Miniscript’s static analysis can flag policies that approach or exceed these limits before use, but you must remember that not every conceivable policy fits within consensus rules.

Fee Implications

Larger scripts create larger witnesses, which increase transaction fees. The worst-case witness size, with all possible signers providing signatures and all hash preimages revealed, determines the fee the sender should reserve. Miniscript makes this cost transparent and calculable, but complex policies always cost more to spend than simple single-key outputs.

Tooling Maturity

Miniscript support is expanding, but not all wallets and signing devices support it yet. You must ensure that your signing infrastructure can satisfy the spending conditions before creating Miniscript-based outputs. Importing a Miniscript descriptor into a wallet without full support can leave funds visible but unspendable from that wallet.

Policy Correctness

Miniscript guarantees that a policy compiles to valid, analysable Script, but it cannot guarantee that the policy matches your intentions. A 2-of-3 threshold with the wrong keys or an incorrect timelock value will compile and function perfectly while enforcing the wrong conditions. Careful review before committing funds is essential, especially for high-value or irreversible custody arrangements.

The glossary entry is for informational purposes only and does not constitute financial or investment advice. Always do your own research before using any protocol or technology.

0

← All 1876 glossary terms