Home › Glossary › Miniscript

Miniscript

Also called: Bitcoin Miniscript, miniscript policy, policy language, BIP379.

Miniscript is a structured way to write Bitcoin Script, specified in BIP 379, that makes complex spending conditions easy to analyze, combine and sign.

Miniscript is a language for writing a subset of Bitcoin Script in a structured, composable way. Instead of hand-assembling opcodes, you combine named fragments such as pk(), older() and thresh(), and each one maps directly onto real script.

Example

wsh(or_d(pk(A),and_v(v:pk(B),older(4032))))

Key A can spend at any time. Key B can spend only once the coins have sat unspent for 4,032 blocks (about four weeks), because older() compiles to OP_CHECKSEQUENCEVERIFY. Policies like this are used for inheritance and recovery setups.

What it makes possible

BIP 379, by Pieter Wuille, Andrew Poelstra, Sanket Kanjalkar, Antoine Poinsot and Ava Chow, starts from problems that are hard with raw script: finding the cheapest script for a policy, combining policies (a multisig where one "key" is itself another multisig), working out what an existing script allows, building a valid witness for any script given the right keys, and predicting the cost of spending. Because every fragment has typed, known behavior, software can check these properties automatically, including whether a third party could malleate the witness.

Where it is used

Miniscript covers P2WSH and tapscript, with small differences between them (multi() in P2WSH, multi_a() in tapscript). It is written inside the wsh() (BIP 382) and tr() (BIP 386) output descriptors, so for users it is an extension of the descriptor language rather than a separate one. Wallets and hardware signers that understand Miniscript can sign for custom policies without bespoke code for each one. See the output descriptors guide for how it fits together.

BIPs that define Miniscript

  • BIP 379: Miniscript: Draft. Miniscript is a structured way of writing Bitcoin scripts, the small programs that define how coins can be spent. It lets software analyze spending conditions, combine them safely, and sign for them…
  • BIP 382: Segwit Output Script Descriptors: Deployed. Defines the descriptor functions for native SegWit outputs, covering both single-key addresses and script-based ones. With these, wallets can precisely describe and back up SegWit wallets, including…
  • BIP 386 (Taproot descriptors): tr() Output Script Descriptors: Deployed. Defines the descriptor function for Taproot outputs, combining a main key with an optional tree of alternative spending conditions. This gives wallets a standard way to describe, back up and recover…
  • BIP 380: Output Script Descriptors General Operation: Deployed. Output script descriptors are a compact text language for describing exactly which addresses a wallet owns and how they are spent. This document defines their general syntax and checksum, giving…
  • BIP 342 (Tapscript): Validation of Taproot Scripts: Deployed. Specifies Tapscript, the updated scripting rules used when a Taproot output is spent through one of its hidden alternative conditions. It switches signature checks to Schnorr, removes some old…

Related terms

  • Output descriptor: An output descriptor is a short text string that says exactly which scripts and addresses a wallet uses: script type, keys and derivation paths.
  • Bitcoin Script: Bitcoin Script is the simple stack-based language that sets the conditions for spending each output, such as which signatures or timelocks are required.
  • P2WSH: P2WSH (Pay to Witness Script Hash) is the native SegWit output for scripts such as multisig: a 32-byte script hash with a 62-character bc1q address.
  • Tapscript: Tapscript is the script language for Taproot script paths (BIP 342): Bitcoin Script with Schnorr signature checks, OP_CHECKSIGADD and OP_SUCCESS hooks.
  • Timelock: A timelock is a rule that stops bitcoin from being spent until a set block height or time, or until the coin has aged a set amount since it confirmed.

Learn more

Guides