Bitcoin Core  24.99.0
P2P Digital Currency
Classes | Enumerations | Functions
miniscript::internal Namespace Reference

Classes

struct  MaxInt
 Class whose objects represent the maximum of a list of integers. More...
 
struct  Ops
 
struct  StackSize
 
struct  NoDupCheck
 

Enumerations

enum class  ParseContext {
  WRAPPED_EXPR , EXPR , SWAP , ALT ,
  CHECK , DUP_IF , VERIFY , NON_ZERO ,
  ZERO_NOTEQUAL , WRAP_U , WRAP_T , AND_N ,
  AND_V , AND_B , ANDOR , OR_B ,
  OR_C , OR_D , OR_I , THRESH ,
  COMMA , CLOSE_BRACKET
}
 
enum class  DecodeContext {
  SINGLE_BKV_EXPR , BKV_EXPR , W_EXPR , SWAP ,
  ALT , CHECK , DUP_IF , VERIFY ,
  NON_ZERO , ZERO_NOTEQUAL , MAYBE_AND_V , AND_V ,
  AND_B , ANDOR , OR_B , OR_C ,
  OR_D , THRESH_W , THRESH_E , ENDIF ,
  ENDIF_NOTIF , ENDIF_ELSE
}
 

Functions

Type SanitizeType (Type x)
 A helper sanitizer/checker for the output of CalcType. More...
 
Type ComputeType (Fragment fragment, Type x, Type y, Type z, const std::vector< Type > &sub_types, uint32_t k, size_t data_size, size_t n_subs, size_t n_keys)
 Helper function for Node::CalcType. More...
 
size_t ComputeScriptLen (Fragment fragment, Type sub0typ, size_t subsize, uint32_t k, size_t n_subs, size_t n_keys)
 Helper function for Node::CalcScriptLen. More...
 
std::optional< std::vector< Opcode > > DecomposeScript (const CScript &script)
 Decode a script into opcode/push pairs. More...
 
std::optional< int64_t > ParseScriptNumber (const Opcode &in)
 Determine whether the passed pair (created by DecomposeScript) is pushing a number. More...
 
int FindNextChar (Span< const char > sp, const char m)
 
template<typename Key , typename Ctx >
std::optional< std::pair< Key, int > > ParseKeyEnd (Span< const char > in, const Ctx &ctx)
 Parse a key string ending at the end of the fragment's text representation. More...
 
template<typename Ctx >
std::optional< std::pair< std::vector< unsigned char >, int > > ParseHexStrEnd (Span< const char > in, const size_t expected_size, const Ctx &ctx)
 Parse a hex string ending at the end of the fragment's text representation. More...
 
template<typename Key >
void BuildBack (Fragment nt, std::vector< NodeRef< Key >> &constructed, const bool reverse=false)
 BuildBack pops the last two elements off constructed and wraps them in the specified Fragment. More...
 
template<typename Key , typename Ctx >
NodeRef< Key > Parse (Span< const char > in, const Ctx &ctx)
 Parse a miniscript from its textual descriptor form. More...
 
template<typename Key , typename Ctx , typename I >
NodeRef< Key > DecodeScript (I &in, I last, const Ctx &ctx)
 Parse a miniscript from a bitcoin script. More...
 

Enumeration Type Documentation

◆ DecodeContext

Enumerator
SINGLE_BKV_EXPR 

A single expression of type B, K, or V.

Specifically, this can't be an and_v or an expression of type W (a: and s: wrappers).

BKV_EXPR 

Potentially multiple SINGLE_BKV_EXPRs as children of (potentially multiple) and_v expressions.

Syntactic sugar for MAYBE_AND_V + SINGLE_BKV_EXPR.

W_EXPR 

An expression of type W (a: or s: wrappers).

SWAP 

SWAP expects the next element to be OP_SWAP (inside a W-type expression that didn't end with FROMALTSTACK), and wraps the top of the constructed stack with s:

ALT 

ALT expects the next element to be TOALTSTACK (we must have already read a FROMALTSTACK earlier), and wraps the top of the constructed stack with a:

CHECK 

CHECK wraps the top constructed node with c:

DUP_IF 

DUP_IF wraps the top constructed node with d:

VERIFY 

VERIFY wraps the top constructed node with v:

NON_ZERO 

NON_ZERO wraps the top constructed node with j:

ZERO_NOTEQUAL 

ZERO_NOTEQUAL wraps the top constructed node with n:

MAYBE_AND_V 

MAYBE_AND_V will check if the next part of the script could be a valid miniscript sub-expression, and if so it will push AND_V and SINGLE_BKV_EXPR to decode it and construct the and_v node.

This is recursive, to deal with multiple and_v nodes inside each other.

AND_V 

AND_V will construct an and_v node from the last two constructed nodes.

AND_B 

AND_B will construct an and_b node from the last two constructed nodes.

ANDOR 

ANDOR will construct an andor node from the last three constructed nodes.

OR_B 

OR_B will construct an or_b node from the last two constructed nodes.

OR_C 

OR_C will construct an or_c node from the last two constructed nodes.

OR_D 

OR_D will construct an or_d node from the last two constructed nodes.

THRESH_W 

In a thresh expression, all sub-expressions other than the first are W-type, and end in OP_ADD.

THRESH_W will check for this OP_ADD and either push a W_EXPR or a SINGLE_BKV_EXPR and jump to THRESH_E accordingly.

THRESH_E 

THRESH_E constructs a thresh node from the appropriate number of constructed children.

ENDIF 

ENDIF signals that we are inside some sort of OP_IF structure, which could be or_d, or_c, or_i, andor, d:, or j: wrapper, depending on what follows.

We read a BKV_EXPR and then deal with the next opcode case-by-case.

ENDIF_NOTIF 

If, inside an ENDIF context, we find an OP_NOTIF before finding an OP_ELSE, we could either be in an or_d or an or_c node.

We then check for IFDUP to distinguish these cases.

ENDIF_ELSE 

If, inside an ENDIF context, we find an OP_ELSE, then we could be in either an or_i or an andor node.

Read the next BKV_EXPR and find either an OP_IF or an OP_NOTIF.

Definition at line 1399 of file miniscript.h.

◆ ParseContext

Enumerator
WRAPPED_EXPR 

An expression which may be begin with wrappers followed by a colon.

EXPR 

A miniscript expression which does not begin with wrappers.

SWAP 

SWAP wraps the top constructed node with s:

ALT 

ALT wraps the top constructed node with a:

CHECK 

CHECK wraps the top constructed node with c:

DUP_IF 

DUP_IF wraps the top constructed node with d:

VERIFY 

VERIFY wraps the top constructed node with v:

NON_ZERO 

NON_ZERO wraps the top constructed node with j:

ZERO_NOTEQUAL 

ZERO_NOTEQUAL wraps the top constructed node with n:

WRAP_U 

WRAP_U will construct an or_i(X,0) node from the top constructed node.

WRAP_T 

WRAP_T will construct an and_v(X,1) node from the top constructed node.

AND_N 

AND_N will construct an andor(X,Y,0) node from the last two constructed nodes.

AND_V 

AND_V will construct an and_v node from the last two constructed nodes.

AND_B 

AND_B will construct an and_b node from the last two constructed nodes.

ANDOR 

ANDOR will construct an andor node from the last three constructed nodes.

OR_B 

OR_B will construct an or_b node from the last two constructed nodes.

OR_C 

OR_C will construct an or_c node from the last two constructed nodes.

OR_D 

OR_D will construct an or_d node from the last two constructed nodes.

OR_I 

OR_I will construct an or_i node from the last two constructed nodes.

THRESH 

THRESH will read a wrapped expression, and then look for a COMMA.

If no comma follows, it will construct a thresh node from the appropriate number of constructed children. Otherwise, it will recurse with another THRESH.

COMMA 

COMMA expects the next element to be ',' and fails if not.

CLOSE_BRACKET 

CLOSE_BRACKET expects the next element to be ')' and fails if not.

Definition at line 929 of file miniscript.h.

Function Documentation

◆ BuildBack()

template<typename Key >
void miniscript::internal::BuildBack ( Fragment  nt,
std::vector< NodeRef< Key >> &  constructed,
const bool  reverse = false 
)

BuildBack pops the last two elements off constructed and wraps them in the specified Fragment.

Definition at line 1012 of file miniscript.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ComputeScriptLen()

size_t miniscript::internal::ComputeScriptLen ( Fragment  fragment,
Type  sub0typ,
size_t  subsize,
uint32_t  k,
size_t  n_subs,
size_t  n_keys 
)

Helper function for Node::CalcScriptLen.

Definition at line 250 of file miniscript.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ComputeType()

Type miniscript::internal::ComputeType ( Fragment  fragment,
Type  x,
Type  y,
Type  z,
const std::vector< Type > &  sub_types,
uint32_t  k,
size_t  data_size,
size_t  n_subs,
size_t  n_keys 
)

Helper function for Node::CalcType.

Definition at line 36 of file miniscript.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DecodeScript()

template<typename Key , typename Ctx , typename I >
NodeRef<Key> miniscript::internal::DecodeScript ( I &  in,
last,
const Ctx &  ctx 
)
inline

Parse a miniscript from a bitcoin script.

In the following wrappers, we only need to push SINGLE_BKV_EXPR rather than BKV_EXPR, because and_v commutes with these wrappers. For example, c:and_v(X,Y) produces the same script as and_v(X,c:Y).

In and_b and or_b nodes, we only look for SINGLE_BKV_EXPR, because or_b(and_v(X,Y),Z) has script [X] [Y] [Z] OP_BOOLOR, the same as and_v(X,or_b(Y,Z)). In this example, the former of these is invalid as miniscript, while the latter is valid. So we leave the and_v "outside" while decoding.

Definition at line 1469 of file miniscript.h.

Here is the call graph for this function:

◆ DecomposeScript()

std::optional< std::vector< Opcode > > miniscript::internal::DecomposeScript ( const CScript script)

Decode a script into opcode/push pairs.

Construct a vector with one element per opcode in the script, in reverse order. Each element is a pair consisting of the opcode, as well as the data pushed by the opcode (including OP_n), if any. OP_CHECKSIGVERIFY, OP_CHECKMULTISIGVERIFY, and OP_EQUALVERIFY are decomposed into OP_CHECKSIG, OP_CHECKMULTISIG, OP_EQUAL respectively, plus OP_VERIFY.

Definition at line 282 of file miniscript.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindNextChar()

int miniscript::internal::FindNextChar ( Span< const char >  sp,
const char  m 
)

Definition at line 331 of file miniscript.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Parse()

template<typename Key , typename Ctx >
NodeRef<Key> miniscript::internal::Parse ( Span< const char >  in,
const Ctx &  ctx 
)
inline

Parse a miniscript from its textual descriptor form.

This does not check whether the script is valid, let alone sane. The caller is expected to use the IsValidTopLevel() and IsSaneTopLevel() to check for these properties on the node.

Definition at line 1029 of file miniscript.h.

Here is the call graph for this function:

◆ ParseHexStrEnd()

template<typename Ctx >
std::optional<std::pair<std::vector<unsigned char>, int> > miniscript::internal::ParseHexStrEnd ( Span< const char >  in,
const size_t  expected_size,
const Ctx &  ctx 
)

Parse a hex string ending at the end of the fragment's text representation.

Definition at line 998 of file miniscript.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ParseKeyEnd()

template<typename Key , typename Ctx >
std::optional<std::pair<Key, int> > miniscript::internal::ParseKeyEnd ( Span< const char >  in,
const Ctx &  ctx 
)

Parse a key string ending at the end of the fragment's text representation.

Definition at line 987 of file miniscript.h.

Here is the call graph for this function:

◆ ParseScriptNumber()

std::optional< int64_t > miniscript::internal::ParseScriptNumber ( const Opcode in)

Determine whether the passed pair (created by DecomposeScript) is pushing a number.

Definition at line 318 of file miniscript.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SanitizeType()

Type miniscript::internal::SanitizeType ( Type  e)

A helper sanitizer/checker for the output of CalcType.

Definition at line 16 of file miniscript.cpp.

Here is the call graph for this function:
Here is the caller graph for this function: