Bitcoin Core  24.99.0
P2P Digital Currency
Functions | Variables
policy.h File Reference
#include <consensus/amount.h>
#include <consensus/consensus.h>
#include <primitives/transaction.h>
#include <script/interpreter.h>
#include <script/standard.h>
#include <cstdint>
#include <string>
Include dependency graph for policy.h:

Go to the source code of this file.

Functions

CAmount GetDustThreshold (const CTxOut &txout, const CFeeRate &dustRelayFee)
 
bool IsDust (const CTxOut &txout, const CFeeRate &dustRelayFee)
 
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 for standard transaction types. 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 &tx, int64_t nSigOpCost, unsigned int bytes_per_sigop)
 
static int64_t GetVirtualTransactionSize (const CTransaction &tx)
 
static int64_t GetVirtualTransactionInputSize (const CTxIn &tx)
 

Variables

static constexpr unsigned int DEFAULT_BLOCK_MAX_WEIGHT {MAX_BLOCK_WEIGHT - 4000}
 Default for -blockmaxweight, which controls the range of block weights the mining code will create. More...
 
static constexpr unsigned int DEFAULT_BLOCK_MIN_TX_FEE {1000}
 Default for -blockmintxfee, which sets the minimum feerate for a transaction in blocks created by mining code. More...
 
static constexpr unsigned int MAX_STANDARD_TX_WEIGHT {400000}
 The maximum weight for transactions we're willing to relay/mine. More...
 
static constexpr unsigned int MIN_STANDARD_TX_NONWITNESS_SIZE {82}
 The minimum non-witness size for transactions we're willing to relay/mine (1 segwit input + 1 P2WPKH output = 82 bytes) More...
 
static constexpr unsigned int MAX_P2SH_SIGOPS {15}
 Maximum number of signature check operations in an IsStandard() P2SH script. More...
 
static constexpr unsigned int MAX_STANDARD_TX_SIGOPS_COST {MAX_BLOCK_SIGOPS_COST/5}
 The maximum number of sigops we're willing to relay/mine in a single tx. More...
 
static constexpr unsigned int DEFAULT_INCREMENTAL_RELAY_FEE {1000}
 Default for -incrementalrelayfee, which sets the minimum feerate increase for mempool limiting or replacement. More...
 
static constexpr unsigned int DEFAULT_BYTES_PER_SIGOP {20}
 Default for -bytespersigop. More...
 
static constexpr bool DEFAULT_PERMIT_BAREMULTISIG {true}
 Default for -permitbaremultisig. More...
 
static constexpr unsigned int MAX_STANDARD_P2WSH_STACK_ITEMS {100}
 The maximum number of witness stack items in a standard P2WSH script. More...
 
static constexpr unsigned int MAX_STANDARD_P2WSH_STACK_ITEM_SIZE {80}
 The maximum size in bytes of each witness stack item in a standard P2WSH script. More...
 
static constexpr unsigned int MAX_STANDARD_TAPSCRIPT_STACK_ITEM_SIZE {80}
 The maximum size in bytes of each witness stack item in a standard BIP 342 script (Taproot, leaf version 0xc0) More...
 
static constexpr unsigned int MAX_STANDARD_P2WSH_SCRIPT_SIZE {3600}
 The maximum size in bytes of a standard witnessScript. More...
 
static constexpr unsigned int MAX_STANDARD_SCRIPTSIG_SIZE {1650}
 The maximum size of a standard ScriptSig. More...
 
static constexpr unsigned int DUST_RELAY_TX_FEE {3000}
 Min feerate for defining dust. More...
 
static constexpr unsigned int DEFAULT_MIN_RELAY_TX_FEE {1000}
 Default for -minrelaytxfee, minimum relay fee for transactions. More...
 
static constexpr unsigned int DEFAULT_ANCESTOR_LIMIT {25}
 Default for -limitancestorcount, max number of in-mempool ancestors. More...
 
static constexpr unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT_KVB {101}
 Default for -limitancestorsize, maximum kilobytes of tx + all in-mempool ancestors. More...
 
static constexpr unsigned int DEFAULT_DESCENDANT_LIMIT {25}
 Default for -limitdescendantcount, max number of in-mempool descendants. More...
 
static constexpr unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT_KVB {101}
 Default for -limitdescendantsize, maximum kilobytes of in-mempool descendants. More...
 
static constexpr unsigned int EXTRA_DESCENDANT_TX_SIZE_LIMIT {10000}
 An extra transaction can be added to a package, as long as it only has one ancestor and is no larger than this. More...
 
static constexpr unsigned int STANDARD_SCRIPT_VERIFY_FLAGS
 Standard script verification flags that standard transactions will comply with. More...
 
static constexpr unsigned int STANDARD_NOT_MANDATORY_VERIFY_FLAGS {STANDARD_SCRIPT_VERIFY_FLAGS & ~MANDATORY_SCRIPT_VERIFY_FLAGS}
 For convenience, standard but not mandatory verify flags. More...
 
static constexpr unsigned int STANDARD_LOCKTIME_VERIFY_FLAGS {LOCKTIME_VERIFY_SEQUENCE}
 Used as the flags parameter to sequence and nLocktime checks in non-consensus code. More...
 
static constexpr decltype(CTransaction::nVersionTX_MAX_STANDARD_VERSION {2}
 

Function Documentation

◆ AreInputsStandard()

bool AreInputsStandard ( const CTransaction tx,
const CCoinsViewCache mapInputs 
)

Check for standard transaction types.

Parameters
[in]mapInputsMap of previous transactions that have outputs we're spending
Returns
True if all inputs (scriptSigs) use only standard transaction forms

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 dustRelayFee 
)

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() [1/2]

static int64_t GetVirtualTransactionInputSize ( const CTxIn tx)
inlinestatic

Definition at line 146 of file policy.h.

Here is the call graph for this function:

◆ GetVirtualTransactionInputSize() [2/2]

int64_t GetVirtualTransactionInputSize ( const CTxIn tx,
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/3]

static int64_t GetVirtualTransactionSize ( const CTransaction tx)
inlinestatic

Definition at line 141 of file policy.h.

Here is the call graph for this function:

◆ GetVirtualTransactionSize() [2/3]

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() [3/3]

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 dustRelayFee 
)

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:

Variable Documentation

◆ DEFAULT_ANCESTOR_LIMIT

constexpr unsigned int DEFAULT_ANCESTOR_LIMIT {25}
staticconstexpr

Default for -limitancestorcount, max number of in-mempool ancestors.

Definition at line 59 of file policy.h.

◆ DEFAULT_ANCESTOR_SIZE_LIMIT_KVB

constexpr unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT_KVB {101}
staticconstexpr

Default for -limitancestorsize, maximum kilobytes of tx + all in-mempool ancestors.

Definition at line 61 of file policy.h.

◆ DEFAULT_BLOCK_MAX_WEIGHT

constexpr unsigned int DEFAULT_BLOCK_MAX_WEIGHT {MAX_BLOCK_WEIGHT - 4000}
staticconstexpr

Default for -blockmaxweight, which controls the range of block weights the mining code will create.

Definition at line 23 of file policy.h.

◆ DEFAULT_BLOCK_MIN_TX_FEE

constexpr unsigned int DEFAULT_BLOCK_MIN_TX_FEE {1000}
staticconstexpr

Default for -blockmintxfee, which sets the minimum feerate for a transaction in blocks created by mining code.

Definition at line 25 of file policy.h.

◆ DEFAULT_BYTES_PER_SIGOP

constexpr unsigned int DEFAULT_BYTES_PER_SIGOP {20}
staticconstexpr

Default for -bytespersigop.

Definition at line 37 of file policy.h.

◆ DEFAULT_DESCENDANT_LIMIT

constexpr unsigned int DEFAULT_DESCENDANT_LIMIT {25}
staticconstexpr

Default for -limitdescendantcount, max number of in-mempool descendants.

Definition at line 63 of file policy.h.

◆ DEFAULT_DESCENDANT_SIZE_LIMIT_KVB

constexpr unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT_KVB {101}
staticconstexpr

Default for -limitdescendantsize, maximum kilobytes of in-mempool descendants.

Definition at line 65 of file policy.h.

◆ DEFAULT_INCREMENTAL_RELAY_FEE

constexpr unsigned int DEFAULT_INCREMENTAL_RELAY_FEE {1000}
staticconstexpr

Default for -incrementalrelayfee, which sets the minimum feerate increase for mempool limiting or replacement.

Definition at line 35 of file policy.h.

◆ DEFAULT_MIN_RELAY_TX_FEE

constexpr unsigned int DEFAULT_MIN_RELAY_TX_FEE {1000}
staticconstexpr

Default for -minrelaytxfee, minimum relay fee for transactions.

Definition at line 57 of file policy.h.

◆ DEFAULT_PERMIT_BAREMULTISIG

constexpr bool DEFAULT_PERMIT_BAREMULTISIG {true}
staticconstexpr

Default for -permitbaremultisig.

Definition at line 39 of file policy.h.

◆ DUST_RELAY_TX_FEE

constexpr unsigned int DUST_RELAY_TX_FEE {3000}
staticconstexpr

Min feerate for defining dust.

Changing the dust limit changes which transactions are standard and should be done with care and ideally rarely. It makes sense to only increase the dust limit after prior releases were already not creating outputs below the new threshold

Definition at line 55 of file policy.h.

◆ EXTRA_DESCENDANT_TX_SIZE_LIMIT

constexpr unsigned int EXTRA_DESCENDANT_TX_SIZE_LIMIT {10000}
staticconstexpr

An extra transaction can be added to a package, as long as it only has one ancestor and is no larger than this.

Not really any reason to make this configurable as it doesn't materially change DoS parameters.

Definition at line 71 of file policy.h.

◆ MAX_P2SH_SIGOPS

constexpr unsigned int MAX_P2SH_SIGOPS {15}
staticconstexpr

Maximum number of signature check operations in an IsStandard() P2SH script.

Definition at line 31 of file policy.h.

◆ MAX_STANDARD_P2WSH_SCRIPT_SIZE

constexpr unsigned int MAX_STANDARD_P2WSH_SCRIPT_SIZE {3600}
staticconstexpr

The maximum size in bytes of a standard witnessScript.

Definition at line 47 of file policy.h.

◆ MAX_STANDARD_P2WSH_STACK_ITEM_SIZE

constexpr unsigned int MAX_STANDARD_P2WSH_STACK_ITEM_SIZE {80}
staticconstexpr

The maximum size in bytes of each witness stack item in a standard P2WSH script.

Definition at line 43 of file policy.h.

◆ MAX_STANDARD_P2WSH_STACK_ITEMS

constexpr unsigned int MAX_STANDARD_P2WSH_STACK_ITEMS {100}
staticconstexpr

The maximum number of witness stack items in a standard P2WSH script.

Definition at line 41 of file policy.h.

◆ MAX_STANDARD_SCRIPTSIG_SIZE

constexpr unsigned int MAX_STANDARD_SCRIPTSIG_SIZE {1650}
staticconstexpr

The maximum size of a standard ScriptSig.

Definition at line 49 of file policy.h.

◆ MAX_STANDARD_TAPSCRIPT_STACK_ITEM_SIZE

constexpr unsigned int MAX_STANDARD_TAPSCRIPT_STACK_ITEM_SIZE {80}
staticconstexpr

The maximum size in bytes of each witness stack item in a standard BIP 342 script (Taproot, leaf version 0xc0)

Definition at line 45 of file policy.h.

◆ MAX_STANDARD_TX_SIGOPS_COST

constexpr unsigned int MAX_STANDARD_TX_SIGOPS_COST {MAX_BLOCK_SIGOPS_COST/5}
staticconstexpr

The maximum number of sigops we're willing to relay/mine in a single tx.

Definition at line 33 of file policy.h.

◆ MAX_STANDARD_TX_WEIGHT

constexpr unsigned int MAX_STANDARD_TX_WEIGHT {400000}
staticconstexpr

The maximum weight for transactions we're willing to relay/mine.

Definition at line 27 of file policy.h.

◆ MIN_STANDARD_TX_NONWITNESS_SIZE

constexpr unsigned int MIN_STANDARD_TX_NONWITNESS_SIZE {82}
staticconstexpr

The minimum non-witness size for transactions we're willing to relay/mine (1 segwit input + 1 P2WPKH output = 82 bytes)

Definition at line 29 of file policy.h.

◆ STANDARD_LOCKTIME_VERIFY_FLAGS

constexpr unsigned int STANDARD_LOCKTIME_VERIFY_FLAGS {LOCKTIME_VERIFY_SEQUENCE}
staticconstexpr

Used as the flags parameter to sequence and nLocktime checks in non-consensus code.

Definition at line 102 of file policy.h.

◆ STANDARD_NOT_MANDATORY_VERIFY_FLAGS

constexpr unsigned int STANDARD_NOT_MANDATORY_VERIFY_FLAGS {STANDARD_SCRIPT_VERIFY_FLAGS & ~MANDATORY_SCRIPT_VERIFY_FLAGS}
staticconstexpr

For convenience, standard but not mandatory verify flags.

Definition at line 99 of file policy.h.

◆ STANDARD_SCRIPT_VERIFY_FLAGS

constexpr unsigned int STANDARD_SCRIPT_VERIFY_FLAGS
staticconstexpr
Initial value:
@ SCRIPT_VERIFY_NULLDUMMY
Definition: interpreter.h:62
@ SCRIPT_VERIFY_DISCOURAGE_OP_SUCCESS
Definition: interpreter.h:139
@ SCRIPT_VERIFY_WITNESS
Definition: interpreter.h:106
@ SCRIPT_VERIFY_CONST_SCRIPTCODE
Definition: interpreter.h:128
@ SCRIPT_VERIFY_MINIMALIF
Definition: interpreter.h:116
@ SCRIPT_VERIFY_LOW_S
Definition: interpreter.h:59
@ SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY
Definition: interpreter.h:97
@ SCRIPT_VERIFY_WITNESS_PUBKEYTYPE
Definition: interpreter.h:124
@ SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_TAPROOT_VERSION
Definition: interpreter.h:136
@ SCRIPT_VERIFY_TAPROOT
Definition: interpreter.h:132
@ SCRIPT_VERIFY_STRICTENC
Definition: interpreter.h:52
@ SCRIPT_VERIFY_NULLFAIL
Definition: interpreter.h:120
@ SCRIPT_VERIFY_DERSIG
Definition: interpreter.h:55
@ SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_PUBKEYTYPE
Definition: interpreter.h:142
@ SCRIPT_VERIFY_CLEANSTACK
Definition: interpreter.h:92
@ SCRIPT_VERIFY_MINIMALDATA
Definition: interpreter.h:71
@ SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS
Definition: interpreter.h:83
@ SCRIPT_VERIFY_CHECKSEQUENCEVERIFY
Definition: interpreter.h:102
@ SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM
Definition: interpreter.h:110
static const unsigned int MANDATORY_SCRIPT_VERIFY_FLAGS
Mandatory script verification flags that all new blocks must comply with for them to be valid.
Definition: standard.h:49

Standard script verification flags that standard transactions will comply with.

However scripts violating these flags may still be present in valid blocks and we must accept those blocks.

Definition at line 77 of file policy.h.

◆ TX_MAX_STANDARD_VERSION

constexpr decltype(CTransaction::nVersion) TX_MAX_STANDARD_VERSION {2}
staticconstexpr

Definition at line 114 of file policy.h.