20 for (
size_t i = 0; i < vch.size(); i++) {
23 if (i == vch.size() - 1 && vch[i] == 0x80) {
36#define stacktop(i) (stack.at(stack.size() + (i)))
37#define altstacktop(i) (altstack.at(altstack.size() + (i)))
38static inline void popstack(std::vector<valtype> &stack) {
40 throw std::runtime_error(
"popstack(): stack empty");
57 while (
static_cast<size_t>(end - pc) >=
b.size() &&
58 std::equal(
b.begin(),
b.end(), pc)) {
63 }
while (script.
GetOp(pc, opcode));
67 script = std::move(result);
74 const std::vector<uint8_t> &
vchSig,
123 CScript scriptCode(pbegincodehash, pend);
169 std::vector<uint8_t> &
vchRet)
const {
278 if (
stack.size() < 1) {
321 if (
stack.size() < 1) {
373 if (
stack.size() < 1) {
379 if (vch.size() > 1) {
382 if (vch.size() == 1 && vch[0] != 1) {
414 if (
stack.size() < 1) {
434 if (
stack.size() < 1) {
453 if (
stack.size() < 2) {
463 if (
stack.size() < 2) {
475 if (
stack.size() < 3) {
489 if (
stack.size() < 4) {
501 if (
stack.size() < 6) {
514 if (
stack.size() < 4) {
524 if (
stack.size() < 1) {
530 stack.push_back(vch);
542 if (
stack.size() < 1) {
551 if (
stack.size() < 1) {
556 stack.push_back(vch);
561 if (
stack.size() < 2) {
570 if (
stack.size() < 2) {
575 stack.push_back(vch);
582 if (
stack.size() < 2) {
596 stack.push_back(vch);
603 if (
stack.size() < 3) {
613 if (
stack.size() < 2) {
622 if (
stack.size() < 2) {
632 if (
stack.size() < 1) {
647 if (
stack.size() < 2) {
662 for (
size_t i = 0; i <
vch1.size(); ++i) {
667 for (
size_t i = 0; i <
vch1.size(); ++i) {
672 for (
size_t i = 0; i <
vch1.size(); ++i) {
689 if (
stack.size() < 2) {
726 if (
stack.size() < 1) {
753 assert(!
"invalid opcode");
776 if (
stack.size() < 2) {
842 assert(!
"invalid opcode");
860 if (
stack.size() < 3) {
883 if (
stack.size() < 1) {
894 .
Write(vch.data(), vch.size())
896 }
else if (opcode ==
OP_SHA1) {
898 .
Write(vch.data(), vch.size())
902 .
Write(vch.data(), vch.size())
921 if (
stack.size() < 2) {
948 if (
stack.size() < 3) {
1050 "Schnorr multisig checkbits implementation "
1051 "assumes < 32 pubkeys.");
1199 for (
size_t i = 0; i <
idxDummy; i++) {
1219 if (
stack.size() < 2) {
1234 if (
stack.size() < 2) {
1260 if (
stack.size() < 1) {
1266 std::reverse(data.begin(), data.end());
1274 if (
stack.size() < 2) {
1291 if (
rawnum.size() > size) {
1298 if (
rawnum.size() == size) {
1309 while (
rawnum.size() < size - 1) {
1318 if (
stack.size() < 1) {
1360template <
class T>
class CTransactionSignatureSerializer {
1367 const unsigned int nIn;
1372 CTransactionSignatureSerializer(
const T &
txToIn,
1385 while (scriptCode.
GetOp(it, opcode)) {
1392 while (scriptCode.
GetOp(it, opcode)) {
1431 template <
typename S>
1443 template <
typename S>
void Serialize(
S &s)
const {
1459 : txTo.vout.size());
1471 for (
const auto &
txin : txTo.vin) {
1479 for (
const auto &
txin : txTo.vin) {
1487 for (
const auto &txout : txTo.vout) {
1513 assert(nIn < txTo.vin.size());
1542 (nIn < txTo.vout.size())) {
1544 ss << txTo.vout[nIn];
1545 hashOutputs =
ss.GetHash();
1550 ss << txTo.nVersion;
1557 ss << txTo.vin[nIn].prevout;
1560 ss << txTo.vin[nIn].nSequence;
1564 ss << txTo.nLockTime;
1568 return ss.GetHash();
1573 (nIn >= txTo.vout.size())) {
1586 return ss.GetHash();
1592 if (
vchSig.size() == 64) {
1601 const std::vector<uint8_t> &
vchSigIn,
const std::vector<uint8_t> &vchPubKey,
1617 this->txdata,
flags);
1645 if (nLockTime >
int64_t(txTo->nLockTime)) {
1674 if (
static_cast<uint32_t>(txTo->nVersion) < 2) {
1750 if (stack.empty()) {
1790 if (stack.empty()) {
1807 if (stack.size() != 1) {
1827 "overflow sanity check on max script size");
1829 "overflow sanity check on maximum possible sigchecks "
1830 "from sig+redeem+pub scripts");
bool DecodeBitfield(const std::vector< uint8_t > &vch, unsigned size, uint32_t &bitfield, ScriptError *serror)
uint32_t countBits(uint32_t v)
virtual bool VerifySignature(const std::vector< uint8_t > &vchSig, const CPubKey &vchPubKey, const uint256 &sighash) const
virtual bool CheckLockTime(const CScriptNum &nLockTime) const
virtual bool CheckSequence(const CScriptNum &nSequence) const
virtual bool CheckSig(const std::vector< uint8_t > &vchSigIn, const std::vector< uint8_t > &vchPubKey, const CScript &scriptCode, uint32_t flags) const
A hasher class for Bitcoin's 160-bit hash (SHA-256 + RIPEMD-160).
CHash160 & Write(Span< const uint8_t > input)
void Finalize(Span< uint8_t > output)
A hasher class for Bitcoin's 256-bit hash (double SHA-256).
CHash256 & Write(Span< const uint8_t > input)
void Finalize(Span< uint8_t > output)
A mutable version of CTransaction.
An encapsulated public key.
bool VerifySchnorr(const uint256 &hash, const std::array< uint8_t, SCHNORR_SIZE > &sig) const
Verify a Schnorr signature (=64 bytes).
bool VerifyECDSA(const uint256 &hash, const std::vector< uint8_t > &vchSig) const
Verify a DER-serialized ECDSA signature (~72 bytes).
A hasher class for RIPEMD-160.
CRIPEMD160 & Write(const uint8_t *data, size_t len)
void Finalize(uint8_t hash[OUTPUT_SIZE])
void Finalize(uint8_t hash[OUTPUT_SIZE])
CSHA1 & Write(const uint8_t *data, size_t len)
A hasher class for SHA-256.
CSHA256 & Write(const uint8_t *data, size_t len)
void Finalize(uint8_t hash[OUTPUT_SIZE])
Serialized script, used inside transaction inputs and outputs.
bool IsPushOnly(const_iterator pc) const
Called by IsStandardTx and P2SH/BIP62 VerifyScript (which makes it consensus-critical).
bool IsPayToScriptHash() const
bool GetOp(const_iterator &pc, opcodetype &opcodeRet, std::vector< uint8_t > &vchRet) const
static bool MinimallyEncode(std::vector< uint8_t > &data)
static bool IsMinimallyEncoded(const std::vector< uint8_t > &vch, const size_t nMaxNumSize=CScriptNum::MAXIMUM_ELEMENT_SIZE)
The basic transaction that is broadcasted on the network and contained in blocks.
static const uint32_t SEQUENCE_LOCKTIME_DISABLE_FLAG
If this flag set, CTxIn::nSequence is NOT interpreted as a relative lock-time.
static const uint32_t SEQUENCE_LOCKTIME_MASK
If CTxIn::nSequence encodes a relative lock-time, this mask is applied to extract that lock-time from...
static const uint32_t SEQUENCE_FINAL
Setting nSequence to this value for every input in a transaction disables nLockTime.
static const uint32_t SEQUENCE_LOCKTIME_TYPE_FLAG
If CTxIn::nSequence encodes a relative lock-time and this flag is set, the relative lock-time has uni...
An output of a transaction.
bool CheckSig(const std::vector< uint8_t > &vchSigIn, const std::vector< uint8_t > &vchPubKey, const CScript &scriptCode, uint32_t flags) const final override
bool CheckSequence(const CScriptNum &nSequence) const final override
bool CheckLockTime(const CScriptNum &nLockTime) const final override
A writer stream (for serialization) that computes a 256-bit hash.
uint256 GetHash()
Compute the double-SHA256 hash of all data written to this object.
CScript::const_iterator pend
bool CheckPostConditions()
std::vector< std::vector< uint8_t > > altstack
CScript::const_iterator pbegincodehash
const ConditionStack & GetConditionStack()
const BaseSignatureChecker & checker
bool CheckPreConditions()
CScript::const_iterator pc
ScriptInterpreter(std::vector< std::vector< uint8_t > > &stack, const CScript &script, uint32_t flags, const BaseSignatureChecker &checker, ScriptExecutionMetrics &metrics)
std::vector< std::vector< uint8_t > > & stack
bool GetNextOp(opcodetype &opcodeRet, std::vector< uint8_t > &vchRet) const
ScriptExecutionMetrics & metrics
Signature hash type wrapper class.
BaseSigHashType getBaseType() const
bool hasAnyoneCanPay() const
SigHashType withForkValue(uint32_t forkId) const
uint32_t getForkValue() const
A Span is an object that can refer to a contiguous sequence of objects.
iterator insert(iterator pos, const T &value)
static bool IsOpcodeDisabled(opcodetype opcode, uint32_t flags)
static void CleanupScriptCode(CScript &scriptCode, const std::vector< uint8_t > &vchSig, uint32_t flags)
uint256 SignatureHash(const CScript &scriptCode, const T &txTo, unsigned int nIn, SigHashType sigHashType, const Amount amount, const PrecomputedTransactionData *cache, uint32_t flags)
bool EvalScript(std::vector< valtype > &stack, const CScript &script, uint32_t flags, const BaseSignatureChecker &checker, ScriptExecutionMetrics &metrics, ScriptError *serror)
static bool EvalChecksig(const valtype &vchSig, const valtype &vchPubKey, CScript::const_iterator pbegincodehash, CScript::const_iterator pend, uint32_t flags, const BaseSignatureChecker &checker, ScriptExecutionMetrics &metrics, ScriptError *serror, bool &fSuccess)
Helper for OP_CHECKSIG and OP_CHECKSIGVERIFY.
bool CastToBool(const valtype &vch)
int FindAndDelete(CScript &script, const CScript &b)
static void popstack(std::vector< valtype > &stack)
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, uint32_t flags, const BaseSignatureChecker &checker, ScriptExecutionMetrics &metricsOut, ScriptError *serror)
Execute an unlocking and locking script together.
#define stacktop(i)
Script is a stack machine (like Forth) that evaluates a predicate returning a bool indicating valid o...
bool CastToBool(const std::vector< uint8_t > &vch)
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
bool CheckMinimalPush(const std::vector< uint8_t > &data, opcodetype opcode)
Check whether the given stack element data would be minimally pushed using the given opcode.
static const unsigned int LOCKTIME_THRESHOLD
static const unsigned int MAX_SCRIPT_ELEMENT_SIZE
static const int MAX_SCRIPT_SIZE
opcodetype
Script opcodes.
static const int MAX_STACK_SIZE
static const int MAX_OPS_PER_SCRIPT
static const int MAX_PUBKEYS_PER_MULTISIG
@ DISCOURAGE_UPGRADABLE_NOPS
@ INVALID_ALTSTACK_OPERATION
@ INVALID_STACK_OPERATION
@ SCRIPT_VERIFY_SIGPUSHONLY
@ SCRIPT_VERIFY_MINIMALIF
@ SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY
@ SCRIPT_ENABLE_REPLAY_PROTECTION
@ SCRIPT_ENABLE_SCHNORR_MULTISIG
@ SCRIPT_VERIFY_STRICTENC
@ SCRIPT_VERIFY_CLEANSTACK
@ SCRIPT_VERIFY_MINIMALDATA
@ SCRIPT_DISALLOW_SEGWIT_RECOVERY
@ SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS
@ SCRIPT_VERIFY_CHECKSEQUENCEVERIFY
@ SCRIPT_ENABLE_SIGHASH_FORKID
@ SCRIPT_VERIFY_INPUT_SIGCHECKS
void Serialize(Stream &, char)=delete
void WriteCompactSize(CSizeComputer &os, uint64_t nSize)
bool CheckTransactionSchnorrSignatureEncoding(const valtype &vchSig, uint32_t flags, ScriptError *serror)
Check that the signature provided to authentify a transaction is properly encoded Schnorr signature (...
bool CheckDataSignatureEncoding(const valtype &vchSig, uint32_t flags, ScriptError *serror)
Check that the signature provided on some data is properly encoded.
bool CheckTransactionECDSASignatureEncoding(const valtype &vchSig, uint32_t flags, ScriptError *serror)
Check that the signature provided to authentify a transaction is properly encoded ECDSA signature.
bool CheckTransactionSignatureEncoding(const valtype &vchSig, uint32_t flags, ScriptError *serror)
Check that the signature provided to authentify a transaction is properly encoded.
bool CheckPubKeyEncoding(const valtype &vchPubKey, uint32_t flags, ScriptError *serror)
Check that a public key is encoded properly.
std::vector< uint8_t > valtype
BaseSigHashType
Base signature hash types Base sig hash types not defined in this enum may be used,...
Span< const std::byte > AsBytes(Span< T > s) noexcept
Precompute sighash midstate to avoid quadratic hashing.
PrecomputedTransactionData()
Struct for holding cumulative results from executing a script or a sequence of scripts.