26typedef std::vector<unsigned char>
valtype;
48 for (
unsigned int i = 0; i < vch.size(); i++)
53 if (i == vch.size()-1 && vch[i] == 0x80)
65#define stacktop(i) (stack.at(size_t(int64_t(stack.size()) + int64_t{i})))
66#define altstacktop(i) (altstack.at(size_t(int64_t(altstack.size()) + int64_t{i})))
67static inline void popstack(std::vector<valtype>& stack)
70 throw std::runtime_error(
"popstack(): stack empty");
79 if (vchPubKey[0] == 0x04) {
84 }
else if (vchPubKey[0] == 0x02 || vchPubKey[0] == 0x03) {
101 if (vchPubKey[0] != 0x02 && vchPubKey[0] != 0x03) {
132 if (sig.size() < 9)
return false;
133 if (sig.size() > 73)
return false;
136 if (sig[0] != 0x30)
return false;
139 if (sig[1] != sig.size() - 3)
return false;
142 unsigned int lenR = sig[3];
145 if (5 + lenR >= sig.size())
return false;
148 unsigned int lenS = sig[5 + lenR];
152 if ((
size_t)(lenR + lenS + 7) != sig.size())
return false;
155 if (sig[2] != 0x02)
return false;
158 if (lenR == 0)
return false;
161 if (sig[4] & 0x80)
return false;
165 if (lenR > 1 && (sig[4] == 0x00) && !(sig[5] & 0x80))
return false;
168 if (sig[lenR + 4] != 0x02)
return false;
171 if (lenS == 0)
return false;
174 if (sig[lenR + 6] & 0x80)
return false;
178 if (lenS > 1 && (sig[lenR + 6] == 0x00) && !(sig[lenR + 7] & 0x80))
return false;
190 std::vector<unsigned char> vchSigCopy(vchSig.begin(), vchSig.begin() + vchSig.size() - 1);
201 if (vchSig.size() == 0) {
214 if (vchSig.size() == 0) {
250 while (
static_cast<size_t>(end - pc) >= b.
size() && std::equal(b.
begin(), b.
end(), pc))
257 while (
script.GetOp(pc, opcode));
261 script = std::move(result);
283class ConditionStack {
286 static constexpr uint32_t NO_FALSE = std::numeric_limits<uint32_t>::max();
289 uint32_t m_stack_size = 0;
291 uint32_t m_first_false_pos = NO_FALSE;
294 bool empty()
const {
return m_stack_size == 0; }
295 bool all_true()
const {
return m_first_false_pos == NO_FALSE; }
296 void push_back(
bool f)
298 if (m_first_false_pos == NO_FALSE && !f) {
301 m_first_false_pos = m_stack_size;
309 if (m_first_false_pos == m_stack_size) {
311 m_first_false_pos = NO_FALSE;
317 if (m_first_false_pos == NO_FALSE) {
319 m_first_false_pos = m_stack_size - 1;
320 }
else if (m_first_false_pos == m_stack_size - 1) {
322 m_first_false_pos = NO_FALSE;
336 CScript scriptCode(pbegincodehash, pend);
367 success = !sig.empty();
377 if (pubkey.size() == 0) {
379 }
else if (pubkey.size() == 32) {
404 switch (sigversion) {
423 static const valtype vchFalse(0);
425 static const valtype vchTrue(1, 1);
435 ConditionStack vfExec;
436 std::vector<valtype> altstack;
443 uint32_t opcode_pos = 0;
449 for (; pc < pend; ++opcode_pos) {
450 bool fExec = vfExec.all_true();
455 if (!
script.GetOp(pc, opcode, vchPushValue))
492 stack.push_back(vchPushValue);
519 stack.push_back(bn.
getvch());
539 if (stack.size() < 1)
578 if (stack.size() < 1)
620 if (stack.size() < 1)
627 if (vch.size() > 1 || (vch.size() == 1 && vch[0] != 1)) {
635 if (vch.size() == 1 && vch[0] != 1)
643 vfExec.push_back(fValue);
667 if (stack.size() < 1)
689 if (stack.size() < 1)
698 if (altstack.size() < 1)
708 if (stack.size() < 2)
718 if (stack.size() < 2)
722 stack.push_back(vch1);
723 stack.push_back(vch2);
730 if (stack.size() < 3)
735 stack.push_back(vch1);
736 stack.push_back(vch2);
737 stack.push_back(vch3);
744 if (stack.size() < 4)
748 stack.push_back(vch1);
749 stack.push_back(vch2);
756 if (stack.size() < 6)
760 stack.erase(stack.end()-6, stack.end()-4);
761 stack.push_back(vch1);
762 stack.push_back(vch2);
769 if (stack.size() < 4)
779 if (stack.size() < 1)
783 stack.push_back(vch);
791 stack.push_back(bn.
getvch());
798 if (stack.size() < 1)
807 if (stack.size() < 1)
810 stack.push_back(vch);
817 if (stack.size() < 2)
819 stack.erase(stack.end() - 2);
826 if (stack.size() < 2)
829 stack.push_back(vch);
838 if (stack.size() < 2)
842 if (n < 0 || n >= (
int)stack.size())
846 stack.erase(stack.end()-n-1);
847 stack.push_back(vch);
856 if (stack.size() < 3)
866 if (stack.size() < 2)
875 if (stack.size() < 2)
878 stack.insert(stack.end()-2, vch);
886 if (stack.size() < 1)
889 stack.push_back(bn.
getvch());
902 if (stack.size() < 2)
906 bool fEqual = (vch1 == vch2);
914 stack.push_back(fEqual ? vchTrue : vchFalse);
937 if (stack.size() < 1)
942 case OP_1ADD: bn += bnOne;
break;
943 case OP_1SUB: bn -= bnOne;
break;
945 case OP_ABS:
if (bn < bnZero) bn = -bn;
break;
946 case OP_NOT: bn = (bn == bnZero);
break;
948 default:
assert(!
"invalid opcode");
break;
951 stack.push_back(bn.
getvch());
970 if (stack.size() < 2)
985 case OP_BOOLAND: bn = (bn1 != bnZero && bn2 != bnZero);
break;
986 case OP_BOOLOR: bn = (bn1 != bnZero || bn2 != bnZero);
break;
994 case OP_MIN: bn = (bn1 < bn2 ? bn1 : bn2);
break;
995 case OP_MAX: bn = (bn1 > bn2 ? bn1 : bn2);
break;
996 default:
assert(!
"invalid opcode");
break;
1000 stack.push_back(bn.
getvch());
1015 if (stack.size() < 3)
1020 bool fValue = (bn2 <= bn1 && bn1 < bn3);
1024 stack.push_back(fValue ? vchTrue : vchFalse);
1039 if (stack.size() < 1)
1054 stack.push_back(vchHash);
1064 pbegincodehash = pc;
1073 if (stack.size() < 2)
1079 bool fSuccess =
true;
1080 if (!
EvalChecksig(vchSig, vchPubKey, pbegincodehash, pend, execdata,
flags, checker, sigversion, serror, fSuccess))
return false;
1083 stack.push_back(fSuccess ? vchTrue : vchFalse);
1106 bool success =
true;
1107 if (!
EvalChecksig(sig, pubkey, pbegincodehash, pend, execdata,
flags, checker, sigversion, serror, success))
return false;
1111 stack.push_back((num + (success ? 1 : 0)).getvch());
1123 if ((
int)stack.size() < i)
1129 nOpCount += nKeysCount;
1135 int ikey2 = nKeysCount + 2;
1137 if ((
int)stack.size() < i)
1141 if (nSigsCount < 0 || nSigsCount > nKeysCount)
1145 if ((
int)stack.size() < i)
1149 CScript scriptCode(pbegincodehash, pend);
1152 for (
int k = 0;
k < nSigsCount;
k++)
1162 bool fSuccess =
true;
1163 while (fSuccess && nSigsCount > 0)
1189 if (nSigsCount > nKeysCount)
1209 if (stack.size() < 1)
1215 stack.push_back(fSuccess ? vchTrue : vchFalse);
1245 if (!vfExec.empty())
1248 return set_success(serror);
1264class CTransactionSignatureSerializer
1269 const unsigned int nIn;
1270 const bool fAnyoneCanPay;
1271 const bool fHashSingle;
1272 const bool fHashNone;
1275 CTransactionSignatureSerializer(
const T& txToIn,
const CScript& scriptCodeIn,
unsigned int nInIn,
int nHashTypeIn) :
1276 txTo(txToIn), scriptCode(scriptCodeIn), nIn(nInIn),
1282 template<
typename S>
1283 void SerializeScriptCode(
S &
s)
const {
1287 unsigned int nCodeSeparators = 0;
1288 while (scriptCode.
GetOp(it, opcode)) {
1294 while (scriptCode.
GetOp(it, opcode)) {
1296 s.write(std::as_bytes(std::span{&itBegin[0], size_t(it - itBegin - 1)}));
1300 if (itBegin != scriptCode.
end())
1301 s.write(std::as_bytes(std::span{&itBegin[0],
size_t(it - itBegin)}));
1305 template<
typename S>
1306 void SerializeInput(
S &
s,
unsigned int nInput)
const {
1317 SerializeScriptCode(
s);
1319 if (nInput != nIn && (fHashSingle || fHashNone))
1327 template<
typename S>
1328 void SerializeOutput(
S &
s,
unsigned int nOutput)
const {
1329 if (fHashSingle && nOutput != nIn)
1337 template<
typename S>
1342 unsigned int nInputs = fAnyoneCanPay ? 1 : txTo.vin.size();
1344 for (
unsigned int nInput = 0; nInput < nInputs; nInput++)
1345 SerializeInput(
s, nInput);
1347 unsigned int nOutputs = fHashNone ? 0 : (fHashSingle ? nIn+1 : txTo.vout.size());
1349 for (
unsigned int nOutput = 0; nOutput < nOutputs; nOutput++)
1350 SerializeOutput(
s, nOutput);
1358uint256 GetPrevoutsSHA256(
const T& txTo)
1361 for (
const auto& txin : txTo.vin) {
1369uint256 GetSequencesSHA256(
const T& txTo)
1372 for (
const auto& txin : txTo.vin) {
1373 ss << txin.nSequence;
1380uint256 GetOutputsSHA256(
const T& txTo)
1383 for (
const auto& txout : txTo.vout) {
1390uint256 GetSpentAmountsSHA256(
const std::vector<CTxOut>& outputs_spent)
1393 for (
const auto& txout : outputs_spent) {
1400uint256 GetSpentScriptsSHA256(
const std::vector<CTxOut>& outputs_spent)
1403 for (
const auto& txout : outputs_spent) {
1404 ss << txout.scriptPubKey;
1424 bool uses_bip143_segwit = force;
1425 bool uses_bip341_taproot = force;
1426 for (
size_t inpos = 0; inpos < txTo.vin.size() && !(uses_bip143_segwit && uses_bip341_taproot); ++inpos) {
1427 if (!txTo.vin[inpos].scriptWitness.IsNull()) {
1434 uses_bip341_taproot =
true;
1439 uses_bip143_segwit =
true;
1442 if (uses_bip341_taproot && uses_bip143_segwit)
break;
1445 if (uses_bip143_segwit || uses_bip341_taproot) {
1451 if (uses_bip143_segwit) {
1489 assert(!
"Unknown MissingDataBehavior value");
1495 uint8_t ext_flag, key_version;
1496 switch (sigversion) {
1512 assert(in_pos < tx_to.vin.size());
1520 static constexpr uint8_t EPOCH = 0;
1526 if (!(hash_type <= 0x03 || (hash_type >= 0x81 && hash_type <= 0x83)))
return false;
1530 ss << tx_to.version;
1531 ss << tx_to.nLockTime;
1545 const uint8_t spend_type = (ext_flag << 1) + (have_annex ? 1 : 0);
1548 ss << tx_to.vin[in_pos].prevout;
1550 ss << tx_to.vin[in_pos].nSequence;
1560 if (in_pos >= tx_to.vout.size())
return false;
1563 sha_single_output << tx_to.vout[in_pos];
1578 hash_out = ss.GetSHA256();
1593 auto& entry = m_cache_entries[CacheIndex(hash_type)];
1594 if (entry.has_value()) {
1595 if (script_code == entry->first) {
1605 auto& entry = m_cache_entries[CacheIndex(hash_type)];
1606 entry.emplace(script_code, writer);
1612 assert(nIn < txTo.vin.size());
1617 if (nIn >= txTo.vout.size()) {
1627 if (sighash_cache && sighash_cache->
Load(nHashType, scriptCode, ss)) {
1649 }
else if ((nHashType & 0x1f) ==
SIGHASH_SINGLE && nIn < txTo.vout.size()) {
1651 inner_ss << txTo.vout[nIn];
1652 hashOutputs = inner_ss.GetHash();
1663 ss << txTo.vin[nIn].prevout;
1666 ss << txTo.vin[nIn].nSequence;
1670 ss << txTo.nLockTime;
1673 CTransactionSignatureSerializer<T> txTmp(txTo, scriptCode, nIn, nHashType);
1680 if (sighash_cache !=
nullptr) {
1681 sighash_cache->
Store(nHashType, scriptCode, ss);
1686 return ss.GetHash();
1692 return pubkey.
Verify(sighash, vchSig);
1709 std::vector<unsigned char> vchSig(vchSigIn);
1712 int nHashType = vchSig.back();
1718 uint256 sighash =
SignatureHash(scriptCode, *txTo, nIn, nHashType, amount, sigversion, this->txdata, &m_sighash_cache);
1720 if (!VerifyECDSASignature(vchSig, pubkey, sighash))
1731 assert(pubkey_in.size() == 32);
1741 if (sig.size() == 65) {
1747 if (!
SignatureHashSchnorr(sighash, execdata, *txTo, nIn, hashtype, sigversion, *this->txdata, m_mdb)) {
1772 if (nLockTime > (int64_t)txTo->nLockTime)
1796 const int64_t txToSequence = (int64_t)txTo->vin[nIn].nSequence;
1800 if (txTo->version < 2)
1813 const int64_t txToSequenceMasked = txToSequence & nLockTimeMask;
1814 const CScriptNum nSequenceMasked = nSequence & nLockTimeMask;
1832 if (nSequenceMasked > txToSequenceMasked)
1844 std::vector<valtype> stack{stack_span.begin(), stack_span.end()};
1849 while (pc < exec_script.
end()) {
1851 if (!exec_script.
GetOp(pc, opcode)) {
1860 return set_success(serror);
1869 for (
const valtype& elem : stack) {
1874 if (!
EvalScript(stack, exec_script,
flags, checker, sigversion, execdata, serror))
return false;
1890 if (std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end())) {
1891 ss_branch << a << b;
1893 ss_branch << b << a;
1906 for (
int i = 0; i < path_len; ++i) {
1924 return q.CheckTapTweak(p, merkle_root, control[0] & 1);
1930 std::span stack{witness.
stack};
1933 if (witversion == 0) {
1936 if (stack.size() == 0) {
1940 exec_script =
CScript(script_bytes.begin(), script_bytes.end());
1943 if (memcmp(hash_exec_script.
begin(), program.data(), 32)) {
1949 if (stack.size() != 2) {
1961 if (stack.size() >= 2 && !stack.back().empty() && stack.back()[0] ==
ANNEX_TAG) {
1970 if (stack.size() == 1) {
1975 return set_success(serror);
1998 return set_success(serror);
2015 if (witness ==
nullptr) {
2016 witness = &emptyWitness;
2018 bool hadWitness =
false;
2028 std::vector<std::vector<unsigned char> > stack, stackCopy;
2044 std::vector<unsigned char> witnessprogram;
2048 if (scriptSig.
size() != 0) {
2069 swap(stack, stackCopy);
2076 const valtype& pubKeySerialized = stack.back();
2077 CScript pubKey2(pubKeySerialized.begin(), pubKeySerialized.end());
2092 if (scriptSig !=
CScript() << std::vector<unsigned char>(pubKey2.
begin(), pubKey2.
end())) {
2115 if (stack.size() != 1) {
2125 if (!hadWitness && !witness->
IsNull()) {
2130 return set_success(serror);
2135 if (witversion == 0) {
2157 std::vector<unsigned char> witnessprogram;
2159 return WitnessSigOps(witnessversion, witnessprogram, witness);
2164 std::vector<unsigned char>
data;
2165 while (pc < scriptSig.
end()) {
2171 return WitnessSigOps(witnessversion, witnessprogram, witness);
2180#define FLAG_NAME(flag) {std::string(#flag), SCRIPT_VERIFY_##flag}
2181 static const std::map<std::string, script_verify_flag_name> g_names_to_enum{
2196 FLAG_NAME(DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM),
2200 FLAG_NAME(DISCOURAGE_UPGRADABLE_PUBKEYTYPE),
2202 FLAG_NAME(DISCOURAGE_UPGRADABLE_TAPROOT_VERSION),
2205 return g_names_to_enum;
2210 std::vector<std::string> res;
2216 if ((
flags & flag) != 0) {
2217 res.push_back(
name);
2221 if (leftover != 0) {
std::vector< unsigned char > valtype
int64_t CAmount
Amount in satoshis (Can be negative)
virtual bool CheckLockTime(const CScriptNum &nLockTime) const
virtual bool CheckSchnorrSignature(std::span< const unsigned char > sig, std::span< const unsigned char > pubkey, SigVersion sigversion, ScriptExecutionData &execdata, ScriptError *serror=nullptr) const
virtual bool CheckSequence(const CScriptNum &nSequence) const
virtual bool CheckECDSASignature(const std::vector< unsigned char > &scriptSig, const std::vector< unsigned char > &vchPubKey, const CScript &scriptCode, SigVersion sigversion) const
A hasher class for Bitcoin's 160-bit hash (SHA-256 + RIPEMD-160).
CHash160 & Write(std::span< const unsigned char > input)
void Finalize(std::span< unsigned char > output)
A hasher class for Bitcoin's 256-bit hash (double SHA-256).
void Finalize(std::span< unsigned char > output)
CHash256 & Write(std::span< const unsigned char > input)
An encapsulated public key.
static constexpr unsigned int COMPRESSED_SIZE
static bool CheckLowS(const std::vector< unsigned char > &vchSig)
Check whether a signature is normalized (lower-S).
bool Verify(const uint256 &hash, const std::vector< unsigned char > &vchSig) const
Verify a DER signature (~72 bytes).
static constexpr unsigned int SIZE
secp256k1:
A hasher class for RIPEMD-160.
CRIPEMD160 & Write(const unsigned char *data, size_t len)
void Finalize(unsigned char hash[OUTPUT_SIZE])
CSHA1 & Write(const unsigned char *data, size_t len)
void Finalize(unsigned char hash[OUTPUT_SIZE])
A hasher class for SHA-256.
void Finalize(unsigned char hash[OUTPUT_SIZE])
CSHA256 & Write(const unsigned char *data, size_t len)
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
unsigned int GetSigOpCount(bool fAccurate) const
Pre-version-0.6, Bitcoin always counted CHECKMULTISIGs as 20 sigops.
bool IsPayToAnchor() const
bool GetOp(const_iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > &vchRet) const
bool IsWitnessProgram(int &version, std::vector< unsigned char > &program) const
std::vector< unsigned char > getvch() const
The basic transaction that is broadcasted on the network and contained in blocks.
static const uint32_t SEQUENCE_LOCKTIME_DISABLE_FLAG
If this flag is 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/IsFinalTx().
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 CheckSchnorrSignature(std::span< const unsigned char > sig, std::span< const unsigned char > pubkey, SigVersion sigversion, ScriptExecutionData &execdata, ScriptError *serror=nullptr) const override
bool CheckECDSASignature(const std::vector< unsigned char > &scriptSig, const std::vector< unsigned char > &vchPubKey, const CScript &scriptCode, SigVersion sigversion) const override
bool CheckLockTime(const CScriptNum &nLockTime) const override
virtual bool VerifySchnorrSignature(std::span< const unsigned char > sig, const XOnlyPubKey &pubkey, const uint256 &sighash) const
virtual bool VerifyECDSASignature(const std::vector< unsigned char > &vchSig, const CPubKey &vchPubKey, const uint256 &sighash) const
bool CheckSequence(const CScriptNum &nSequence) const 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.
uint256 GetSHA256()
Compute the SHA256 hash of all data written to this object.
Data structure to cache SHA256 midstates for the ECDSA sighash calculations (bare,...
void Store(int32_t hash_type, const CScript &script_code, const HashWriter &writer) noexcept
Store into this cache object the provided SHA256 midstate.
bool Load(int32_t hash_type, const CScript &script_code, HashWriter &writer) const noexcept
Load into writer the SHA256 midstate if found in this cache.
int CacheIndex(int32_t hash_type) const noexcept
Given a hash_type, find which of the 6 cache entries is to be used.
bool VerifySchnorr(const uint256 &msg, std::span< const unsigned char > sigbytes) const
Verify a Schnorr signature against this public key.
static constexpr unsigned int size()
constexpr unsigned char * begin()
iterator insert(iterator pos, const T &value)
constexpr value_type as_int() const
HashWriter TaggedHash(const std::string &tag)
Return a HashWriter primed for tagged hashes (as specified in BIP 340).
uint256 SHA256Uint256(const uint256 &input)
Single-SHA256 a 32-byte input (represented as uint256).
uint256 ComputeTapbranchHash(std::span< const unsigned char > a, std::span< const unsigned char > b)
Compute the BIP341 tapbranch hash from two branches.
const std::map< std::string, script_verify_flag_name > & ScriptFlagNamesToEnum()
static bool IsDefinedHashtypeSignature(const valtype &vchSig)
bool SignatureHashSchnorr(uint256 &hash_out, ScriptExecutionData &execdata, const T &tx_to, uint32_t in_pos, uint8_t hash_type, SigVersion sigversion, const PrecomputedTransactionData &cache, MissingDataBehavior mdb)
static bool EvalChecksigTapscript(const valtype &sig, const valtype &pubkey, ScriptExecutionData &execdata, script_verify_flags flags, const BaseSignatureChecker &checker, SigVersion sigversion, ScriptError *serror, bool &success)
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> <hashtype> Where R a...
uint256 ComputeTaprootMerkleRoot(std::span< const unsigned char > control, const uint256 &tapleaf_hash)
Compute the BIP341 taproot script tree Merkle root from control block and leaf hash.
bool CastToBool(const valtype &vch)
int FindAndDelete(CScript &script, const CScript &b)
static bool EvalChecksig(const valtype &sig, const valtype &pubkey, CScript::const_iterator pbegincodehash, CScript::const_iterator pend, ScriptExecutionData &execdata, script_verify_flags flags, const BaseSignatureChecker &checker, SigVersion sigversion, ScriptError *serror, bool &success)
Helper for OP_CHECKSIG, OP_CHECKSIGVERIFY, and (in Tapscript) OP_CHECKSIGADD.
const HashWriter HASHER_TAPBRANCH
Hasher with tag "TapBranch" pre-fed to it.
static void popstack(std::vector< valtype > &stack)
static bool IsLowDERSignature(const valtype &vchSig, ScriptError *serror)
size_t CountWitnessSigOps(const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness &witness, script_verify_flags flags)
uint256 ComputeTapleafHash(uint8_t leaf_version, std::span< const unsigned char > script)
Compute the BIP341 tapleaf hash from leaf version & script.
bool EvalScript(std::vector< std::vector< unsigned char > > &stack, const CScript &script, script_verify_flags flags, const BaseSignatureChecker &checker, SigVersion sigversion, ScriptExecutionData &execdata, ScriptError *serror)
uint256 SignatureHash(const CScript &scriptCode, const T &txTo, unsigned int nIn, int32_t nHashType, const CAmount &amount, SigVersion sigversion, const PrecomputedTransactionData *cache, SigHashCache *sighash_cache)
static bool ExecuteWitnessScript(const std::span< const valtype > &stack_span, const CScript &exec_script, script_verify_flags flags, SigVersion sigversion, const BaseSignatureChecker &checker, ScriptExecutionData &execdata, ScriptError *serror)
static size_t WitnessSigOps(int witversion, const std::vector< unsigned char > &witprogram, const CScriptWitness &witness)
std::vector< unsigned char > valtype
static bool IsCompressedOrUncompressedPubKey(const valtype &vchPubKey)
std::vector< std::string > GetScriptFlagNames(script_verify_flags flags)
bool CheckSignatureEncoding(const std::vector< unsigned char > &vchSig, script_verify_flags flags, ScriptError *serror)
#define stacktop(i)
Script is a stack machine (like Forth) that evaluates a predicate returning a bool indicating valid o...
const HashWriter HASHER_TAPLEAF
Hasher with tag "TapLeaf" pre-fed to it.
static bool VerifyWitnessProgram(const CScriptWitness &witness, int witversion, const std::vector< unsigned char > &program, script_verify_flags flags, const BaseSignatureChecker &checker, ScriptError *serror, bool is_p2sh)
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, script_verify_flags flags, const BaseSignatureChecker &checker, ScriptError *serror)
static bool HandleMissingData(MissingDataBehavior mdb)
static bool CheckPubKeyEncoding(const valtype &vchPubKey, script_verify_flags flags, const SigVersion &sigversion, ScriptError *serror)
static bool EvalChecksigPreTapscript(const valtype &vchSig, const valtype &vchPubKey, CScript::const_iterator pbegincodehash, CScript::const_iterator pend, script_verify_flags flags, const BaseSignatureChecker &checker, SigVersion sigversion, ScriptError *serror, bool &fSuccess)
static bool VerifyTaprootCommitment(const std::vector< unsigned char > &control, const std::vector< unsigned char > &program, const uint256 &tapleaf_hash)
const HashWriter HASHER_TAPSIGHASH
Hasher with tag "TapSighash" pre-fed to it.
static constexpr size_t WITNESS_V0_KEYHASH_SIZE
@ TAPROOT
Witness v1 with 32-byte program, not BIP16 P2SH-wrapped, key path spending; see BIP 341.
@ BASE
Bare scripts and BIP16 P2SH-wrapped redeemscripts.
@ TAPSCRIPT
Witness v1 with 32-byte program, not BIP16 P2SH-wrapped, script path spending, leaf version 0xc0; see...
@ WITNESS_V0
Witness v0 (P2WPKH and P2WSH); see BIP 141.
static constexpr uint8_t TAPROOT_LEAF_MASK
static constexpr uint8_t TAPROOT_LEAF_TAPSCRIPT
static constexpr size_t WITNESS_V0_SCRIPTHASH_SIZE
Signature hash sizes.
@ SIGHASH_DEFAULT
Taproot only; implied when sighash byte is missing, and equivalent to SIGHASH_ALL.
static constexpr size_t TAPROOT_CONTROL_NODE_SIZE
static constexpr size_t WITNESS_V1_TAPROOT_SIZE
MissingDataBehavior
Enum to specify what *TransactionSignatureChecker's behavior should be when dealing with missing tran...
@ ASSERT_FAIL
Abort execution through assertion failure (for consensus code)
@ FAIL
Just act as if the signature was invalid.
static constexpr size_t TAPROOT_CONTROL_MAX_SIZE
@ SCRIPT_VERIFY_NULLDUMMY
@ SCRIPT_VERIFY_STRICTENC
@ SCRIPT_VERIFY_CHECKSEQUENCEVERIFY
@ SCRIPT_VERIFY_CLEANSTACK
@ SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY
@ SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS
@ SCRIPT_VERIFY_DISCOURAGE_OP_SUCCESS
@ SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_TAPROOT_VERSION
@ SCRIPT_VERIFY_SIGPUSHONLY
@ SCRIPT_VERIFY_WITNESS_PUBKEYTYPE
@ SCRIPT_VERIFY_MINIMALIF
@ SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM
@ SCRIPT_VERIFY_MINIMALDATA
@ SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_PUBKEYTYPE
@ SCRIPT_VERIFY_CONST_SCRIPTCODE
static constexpr script_verify_flags SCRIPT_VERIFY_NONE
Script verification flags.
static constexpr size_t TAPROOT_CONTROL_BASE_SIZE
#define S(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)
bool CheckMinimalPush(const std::vector< unsigned char > &data, opcodetype opcode)
bool IsOpSuccess(const opcodetype &opcode)
Test for OP_SUCCESSx opcodes as defined by BIP342.
static constexpr int64_t VALIDATION_WEIGHT_PER_SIGOP_PASSED
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 constexpr int64_t VALIDATION_WEIGHT_OFFSET
static const int MAX_PUBKEYS_PER_MULTISIG
static constexpr unsigned int ANNEX_TAG
enum ScriptError_t ScriptError
@ SCRIPT_ERR_OP_CODESEPARATOR
@ SCRIPT_ERR_SIG_PUSHONLY
@ SCRIPT_ERR_DISCOURAGE_UPGRADABLE_PUBKEYTYPE
@ SCRIPT_ERR_NUMEQUALVERIFY
@ SCRIPT_ERR_TAPSCRIPT_CHECKMULTISIG
@ SCRIPT_ERR_DISABLED_OPCODE
@ SCRIPT_ERR_DISCOURAGE_UPGRADABLE_TAPROOT_VERSION
@ SCRIPT_ERR_INVALID_ALTSTACK_OPERATION
@ SCRIPT_ERR_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM
@ SCRIPT_ERR_TAPSCRIPT_EMPTY_PUBKEY
@ SCRIPT_ERR_TAPSCRIPT_MINIMALIF
@ SCRIPT_ERR_UNKNOWN_ERROR
@ SCRIPT_ERR_WITNESS_PROGRAM_WRONG_LENGTH
@ SCRIPT_ERR_SIG_HASHTYPE
@ SCRIPT_ERR_CHECKSIGVERIFY
@ SCRIPT_ERR_WITNESS_MALLEATED_P2SH
@ SCRIPT_ERR_SCHNORR_SIG_SIZE
@ SCRIPT_ERR_WITNESS_MALLEATED
@ SCRIPT_ERR_DISCOURAGE_UPGRADABLE_NOPS
@ SCRIPT_ERR_TAPSCRIPT_VALIDATION_WEIGHT
@ SCRIPT_ERR_INVALID_STACK_OPERATION
@ SCRIPT_ERR_DISCOURAGE_OP_SUCCESS
@ SCRIPT_ERR_WITNESS_UNEXPECTED
@ SCRIPT_ERR_NEGATIVE_LOCKTIME
@ SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH
@ SCRIPT_ERR_SIG_NULLFAIL
@ SCRIPT_ERR_SIG_NULLDUMMY
@ SCRIPT_ERR_CHECKMULTISIGVERIFY
@ SCRIPT_ERR_TAPROOT_WRONG_CONTROL_SIZE
@ SCRIPT_ERR_UNSATISFIED_LOCKTIME
@ SCRIPT_ERR_WITNESS_PUBKEYTYPE
@ SCRIPT_ERR_SIG_FINDANDDELETE
@ SCRIPT_ERR_PUBKEY_COUNT
@ SCRIPT_ERR_WITNESS_PROGRAM_WITNESS_EMPTY
@ SCRIPT_ERR_SCHNORR_SIG_HASHTYPE
@ SCRIPT_ERR_UNBALANCED_CONDITIONAL
void Serialize(Stream &, V)=delete
void WriteCompactSize(SizeComputer &os, uint64_t nSize)
uint64_t GetSerializeSize(const T &t)
T & SpanPopBack(std::span< T > &span)
A span is an object that can refer to a contiguous sequence of objects.
A mutable version of CTransaction.
std::vector< std::vector< unsigned char > > stack
void Init(const T &tx, std::vector< CTxOut > &&spent_outputs, bool force=false)
Initialize this PrecomputedTransactionData with transaction data.
uint256 m_sequences_single_hash
bool m_bip341_taproot_ready
Whether the 5 fields above are initialized.
PrecomputedTransactionData()=default
bool m_bip143_segwit_ready
Whether the 3 fields above are initialized.
uint256 m_prevouts_single_hash
uint256 m_spent_amounts_single_hash
uint256 m_spent_scripts_single_hash
bool m_spent_outputs_ready
Whether m_spent_outputs is initialized.
uint256 m_outputs_single_hash
std::vector< CTxOut > m_spent_outputs
std::optional< uint256 > m_output_hash
The hash of the corresponding output.
uint256 m_tapleaf_hash
The tapleaf hash.
uint256 m_annex_hash
Hash of the annex data.
int64_t m_validation_weight_left
How much validation weight is left (decremented for every successful non-empty signature check).
bool m_annex_present
Whether an annex is present.
bool m_annex_init
Whether m_annex_present and (when needed) m_annex_hash are initialized.
bool m_codeseparator_pos_init
Whether m_codeseparator_pos is initialized.
bool m_tapleaf_hash_init
Whether m_tapleaf_hash is initialized.
bool m_validation_weight_left_init
Whether m_validation_weight_left is initialized.
uint32_t m_codeseparator_pos
Opcode position of the last executed OP_CODESEPARATOR (or 0xFFFFFFFF if none executed).