Bitcoin Guides

Bitcoin

Explore other guides

Advanced

What is Bitcoin Miniscript and how does it work?

Released in August 2019 by Bitcoin developer Pieter Wuille, Bitcoin Miniscript aims to improve Bitcoin’s programmability without compromising security through the addition of an improved scripting compiler.

The goal is to make programmers’ lives easier and to allow for more/better functionality.

Bitcoin’s lack of programmability

One of the key security aspects of Bitcoin (besides its massive energy requirements and vast decentralised network) is the fact it was developed in a non-Turing complete way, meaning it lacks programmability and doesn’t run loops or complex programs.

The less programmability a program has, the less chance you have of encountering errors, bugs, or issues.

In addition, it’s harder to break the code given less people know how to code in it.

As Bitcoin developer and educator Jimmy Song has said during his weekly podcast, ‘Off Chain with Jimmy Song’:

“The smart contract language differs from Ethereum’s Solidity language, because while Ethereum makes it possible to write many more types of smart contracts, Miniscript actually reduces the possibilities.”

Bitcoin Miniscript

As explained by Blockstream on GitHub – a company focused on improving Bitcoin and creating products over the Bitcoin network – there are some advantages to using a more user-friendly scripting language:

“Miniscript is a language for writing (a subset of) Bitcoin Scripts in a structured way, enabling analysis, composition, generic signing, and more.”

Blockstream adds that Bitcoin is designed for the implementation of spending conditions consisting of various combinations of signatures, hash locks, and time locks. Yet despite being limited in functionality, it is still highly nontrivial to:

  • Given a combination of spending conditions, find the most economical script to implement it.
  • Given two scripts, construct a script that implements a composition of their spending conditions (for example, a multisig where one of the “keys” is another multisig).
  • Given a script, find out what spending conditions it permits.
  • Given a script and access to a sufficient set of private keys, construct a general satisfying witness for it.
  • Given a script, be able to predict the cost of spending an output.
  • Given a script, know whether particular resource limitations like the ops limit might be hit when spending.

 

Blockstream concludes that Miniscript functions as a representation for scripts that makes the operations listed above possible. It has a structure that allows composition and is easy to statically analyse for various properties like the spending conditions, correctness, security properties, and malleability.

Finally, compatible scripts can easily be converted to Miniscript form – avoiding the need for additional metadata.

Disclaimer: The views and opinions expressed by the author should not be considered as financial advice. We do not give advice on financial products.