Proposed BIP text for Miniscript

Proposed BIP text for Miniscript

Original Postby Ava Chow

Posted on: May 16, 2024 19:21 UTC

Miniscript is a language designed to write Bitcoin Scripts in a structured manner, facilitating tasks such as analysis, composition, generic signing, and more.

It addresses the challenges posed by Bitcoin Script's stack-based nature, which includes various edge cases and limitations. Miniscript aims to simplify finding economical scripts for given spending conditions, composing scripts from multiple conditions, analyzing script permissions, constructing general satisfying witnesses, predicting cost implications, and understanding resource limitations during script execution.

The document detailing Miniscript, currently in draft status, was created on October 10, 2023, and is an informational BIP (Bitcoin Improvement Proposal). Authored by notable figures including Pieter Wuille and Andrew Poelstra, it specifies how Miniscript can be applied to both P2WSH (BIP143) and Tapscript (BIP342) scripts, highlighting minor variations between these applications. The Miniscript translation table maps script fragments to their Bitcoin Script equivalents, supporting both syntactic sugar elements and complex conditional structures. This mapping facilitates the use of Miniscript in script descriptors like those defined in BIP 382 and BIP 386, with specific restrictions on key expressions relevant to each context.

The type system introduced categorizes Miniscript expressions based on their functional characteristics and interaction requirements. Expressions are classified into basic types—Base (B), Verify (V), Key (K), and Wrapped (W)—each with associated modifiers that indicate additional properties such as argument count, satisfaction conditions, and timelock considerations. This system enables precise composition and analysis of scripts, ensuring that only compatible expressions are combined. Furthermore, the document outlines Miniscript's approach to malleability, defining properties that help assess whether a script can be satisfied in a non-malleable manner. Malleability considerations are crucial for maintaining transaction integrity and preventing third-party alterations.

Miniscript also provides mechanisms for determining both satisfactions and dissatisfactions of expressions, offering insights into how scripts can be fulfilled or rendered unsatisfiable. This aspect is vital for understanding the versatility and constraints of script implementations. For instance, the document explains how certain expressions may permit multiple valid satisfactions, some of which might be unnecessary or "non-canonical," yet still technically valid.

The discussion on security emphasizes Miniscript's goal to ensure consensus soundness and standardness completeness, guaranteeing that scripts behave as intended under all conditions. By constraining hash preimages to 32 bytes, Miniscript mitigates potential abuses and ensures predictable execution costs. Additionally, the need for digital signatures in satisfying conditions enhances security by preventing unauthorized modifications to transaction attributes like nLockTime and nSequence.

In terms of compatibility and implementation, Miniscript extends the functionality of BIP 380 Output Script Descriptors, introducing a structured approach to script creation that is optimized for wsh() and tr() contexts. Reference implementations and contributions to Bitcoin Core highlight ongoing efforts to integrate Miniscript capabilities directly into the platform, with significant advancements marked by contributions in versions 25.0 and 26.0 of Bitcoin Core.

For detailed information and updates on Miniscript, the GitHub repository serves as the primary source, inviting feedback and collaboration from the broader community to refine and enhance this innovative scripting language.