46 int witnessversion = 0;
47 std::vector<unsigned char> witnessprogram;
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];
95 if (!max_datacarrier_bytes || scriptPubKey.
size() > *max_datacarrier_bytes) {
103bool IsStandardTx(
const CTransaction& tx,
const std::optional<unsigned>& max_datacarrier_bytes,
bool permit_bare_multisig,
const CFeeRate& dust_relay_fee, std::string& reason)
131 reason =
"scriptsig-size";
135 reason =
"scriptsig-not-pushonly";
140 unsigned int nDataOut = 0;
144 reason =
"scriptpubkey";
151 reason =
"bare-multisig";
164 reason =
"multi-op-return";
195 for (
unsigned int i = 0; i < tx.
vin.size(); i++) {
198 std::vector<std::vector<unsigned char> > vSolutions;
207 std::vector<std::vector<unsigned char> > stack;
213 CScript subscript(stack.back().begin(), stack.back().end());
228 for (
unsigned int i = 0; i < tx.
vin.size(); i++)
232 if (tx.
vin[i].scriptWitness.IsNull())
247 std::vector <std::vector<unsigned char> > stack;
255 prevScript =
CScript(stack.back().begin(), stack.back().end());
259 int witnessversion = 0;
260 std::vector<unsigned char> witnessprogram;
270 size_t sizeWitnessStack = tx.
vin[i].scriptWitness.stack.size() - 1;
273 for (
unsigned int j = 0; j < sizeWitnessStack; j++) {
284 Span stack{tx.
vin[i].scriptWitness.stack};
285 if (stack.size() >= 2 && !stack.back().empty() && stack.back()[0] ==
ANNEX_TAG) {
289 if (stack.size() >= 2) {
293 if (control_block.empty())
return false;
296 for (
const auto& item : stack) {
300 }
else if (stack.size() == 1) {
int64_t CAmount
Amount in satoshis (Can be negative)
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 kilovirtualbyte: CAmount / kvB.
CAmount GetFee(uint32_t num_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
A Span is an object that can refer to a contiguous sequence of objects.
static int64_t GetTransactionInputWeight(const CTxIn &txin)
static int32_t GetTransactionWeight(const CTransaction &tx)
static const int WITNESS_SCALE_FACTOR
bool EvalScript(std::vector< std::vector< unsigned char > > &stack, const CScript &script, unsigned int flags, const BaseSignatureChecker &checker, SigVersion sigversion, ScriptExecutionData &execdata, ScriptError *serror)
@ BASE
Bare scripts and BIP16 P2SH-wrapped redeemscripts.
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.
static constexpr size_t WITNESS_V1_TAPROOT_SIZE
bool IsStandard(const CScript &scriptPubKey, const std::optional< unsigned > &max_datacarrier_bytes, TxoutType &whichType)
bool AreInputsStandard(const CTransaction &tx, const CCoinsViewCache &mapInputs)
Check transaction inputs to mitigate two potential denial-of-service attacks:
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)
bool IsWitnessStandard(const CTransaction &tx, const CCoinsViewCache &mapInputs)
Check if the transaction is over standard P2WSH resources limit: 3600bytes witnessScript size,...
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.
static constexpr decltype(CTransaction::version) TX_MAX_STANDARD_VERSION
static constexpr unsigned int MAX_STANDARD_P2WSH_STACK_ITEMS
The maximum number of witness stack items in a standard P2WSH script.
static constexpr unsigned int MAX_STANDARD_TAPSCRIPT_STACK_ITEM_SIZE
The maximum size in bytes of each witness stack item in a standard BIP 342 script (Taproot,...
static constexpr unsigned int MAX_DUST_OUTPUTS_PER_TX
Maximum number of ephemeral dust outputs allowed.
static constexpr unsigned int MAX_STANDARD_P2WSH_STACK_ITEM_SIZE
The maximum size in bytes of each witness stack item in a standard P2WSH script.
static constexpr int32_t MAX_STANDARD_TX_WEIGHT
The maximum weight for transactions we're willing to relay/mine.
static constexpr unsigned int MAX_P2SH_SIGOPS
Maximum number of signature check operations in an IsStandard() P2SH script.
static constexpr unsigned int MAX_STANDARD_P2WSH_SCRIPT_SIZE
The maximum size in bytes of a standard witnessScript.
static constexpr unsigned int MAX_STANDARD_SCRIPTSIG_SIZE
The maximum size of a standard ScriptSig.
static constexpr unsigned int ANNEX_TAG
size_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(Span< T > &span)
Pop the last element off a span, and return a reference to that element.