2

What is a sane Miniscript? How does it differ to a valid Miniscript?

This was asked during a Bitcoin Core PR review club on Miniscript hosted by stickies-v on May 18th 2022.

2 Answers 2

2

A valid Miniscript is any correctly typed Miniscript.

A sane Miniscript needs to be valid, consensus and standardness-compliant (e.g. number of operations and script size), have non-malleable solutions, not mix different timelock units on a particular branch of the script and not have duplicate keys.

From miniscript.h:

//! Whether the apparent policy of this node matches its script semantics. Doesn't guarantee it is a safe script on its own.
bool IsSaneSubexpression() const { return ValidSatisfactions() && IsNonMalleable() && CheckTimeLocksMix() && CheckDuplicateKey(); }

//! Check whether this node is safe as a script on its own.
bool IsSane() const { return IsValidTopLevel() && IsSaneSubexpression() && NeedsSignature(); }

A Miniscript is sane if it is of the form X OR Y with X containing a block check and Y containing a time check but X AND Y would be unspendable. e.g. (A signs) OR ((B signs) AND (timelock) AND (heightlock)) would not be considered sane. Even though it can be spent by A, its apparent policy doesn't match the actual script (whose actual policy is just "A signs", because the other branch is unusable)

The Node::IsSane() method has the docstring "Whether the apparent policy of this node matches its script semantics."

Thanks to participants for answering this at the Bitcoin Core PR review club.

1

A WIP "Work In Progress" that may be of interest to you is the Miniscript Templates repo: https://github.com/Blockstream/miniscript-templates

One of the goals is to curate miniscript policies that are "sane", "valid" and "useful". :)

Feel free to comment on PRs as they are posted!

https://github.com/Blockstream/miniscript-templates/pull/2

miniscript-templates

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.