Skip to main content

Miniscript | Bitcoin Glossary | Mapping Bitcoin

Miniscript

Desarrollo

A structured representation of Bitcoin Script that enables analysis, composition, and generic signing of spending conditions. Miniscript makes it easier to reason about complex scripts, verify their correctness, and build interoperable wallet software.

Overview

Miniscript is a language for writing Bitcoin spending conditions in a structured, analyzable way. Developed primarily by Pieter Wuille, Andrew Poelstra, and Sanket Kanjalkar, Miniscript sits between high-level policy descriptions and raw Bitcoin Script. It makes it possible to automatically analyze scripts for correctness, compute signing requirements, and estimate transaction sizes — tasks that are extremely difficult with raw Script.

Architecture

┌─────────────────────────────────┐
│    Policy Language (high-level)  │
│    e.g., thresh(2, pk(A),        │
│           pk(B), pk(C))          │
├─────────────────────────────────┤
│    Miniscript (structured)       │  ← Analysis happens here
│    e.g., thresh(2, pk_k(A),      │
│           s:pk_k(B), s:pk_k(C))  │
├─────────────────────────────────┤
│    Bitcoin Script (raw opcodes)  │
│    e.g., <A> OP_CHECKSIG ...     │
└─────────────────────────────────┘

Key Benefits

  • Correctness verification: Automatically determine whether a script is valid, non-malleable, and consensus-safe
  • Spending analysis: Determine all possible ways to satisfy a script and which keys or conditions are needed for each
  • Fee estimation: Calculate the maximum witness size, enabling accurate fee estimation before signing
  • Composition: Safely combine multiple spending conditions (e.g., timelocks with multisig) without subtle bugs

Use Cases

Miniscript is particularly valuable for complex custody setups, such as a vault that requires 2-of-3 signatures normally but allows a single recovery key after a timelock. Without Miniscript, constructing and verifying such scripts would require deep Script expertise and manual auditing.

Common Misconceptions

Miniscript is not a replacement for Bitcoin Script — it is a structured subset of it. Not all valid Bitcoin Scripts can be expressed as Miniscript, but all Miniscripts compile to valid Bitcoin Script. It focuses specifically on the subset of scripts that are useful for spending conditions.