Bitcoin Core  22.99.0
P2P Digital Currency
Classes | Typedefs | Enumerations | Functions | Variables
interpreter.h File Reference
#include <hash.h>
#include <script/script_error.h>
#include <span.h>
#include <primitives/transaction.h>
#include <vector>
#include <stdint.h>
Include dependency graph for interpreter.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  PrecomputedTransactionData
 
struct  ScriptExecutionData
 
class  BaseSignatureChecker
 
class  GenericTransactionSignatureChecker< T >
 
class  DeferringSignatureChecker
 

Typedefs

using TransactionSignatureChecker = GenericTransactionSignatureChecker< CTransaction >
 
using MutableTransactionSignatureChecker = GenericTransactionSignatureChecker< CMutableTransaction >
 

Enumerations

enum  {
  SIGHASH_ALL = 1, SIGHASH_NONE = 2, SIGHASH_SINGLE = 3, SIGHASH_ANYONECANPAY = 0x80,
  SIGHASH_DEFAULT = 0, SIGHASH_OUTPUT_MASK = 3, SIGHASH_INPUT_MASK = 0x80
}
 Signature hash types/flags. More...
 
enum  : uint32_t {
  SCRIPT_VERIFY_NONE = 0, SCRIPT_VERIFY_P2SH = (1U << 0), SCRIPT_VERIFY_STRICTENC = (1U << 1), SCRIPT_VERIFY_DERSIG = (1U << 2),
  SCRIPT_VERIFY_LOW_S = (1U << 3), SCRIPT_VERIFY_NULLDUMMY = (1U << 4), SCRIPT_VERIFY_SIGPUSHONLY = (1U << 5), SCRIPT_VERIFY_MINIMALDATA = (1U << 6),
  SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS = (1U << 7), SCRIPT_VERIFY_CLEANSTACK = (1U << 8), SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY = (1U << 9), SCRIPT_VERIFY_CHECKSEQUENCEVERIFY = (1U << 10),
  SCRIPT_VERIFY_WITNESS = (1U << 11), SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM = (1U << 12), SCRIPT_VERIFY_MINIMALIF = (1U << 13), SCRIPT_VERIFY_NULLFAIL = (1U << 14),
  SCRIPT_VERIFY_WITNESS_PUBKEYTYPE = (1U << 15), SCRIPT_VERIFY_CONST_SCRIPTCODE = (1U << 16), SCRIPT_VERIFY_TAPROOT = (1U << 17), SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_TAPROOT_VERSION = (1U << 18),
  SCRIPT_VERIFY_DISCOURAGE_OP_SUCCESS = (1U << 19), SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_PUBKEYTYPE = (1U << 20), SCRIPT_VERIFY_END_MARKER
}
 Script verification flags. More...
 
enum  SigVersion { SigVersion::BASE = 0, SigVersion::WITNESS_V0 = 1, SigVersion::TAPROOT = 2, SigVersion::TAPSCRIPT = 3 }
 
enum  MissingDataBehavior { MissingDataBehavior::ASSERT_FAIL, MissingDataBehavior::FAIL }
 Enum to specify what *TransactionSignatureChecker's behavior should be when dealing with missing transaction data. More...
 

Functions

bool CheckSignatureEncoding (const std::vector< unsigned char > &vchSig, unsigned int flags, ScriptError *serror)
 
template<class T >
uint256 SignatureHash (const CScript &scriptCode, const T &txTo, unsigned int nIn, int nHashType, const CAmount &amount, SigVersion sigversion, const PrecomputedTransactionData *cache=nullptr)
 
template<typename T >
bool SignatureHashSchnorr (uint256 &hash_out, const ScriptExecutionData &execdata, const T &tx_to, uint32_t in_pos, uint8_t hash_type, SigVersion sigversion, const PrecomputedTransactionData &cache, MissingDataBehavior mdb)
 
uint256 ComputeTapleafHash (uint8_t leaf_version, const CScript &script)
 Compute the BIP341 tapleaf hash from leaf version & script. More...
 
uint256 ComputeTaprootMerkleRoot (Span< const unsigned char > control, const uint256 &tapleaf_hash)
 Compute the BIP341 taproot script tree Merkle root from control block and leaf hash. More...
 
bool EvalScript (std::vector< std::vector< unsigned char > > &stack, const CScript &script, unsigned int flags, const BaseSignatureChecker &checker, SigVersion sigversion, ScriptExecutionData &execdata, ScriptError *error=nullptr)
 
bool EvalScript (std::vector< std::vector< unsigned char > > &stack, const CScript &script, unsigned int flags, const BaseSignatureChecker &checker, SigVersion sigversion, ScriptError *error=nullptr)
 
bool VerifyScript (const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, unsigned int flags, const BaseSignatureChecker &checker, ScriptError *serror=nullptr)
 
size_t CountWitnessSigOps (const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, unsigned int flags)
 
bool CheckMinimalPush (const std::vector< unsigned char > &data, opcodetype opcode)
 
int FindAndDelete (CScript &script, const CScript &b)
 

Variables

static constexpr size_t WITNESS_V0_SCRIPTHASH_SIZE = 32
 Signature hash sizes. More...
 
static constexpr size_t WITNESS_V0_KEYHASH_SIZE = 20
 
static constexpr size_t WITNESS_V1_TAPROOT_SIZE = 32
 
static constexpr uint8_t TAPROOT_LEAF_MASK = 0xfe
 
static constexpr uint8_t TAPROOT_LEAF_TAPSCRIPT = 0xc0
 
static constexpr size_t TAPROOT_CONTROL_BASE_SIZE = 33
 
static constexpr size_t TAPROOT_CONTROL_NODE_SIZE = 32
 
static constexpr size_t TAPROOT_CONTROL_MAX_NODE_COUNT = 128
 
static constexpr size_t TAPROOT_CONTROL_MAX_SIZE = TAPROOT_CONTROL_BASE_SIZE + TAPROOT_CONTROL_NODE_SIZE * TAPROOT_CONTROL_MAX_NODE_COUNT
 
const CHashWriter HASHER_TAPLEAF
 Hasher with tag "TapLeaf" pre-fed to it. More...
 
const CHashWriter HASHER_TAPBRANCH
 Hasher with tag "TapBranch" pre-fed to it. More...
 

Typedef Documentation

◆ MutableTransactionSignatureChecker

Definition at line 293 of file interpreter.h.

◆ TransactionSignatureChecker

Definition at line 292 of file interpreter.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Signature hash types/flags.

Enumerator
SIGHASH_ALL 
SIGHASH_NONE 
SIGHASH_SINGLE 
SIGHASH_ANYONECANPAY 
SIGHASH_DEFAULT 

Taproot only; implied when sighash byte is missing, and equivalent to SIGHASH_ALL.

SIGHASH_OUTPUT_MASK 
SIGHASH_INPUT_MASK 

Definition at line 25 of file interpreter.h.

◆ anonymous enum

anonymous enum : uint32_t

Script verification flags.

All flags are intended to be soft forks: the set of acceptable scripts under flags (A | B) is a subset of the acceptable scripts under flag (A).

Enumerator
SCRIPT_VERIFY_NONE 
SCRIPT_VERIFY_P2SH 
SCRIPT_VERIFY_STRICTENC 
SCRIPT_VERIFY_DERSIG 
SCRIPT_VERIFY_LOW_S 
SCRIPT_VERIFY_NULLDUMMY 
SCRIPT_VERIFY_SIGPUSHONLY 
SCRIPT_VERIFY_MINIMALDATA 
SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS 
SCRIPT_VERIFY_CLEANSTACK 
SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY 
SCRIPT_VERIFY_CHECKSEQUENCEVERIFY 
SCRIPT_VERIFY_WITNESS 
SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM 
SCRIPT_VERIFY_MINIMALIF 
SCRIPT_VERIFY_NULLFAIL 
SCRIPT_VERIFY_WITNESS_PUBKEYTYPE 
SCRIPT_VERIFY_CONST_SCRIPTCODE 
SCRIPT_VERIFY_TAPROOT 
SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_TAPROOT_VERSION 
SCRIPT_VERIFY_DISCOURAGE_OP_SUCCESS 
SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_PUBKEYTYPE 
SCRIPT_VERIFY_END_MARKER 

Definition at line 42 of file interpreter.h.

◆ MissingDataBehavior

enum MissingDataBehavior
strong

Enum to specify what *TransactionSignatureChecker's behavior should be when dealing with missing transaction data.

Enumerator
ASSERT_FAIL 

Abort execution through assertion failure (for consensus code)

FAIL 

Just act as if the signature was invalid.

Definition at line 260 of file interpreter.h.

◆ SigVersion

enum SigVersion
strong
Enumerator
BASE 

Bare scripts and BIP16 P2SH-wrapped redeemscripts.

WITNESS_V0 

Witness v0 (P2WPKH and P2WSH); see BIP 141.

TAPROOT 

Witness v1 with 32-byte program, not BIP16 P2SH-wrapped, key path spending; see BIP 341.

TAPSCRIPT 

Witness v1 with 32-byte program, not BIP16 P2SH-wrapped, script path spending, leaf version 0xc0; see BIP 342.

Definition at line 180 of file interpreter.h.

Function Documentation

◆ CheckMinimalPush()

bool CheckMinimalPush ( const std::vector< unsigned char > &  data,
opcodetype  opcode 
)

Definition at line 228 of file interpreter.cpp.

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

◆ CheckSignatureEncoding()

bool CheckSignatureEncoding ( const std::vector< unsigned char > &  vchSig,
unsigned int  flags,
ScriptError serror 
)

Definition at line 200 of file interpreter.cpp.

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

◆ ComputeTapleafHash()

uint256 ComputeTapleafHash ( uint8_t  leaf_version,
const CScript script 
)

Compute the BIP341 tapleaf hash from leaf version & script.

Definition at line 1850 of file interpreter.cpp.

Here is the caller graph for this function:

◆ ComputeTaprootMerkleRoot()

uint256 ComputeTaprootMerkleRoot ( Span< const unsigned char >  control,
const uint256 tapleaf_hash 
)

Compute the BIP341 taproot script tree Merkle root from control block and leaf hash.

Requires control block to have valid length (33 + k*32, with k in {0,1,..,128}).

Definition at line 1855 of file interpreter.cpp.

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

◆ CountWitnessSigOps()

size_t CountWitnessSigOps ( const CScript scriptSig,
const CScript scriptPubKey,
const CScriptWitness witness,
unsigned int  flags 
)

Definition at line 2106 of file interpreter.cpp.

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

◆ EvalScript() [1/2]

bool EvalScript ( std::vector< std::vector< unsigned char > > &  stack,
const CScript script,
unsigned int  flags,
const BaseSignatureChecker checker,
SigVersion  sigversion,
ScriptError error = nullptr 
)

Definition at line 1261 of file interpreter.cpp.

Here is the call graph for this function:

◆ EvalScript() [2/2]

bool EvalScript ( std::vector< std::vector< unsigned char > > &  stack,
const CScript script,
unsigned int  flags,
const BaseSignatureChecker checker,
SigVersion  sigversion,
ScriptExecutionData execdata,
ScriptError error = nullptr 
)

Definition at line 431 of file interpreter.cpp.

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

◆ FindAndDelete()

int FindAndDelete ( CScript script,
const CScript b 
)

Definition at line 253 of file interpreter.cpp.

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

◆ SignatureHash()

template<class T >
uint256 SignatureHash ( const CScript scriptCode,
const T &  txTo,
unsigned int  nIn,
int  nHashType,
const CAmount amount,
SigVersion  sigversion,
const PrecomputedTransactionData cache = nullptr 
)

Definition at line 1590 of file interpreter.cpp.

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

◆ SignatureHashSchnorr()

template<typename T >
bool SignatureHashSchnorr ( uint256 hash_out,
const ScriptExecutionData execdata,
const T &  tx_to,
uint32_t  in_pos,
uint8_t  hash_type,
SigVersion  sigversion,
const PrecomputedTransactionData cache,
MissingDataBehavior  mdb 
)

Definition at line 1503 of file interpreter.cpp.

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

◆ VerifyScript()

bool VerifyScript ( const CScript scriptSig,
const CScript scriptPubKey,
const CScriptWitness witness,
unsigned int  flags,
const BaseSignatureChecker checker,
ScriptError serror = nullptr 
)

Definition at line 1969 of file interpreter.cpp.

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

Variable Documentation

◆ HASHER_TAPBRANCH

const CHashWriter HASHER_TAPBRANCH

Hasher with tag "TapBranch" pre-fed to it.

Definition at line 1488 of file interpreter.cpp.

◆ HASHER_TAPLEAF

const CHashWriter HASHER_TAPLEAF

Hasher with tag "TapLeaf" pre-fed to it.

Definition at line 1487 of file interpreter.cpp.

◆ TAPROOT_CONTROL_BASE_SIZE

constexpr size_t TAPROOT_CONTROL_BASE_SIZE = 33
staticconstexpr

Definition at line 220 of file interpreter.h.

◆ TAPROOT_CONTROL_MAX_NODE_COUNT

constexpr size_t TAPROOT_CONTROL_MAX_NODE_COUNT = 128
staticconstexpr

Definition at line 222 of file interpreter.h.

◆ TAPROOT_CONTROL_MAX_SIZE

constexpr size_t TAPROOT_CONTROL_MAX_SIZE = TAPROOT_CONTROL_BASE_SIZE + TAPROOT_CONTROL_NODE_SIZE * TAPROOT_CONTROL_MAX_NODE_COUNT
staticconstexpr

Definition at line 223 of file interpreter.h.

◆ TAPROOT_CONTROL_NODE_SIZE

constexpr size_t TAPROOT_CONTROL_NODE_SIZE = 32
staticconstexpr

Definition at line 221 of file interpreter.h.

◆ TAPROOT_LEAF_MASK

constexpr uint8_t TAPROOT_LEAF_MASK = 0xfe
staticconstexpr

Definition at line 218 of file interpreter.h.

◆ TAPROOT_LEAF_TAPSCRIPT

constexpr uint8_t TAPROOT_LEAF_TAPSCRIPT = 0xc0
staticconstexpr

Definition at line 219 of file interpreter.h.

◆ WITNESS_V0_KEYHASH_SIZE

constexpr size_t WITNESS_V0_KEYHASH_SIZE = 20
staticconstexpr

Definition at line 215 of file interpreter.h.

◆ WITNESS_V0_SCRIPTHASH_SIZE

constexpr size_t WITNESS_V0_SCRIPTHASH_SIZE = 32
staticconstexpr

Signature hash sizes.

Definition at line 214 of file interpreter.h.

◆ WITNESS_V1_TAPROOT_SIZE

constexpr size_t WITNESS_V1_TAPROOT_SIZE = 32
staticconstexpr

Definition at line 216 of file interpreter.h.