1

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.

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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