46 int witnessversion = 0;
47 std::vector<unsigned char> witnessprogram;
57 nSize += (32 + 4 + 1 + (107 / WITNESS_SCALE_FACTOR) + 4);
59 nSize += (32 + 4 + 1 + 107 + 4);
62 return dustRelayFeeIn.
GetFee(nSize);
72 std::vector<uint32_t> dust_outputs;
73 for (uint32_t i{0}; i < tx.
vout.size(); ++i) {
74 if (
IsDust(tx.
vout[i], dust_relay_rate)) dust_outputs.push_back(i);
81 std::vector<std::vector<unsigned char> > vSolutions;
82 whichType =
Solver(scriptPubKey, vSolutions);
87 unsigned char m = vSolutions.front()[0];
88 unsigned char n = vSolutions.back()[0];
99bool IsStandardTx(
const CTransaction& tx,
const std::optional<unsigned>& max_datacarrier_bytes,
bool permit_bare_multisig,
const CFeeRate& dust_relay_fee, std::string& reason)
101 if (tx.
version > TX_MAX_STANDARD_VERSION || tx.
version < TX_MIN_STANDARD_VERSION) {
110 unsigned int sz = GetTransactionWeight(tx);
111 if (sz > MAX_STANDARD_TX_WEIGHT) {
127 reason =
"scriptsig-size";
131 reason =
"scriptsig-not-pushonly";
136 unsigned int datacarrier_bytes_left = max_datacarrier_bytes.value_or(0);
140 reason =
"scriptpubkey";
146 if (size > datacarrier_bytes_left) {
147 reason =
"datacarrier";
150 datacarrier_bytes_left -= size;
152 reason =
"bare-multisig";
158 if (
GetDust(tx, dust_relay_fee).size() > MAX_DUST_OUTPUTS_PER_TX) {
173 unsigned int sigops{0};
174 for (
const auto& txin: tx.
vin) {
184 sigops += txin.scriptSig.GetSigOpCount(
true);
185 sigops += prev_txo.scriptPubKey.GetSigOpCount(txin.scriptSig);
187 if (sigops > MAX_TX_LEGACY_SIGOPS) {
223 for (
unsigned int i = 0; i < tx.
vin.size(); i++) {
226 std::vector<std::vector<unsigned char> > vSolutions;
235 std::vector<std::vector<unsigned char> > stack;
241 CScript subscript(stack.back().begin(), stack.back().end());
256 for (
unsigned int i = 0; i < tx.
vin.size(); i++)
260 if (tx.
vin[i].scriptWitness.IsNull())
275 std::vector <std::vector<unsigned char> > stack;
283 prevScript =
CScript(stack.back().begin(), stack.back().end());
287 int witnessversion = 0;
288 std::vector<unsigned char> witnessprogram;
295 if (witnessversion == 0 && witnessprogram.size() == WITNESS_V0_SCRIPTHASH_SIZE) {
296 if (tx.
vin[i].scriptWitness.stack.back().size() > MAX_STANDARD_P2WSH_SCRIPT_SIZE)
298 size_t sizeWitnessStack = tx.
vin[i].scriptWitness.stack.size() - 1;
299 if (sizeWitnessStack > MAX_STANDARD_P2WSH_STACK_ITEMS)
301 for (
unsigned int j = 0; j < sizeWitnessStack; j++) {
302 if (tx.
vin[i].scriptWitness.stack[j].size() > MAX_STANDARD_P2WSH_STACK_ITEM_SIZE)
310 if (witnessversion == 1 && witnessprogram.size() == WITNESS_V1_TAPROOT_SIZE && !p2sh) {
312 std::span stack{tx.
vin[i].scriptWitness.stack};
313 if (stack.size() >= 2 && !stack.back().empty() && stack.back()[0] == ANNEX_TAG) {
317 if (stack.size() >= 2) {
321 if (control_block.empty())
return false;
322 if ((control_block[0] & TAPROOT_LEAF_MASK) == TAPROOT_LEAF_TAPSCRIPT) {
324 for (
const auto& item : stack) {
325 if (item.size() > MAX_STANDARD_TAPSCRIPT_STACK_ITEM_SIZE)
return false;
328 }
else if (stack.size() == 1) {
347 std::vector<uint8_t> program;
348 for (
const auto& txin: tx.
vin) {
352 if (prev_spk.IsWitnessProgram(version, program) && !prev_spk.IsPayToAnchor(version, program)) {
359 if (prev_spk.IsPayToScriptHash()) {
361 std::vector <std::vector<uint8_t>> stack;
366 const CScript redeem_script{stack.back().begin(), stack.back().end()};
378 return std::max(weight, sigop_cost * bytes_per_sigop);
383 return (
GetSigOpsAdjustedWeight(nWeight, nSigOpCost, bytes_per_sigop) + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR;
int64_t CAmount
Amount in satoshis (Can be negative).
#define Assert(val)
Identity function.
CCoinsView that adds a memory cache for transactions to another CCoinsView.
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to Coin in the cache, or coinEmpty if not found.
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
CAmount GetFee(int32_t virtual_bytes) const
Return the fee in satoshis for the given vsize in vbytes.
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 IsUnspendable() const
Returns whether the script is guaranteed to fail at execution, regardless of the initial stack.
unsigned int GetSigOpCount(bool fAccurate) const
Pre-version-0.6, Bitcoin always counted CHECKMULTISIGs as 20 sigops.
bool IsPayToAnchor() const
bool IsWitnessProgram(int &version, std::vector< unsigned char > &program) const
The basic transaction that is broadcasted on the network and contained in blocks.
const std::vector< CTxOut > vout
const std::vector< CTxIn > vin
An input of a transaction.
An output of a transaction.
CTxOut out
unspent transaction output
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)
@ BASE
Bare scripts and BIP16 P2SH-wrapped redeemscripts.
bool SpendsNonAnchorWitnessProg(const CTransaction &tx, const CCoinsViewCache &prevouts)
Check whether this transaction spends any witness program but P2A, including not-yet-defined ones.
bool AreInputsStandard(const CTransaction &tx, const CCoinsViewCache &mapInputs)
Check transaction inputs.
CAmount GetDustThreshold(const CTxOut &txout, const CFeeRate &dustRelayFeeIn)
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost, unsigned int bytes_per_sigop)
Compute the virtual transaction size (weight reinterpreted as bytes).
int64_t GetVirtualTransactionInputSize(const CTxIn &txin, int64_t nSigOpCost, unsigned int bytes_per_sigop)
static bool CheckSigopsBIP54(const CTransaction &tx, const CCoinsViewCache &inputs)
Check the total number of non-witness sigops across the whole transaction, as per BIP54.
bool IsWitnessStandard(const CTransaction &tx, const CCoinsViewCache &mapInputs)
Check if the transaction is over standard P2WSH resources limit: 3600bytes witnessScript size,...
bool IsStandard(const CScript &scriptPubKey, TxoutType &whichType)
bool IsStandardTx(const CTransaction &tx, const std::optional< unsigned > &max_datacarrier_bytes, bool permit_bare_multisig, const CFeeRate &dust_relay_fee, std::string &reason)
Check for standard transaction types.
bool IsDust(const CTxOut &txout, const CFeeRate &dustRelayFeeIn)
std::vector< uint32_t > GetDust(const CTransaction &tx, CFeeRate dust_relay_rate)
Get the vout index numbers of all dust outputs.
int64_t GetSigOpsAdjustedWeight(int64_t weight, int64_t sigop_cost, unsigned int bytes_per_sigop)
uint64_t GetSerializeSize(const T &t)
TxoutType Solver(const CScript &scriptPubKey, std::vector< std::vector< unsigned char > > &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
@ WITNESS_UNKNOWN
Only for Witness versions not already defined above.
@ NULL_DATA
unspendable OP_RETURN script that carries data
T & SpanPopBack(std::span< T > &span)
A span is an object that can refer to a contiguous sequence of objects.