Bitcoin Core  27.99.0
P2P Digital Currency
Functions
policy.cpp File Reference
#include <policy/policy.h>
#include <coins.h>
#include <consensus/amount.h>
#include <consensus/consensus.h>
#include <consensus/validation.h>
#include <policy/feerate.h>
#include <primitives/transaction.h>
#include <script/interpreter.h>
#include <script/script.h>
#include <script/solver.h>
#include <serialize.h>
#include <span.h>
#include <algorithm>
#include <cstddef>
#include <vector>
Include dependency graph for policy.cpp:

Go to the source code of this file.

Functions

CAmount GetDustThreshold (const CTxOut &txout, const CFeeRate &dustRelayFeeIn)
 
bool IsDust (const CTxOut &txout, const CFeeRate &dustRelayFeeIn)
 
bool IsStandard (const CScript &scriptPubKey, const std::optional< unsigned > &max_datacarrier_bytes, 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. More...
 
bool AreInputsStandard (const CTransaction &tx, const CCoinsViewCache &mapInputs)
 Check transaction inputs to mitigate two potential denial-of-service attacks: More...
 
bool IsWitnessStandard (const CTransaction &tx, const CCoinsViewCache &mapInputs)
 Check if the transaction is over standard P2WSH resources limit: 3600bytes witnessScript size, 80bytes per witness stack element, 100 witness stack elements These limits are adequate for multisignatures up to n-of-100 using OP_CHECKSIG, OP_ADD, and OP_EQUAL. More...
 
int64_t GetVirtualTransactionSize (int64_t nWeight, int64_t nSigOpCost, unsigned int bytes_per_sigop)
 Compute the virtual transaction size (weight reinterpreted as bytes). More...
 
int64_t GetVirtualTransactionSize (const CTransaction &tx, int64_t nSigOpCost, unsigned int bytes_per_sigop)
 
int64_t GetVirtualTransactionInputSize (const CTxIn &txin, int64_t nSigOpCost, unsigned int bytes_per_sigop)
 

Function Documentation

◆ AreInputsStandard()

bool AreInputsStandard ( const CTransaction tx,
const CCoinsViewCache mapInputs 
)

Check transaction inputs to mitigate two potential denial-of-service attacks:

Check for standard transaction types.

  1. scriptSigs with extra data stuffed into them, not consumed by scriptPubKey (or P2SH script)
  2. P2SH scripts with a crazy number of expensive CHECKSIG/CHECKMULTISIG operations

Why bother? To avoid denial-of-service attacks; an attacker can submit a standard HASH... OP_EQUAL transaction, which will get accepted into blocks. The redemption script can be anything; an attacker could use a very expensive-to-check-upon-redemption script like: DUP CHECKSIG DROP ... repeated 100 times... OP_1

Note that only the non-witness portion of the transaction is checked here.

Definition at line 177 of file policy.cpp.

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

◆ GetDustThreshold()

CAmount GetDustThreshold ( const CTxOut txout,
const CFeeRate dustRelayFeeIn 
)

Definition at line 26 of file policy.cpp.

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

◆ GetVirtualTransactionInputSize()

int64_t GetVirtualTransactionInputSize ( const CTxIn txin,
int64_t  nSigOpCost,
unsigned int  bytes_per_sigop 
)

Definition at line 305 of file policy.cpp.

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

◆ GetVirtualTransactionSize() [1/2]

int64_t GetVirtualTransactionSize ( const CTransaction tx,
int64_t  nSigOpCost,
unsigned int  bytes_per_sigop 
)

Definition at line 300 of file policy.cpp.

Here is the call graph for this function:

◆ GetVirtualTransactionSize() [2/2]

int64_t GetVirtualTransactionSize ( int64_t  nWeight,
int64_t  nSigOpCost,
unsigned int  bytes_per_sigop 
)

Compute the virtual transaction size (weight reinterpreted as bytes).

Definition at line 295 of file policy.cpp.

Here is the caller graph for this function:

◆ IsDust()

bool IsDust ( const CTxOut txout,
const CFeeRate dustRelayFeeIn 
)

Definition at line 65 of file policy.cpp.

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

◆ IsStandard()

bool IsStandard ( const CScript scriptPubKey,
const std::optional< unsigned > &  max_datacarrier_bytes,
TxoutType whichType 
)

Definition at line 70 of file policy.cpp.

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

◆ IsStandardTx()

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.

Returns
True if all outputs (scriptPubKeys) use only standard transaction forms

Definition at line 94 of file policy.cpp.

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

◆ IsWitnessStandard()

bool IsWitnessStandard ( const CTransaction tx,
const CCoinsViewCache mapInputs 
)

Check if the transaction is over standard P2WSH resources limit: 3600bytes witnessScript size, 80bytes per witness stack element, 100 witness stack elements These limits are adequate for multisignatures up to n-of-100 using OP_CHECKSIG, OP_ADD, and OP_EQUAL.

Also enforce a maximum stack item size limit and no annexes for tapscript spends.

Definition at line 211 of file policy.cpp.

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