[#miniscript-Type]
= xref:miniscript.adoc[miniscript]::Type
:relfileprefix: ../
:mrdocs:

This type encapsulates the miniscript type system properties&period;

== Synopsis

Declared in `&lt;script&sol;miniscript&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class Type;
----

== Description

Every miniscript expression is one of 4 basic types, and additionally has a number of boolean type properties&period;

The basic types are&colon;

* &quot;B&quot; Base&colon;
* Takes its inputs from the top of the stack&period;
* When satisfied, pushes a nonzero value of up to 4 bytes onto the stack&period;
* When dissatisfied, pushes a 0 onto the stack&period;
* This is used for most expressions, and required for the top level one&period;
* For example&colon; older(n) &equals; &lt;n&gt; OP&lowbar;CHECKSEQUENCEVERIFY&period;
* &quot;V&quot; Verify&colon;
* Takes its inputs from the top of the stack&period;
* When satisfied, pushes nothing&period;
* Cannot be dissatisfied&period;
* This can be obtained by adding an OP&lowbar;VERIFY to a B, modifying the last opcode of a B to its &hyphen;VERIFY version (only for OP&lowbar;CHECKSIG, OP&lowbar;CHECKSIGVERIFY, OP&lowbar;NUMEQUAL and OP&lowbar;EQUAL), or by combining a V fragment under some conditions&period;
* For example vc&colon;pk&lowbar;k(key) &equals; &lt;key&gt; OP&lowbar;CHECKSIGVERIFY
* &quot;K&quot; Key&colon;
* Takes its inputs from the top of the stack&period;
* Becomes a B when followed by OP&lowbar;CHECKSIG&period;
* Always pushes a public key onto the stack, for which a signature is to be provided to satisfy the expression&period;
* For example pk&lowbar;h(key) &equals; OP&lowbar;DUP OP&lowbar;HASH160 &lt;Hash160(key)&gt; OP&lowbar;EQUALVERIFY
* &quot;W&quot; Wrapped&colon;
* Takes its input from one below the top of the stack&period;
* When satisfied, pushes a nonzero value (like B) on top of the stack, or one below&period;
* When dissatisfied, pushes 0 op top of the stack or one below&period;
* Is always &quot;OP&lowbar;SWAP &lsqb;B&rsqb;&quot; or &quot;OP&lowbar;TOALTSTACK &lsqb;B&rsqb;OP&lowbar;FROMALTSTACK&quot;&period;
* For example sc&colon;pk&lowbar;k(key) &equals; OP&lowbar;SWAP &lt;key&gt; OP&lowbar;CHECKSIG

There are type properties that help reasoning about correctness&colon;

* &quot;z&quot; Zero&hyphen;arg&colon;
* Is known to always consume exactly 0 stack elements&period;
* For example after(n) &equals; &lt;n&gt; OP&lowbar;CHECKLOCKTIMEVERIFY
* &quot;o&quot; One&hyphen;arg&colon;
* Is known to always consume exactly 1 stack element&period;
* Conflicts with property &apos;z&apos;
* For example sha256(hash) &equals; OP&lowbar;SIZE 32 OP&lowbar;EQUALVERIFY OP&lowbar;SHA256 &lt;hash&gt; OP&lowbar;EQUAL
* &quot;n&quot; Nonzero&colon;
* For every way this expression can be satisfied, a satisfaction exists that never needs a zero top stack element&period;
* Conflicts with property &apos;z&apos; and with type &apos;W&apos;&period;
* &quot;d&quot; Dissatisfiable&colon;
* There is an easy way to construct a dissatisfaction for this expression&period;
* Conflicts with type &apos;V&apos;&period;
* &quot;u&quot; Unit&colon;
* In case of satisfaction, an exact 1 is put on the stack (rather than just nonzero)&period;
* Conflicts with type &apos;V&apos;&period;

Additional type properties help reasoning about nonmalleability&colon;

* &quot;e&quot; Expression&colon;
* This implies property &apos;d&apos;, but the dissatisfaction is nonmalleable&period;
* This generally requires &apos;e&apos; for all subexpressions which are invoked for that dissatisfaction, and property &apos;f&apos; for the unexecuted subexpressions in that case&period;
* Conflicts with type &apos;V&apos;&period;
* &quot;f&quot; Forced&colon;
* Dissatisfactions (if any) for this expression always involve at least one signature&period;
* Is always true for type &apos;V&apos;&period;
* &quot;s&quot; Safe&colon;
* Satisfactions for this expression always involve at least one signature&period;
* &quot;m&quot; Nonmalleable&colon;
* For every way this expression can be satisfied (which may be none), a nonmalleable satisfaction exists&period;
* This generally requires &apos;m&apos; for all subexpressions, and &apos;e&apos; for all subexpressions which are dissatisfied when satisfying the parent&period;

One type property is an implementation detail&colon;

* &quot;x&quot; Expensive verify&colon;
* Expressions with this property have a script whose last opcode is not EQUAL, CHECKSIG, or CHECKMULTISIG&period;
* Not having this property means that it can be converted to a V at no cost (by switching to the &hyphen;VERIFY version of the last opcode)&period;

Five more type properties for representing timelock information&period; Spend paths in miniscripts containing conflicting timelocks and heightlocks cannot be spent together&period; This helps users detect if miniscript does not match the semantic behaviour the user expects&period;

* &quot;g&quot; Whether the branch contains a relative time timelock
* &quot;h&quot; Whether the branch contains a relative height timelock
* &quot;i&quot; Whether the branch contains an absolute time timelock
* &quot;j&quot; Whether the branch contains an absolute height timelock
* &quot;k&quot;
* Whether all satisfactions of this expression don&apos;t contain a mix of heightlock and timelock of the same type&period;
* If the miniscript does not have the &quot;k&quot; property, the miniscript template will not match the user expectation of the corresponding spending policy&period; For each of these properties the subset rule holds&colon; an expression with properties X, Y, and Z, is also valid in places where an X, a Y, a Z, an XY, &period;&period;&period; is expected&period;

== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:miniscript/Type/If.adoc[`If`] 
| The empty type if x is false, itself otherwise&period;
| xref:miniscript/Type/operator_bitand.adoc[`operator&amp;`] 
| Compute the type with the intersection of properties&period;
| xref:miniscript/Type/operator_bitor.adoc[`operator&verbar;`] 
| Compute the type with the union of properties&period;
| xref:miniscript/Type/operator_lshift.adoc[`operator&lt;&lt;`] 
| Check whether the left hand&apos;s properties are superset of the right&apos;s (&equals; left is a subtype of right)&period;
| xref:miniscript/Type/operator_eq.adoc[`operator&equals;&equals;`] 
| Equality operator&period;
| xref:miniscript/Type/operator_lt.adoc[`operator&lt;`] 
| Comparison operator to enable use in sets&sol;maps (total ordering incompatible with &lt;&lt;)&period;
|===


== Friends

[cols="1,4"]
|===
| Name| Description
| `xref:miniscript/operator_mst.adoc[miniscript::operator&quot;&quot;&lowbar;mst]`
| The only way to publicly construct a Type is using this literal operator&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
