Bitcoin Core  0.20.99
P2P Digital Currency
Macros | Typedefs | Functions
interpreter.cpp File Reference
#include <script/interpreter.h>
#include <crypto/ripemd160.h>
#include <crypto/sha1.h>
#include <crypto/sha256.h>
#include <pubkey.h>
#include <script/script.h>
#include <uint256.h>
Include dependency graph for interpreter.cpp:

Go to the source code of this file.

Macros

#define stacktop(i)   (stack.at(stack.size()+(i)))
 Script is a stack machine (like Forth) that evaluates a predicate returning a bool indicating valid or not. More...
 
#define altstacktop(i)   (altstack.at(altstack.size()+(i)))
 

Typedefs

typedef std::vector< unsigned char > valtype
 

Functions

bool CastToBool (const valtype &vch)
 
static void popstack (std::vector< valtype > &stack)
 
static bool IsCompressedOrUncompressedPubKey (const valtype &vchPubKey)
 
static bool IsCompressedPubKey (const valtype &vchPubKey)
 
static bool IsValidSignatureEncoding (const std::vector< unsigned char > &sig)
 A canonical signature exists of: <30> <total len>=""> <02> <len r>=""> <R> <02> <len s>=""> <S> <hashtype> Where R and S are not negative (their first byte has its highest bit not set), and not excessively padded (do not start with a 0 byte, unless an otherwise negative number follows, in which case a single 0 byte is necessary and even required). More...
 
static bool IsLowDERSignature (const valtype &vchSig, ScriptError *serror)
 
static bool IsDefinedHashtypeSignature (const valtype &vchSig)
 
bool CheckSignatureEncoding (const std::vector< unsigned char > &vchSig, unsigned int flags, ScriptError *serror)
 
static bool CheckPubKeyEncoding (const valtype &vchPubKey, unsigned int flags, const SigVersion &sigversion, ScriptError *serror)
 
static bool CheckMinimalPush (const valtype &data, opcodetype opcode)
 
int FindAndDelete (CScript &script, const CScript &b)
 
static bool EvalChecksig (const valtype &vchSig, const valtype &vchPubKey, CScript::const_iterator pbegincodehash, CScript::const_iterator pend, unsigned int flags, const BaseSignatureChecker &checker, SigVersion sigversion, ScriptError *serror, bool &fSuccess)
 Helper for OP_CHECKSIG and OP_CHECKSIGVERIFY. More...
 
bool EvalScript (std::vector< std::vector< unsigned char > > &stack, const CScript &script, unsigned int flags, const BaseSignatureChecker &checker, SigVersion sigversion, 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)
 
static bool ExecuteWitnessScript (const Span< const valtype > &stack_span, const CScript &scriptPubKey, unsigned int flags, SigVersion sigversion, const BaseSignatureChecker &checker, ScriptError *serror)
 
static bool VerifyWitnessProgram (const CScriptWitness &witness, int witversion, const std::vector< unsigned char > &program, unsigned int flags, const BaseSignatureChecker &checker, ScriptError *serror)
 
bool VerifyScript (const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, unsigned int flags, const BaseSignatureChecker &checker, ScriptError *serror)
 
static size_t WitnessSigOps (int witversion, const std::vector< unsigned char > &witprogram, const CScriptWitness &witness)
 
size_t CountWitnessSigOps (const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, unsigned int flags)
 

Macro Definition Documentation

◆ altstacktop

#define altstacktop (   i)    (altstack.at(altstack.size()+(i)))

Definition at line 55 of file interpreter.cpp.

◆ stacktop

#define stacktop (   i)    (stack.at(stack.size()+(i)))

Script is a stack machine (like Forth) that evaluates a predicate returning a bool indicating valid or not.

There are no loops.

Definition at line 54 of file interpreter.cpp.

Typedef Documentation

◆ valtype

typedef std::vector<unsigned char> valtype

Definition at line 15 of file interpreter.cpp.

Function Documentation

◆ CastToBool()

bool CastToBool ( const valtype vch)

Definition at line 35 of file interpreter.cpp.

Here is the caller graph for this function:

◆ CheckMinimalPush()

static bool CheckMinimalPush ( const valtype data,
opcodetype  opcode 
)
static

Definition at line 228 of file interpreter.cpp.

Here is the caller graph for this function:

◆ CheckPubKeyEncoding()

static bool CheckPubKeyEncoding ( const valtype vchPubKey,
unsigned int  flags,
const SigVersion sigversion,
ScriptError serror 
)
static

Definition at line 217 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:

◆ CountWitnessSigOps()

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

Definition at line 1698 of file interpreter.cpp.

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

◆ EvalChecksig()

static bool EvalChecksig ( const valtype vchSig,
const valtype vchPubKey,
CScript::const_iterator  pbegincodehash,
CScript::const_iterator  pend,
unsigned int  flags,
const BaseSignatureChecker checker,
SigVersion  sigversion,
ScriptError serror,
bool &  fSuccess 
)
static

Helper for OP_CHECKSIG and OP_CHECKSIGVERIFY.

A return value of false means the script fails entirely. When true is returned, the fSuccess variable indicates whether the signature check itself succeeded.

Definition at line 350 of file interpreter.cpp.

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

◆ EvalScript()

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

Definition at line 374 of file interpreter.cpp.

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

◆ ExecuteWitnessScript()

static bool ExecuteWitnessScript ( const Span< const valtype > &  stack_span,
const CScript scriptPubKey,
unsigned int  flags,
SigVersion  sigversion,
const BaseSignatureChecker checker,
ScriptError serror 
)
static

Definition at line 1504 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:

◆ IsCompressedOrUncompressedPubKey()

static bool IsCompressedOrUncompressedPubKey ( const valtype vchPubKey)
static

Definition at line 63 of file interpreter.cpp.

Here is the caller graph for this function:

◆ IsCompressedPubKey()

static bool IsCompressedPubKey ( const valtype vchPubKey)
static

Definition at line 85 of file interpreter.cpp.

Here is the caller graph for this function:

◆ IsDefinedHashtypeSignature()

static bool IsDefinedHashtypeSignature ( const valtype vchSig)
static

Definition at line 189 of file interpreter.cpp.

Here is the caller graph for this function:

◆ IsLowDERSignature()

static bool IsLowDERSignature ( const valtype vchSig,
ScriptError serror 
)
static

Definition at line 172 of file interpreter.cpp.

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

◆ IsValidSignatureEncoding()

static bool IsValidSignatureEncoding ( const std::vector< unsigned char > &  sig)
static

A canonical signature exists of: <30> <total len>=""> <02> <len r>=""> <R> <02> <len s>=""> <S> <hashtype> Where R and S are not negative (their first byte has its highest bit not set), and not excessively padded (do not start with a 0 byte, unless an otherwise negative number follows, in which case a single 0 byte is necessary and even required).

See https://bitcointalk.org/index.php?topic=8392.msg127623#msg127623

This function is consensus-critical since BIP66.

Definition at line 107 of file interpreter.cpp.

Here is the caller graph for this function:

◆ popstack()

static void popstack ( std::vector< valtype > &  stack)
inlinestatic

Definition at line 56 of file interpreter.cpp.

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 
)

Definition at line 1321 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 
)

Definition at line 1561 of file interpreter.cpp.

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

◆ VerifyWitnessProgram()

static bool VerifyWitnessProgram ( const CScriptWitness witness,
int  witversion,
const std::vector< unsigned char > &  program,
unsigned int  flags,
const BaseSignatureChecker checker,
ScriptError serror 
)
static

Definition at line 1522 of file interpreter.cpp.

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

◆ WitnessSigOps()

static size_t WitnessSigOps ( int  witversion,
const std::vector< unsigned char > &  witprogram,
const CScriptWitness witness 
)
static

Definition at line 1682 of file interpreter.cpp.

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