Bitcoin Core  27.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/solver.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 int32_t 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 {65}
 The minimum non-witness size for transactions we're willing to relay/mine: one larger than 64
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 const bool DEFAULT_ACCEPT_DATACARRIER = true
 Default for -datacarrier. More...
 
static const unsigned int MAX_OP_RETURN_RELAY = 83
 Default setting for -datacarriersize. 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 MANDATORY_SCRIPT_VERIFY_FLAGS
 Mandatory script verification flags that all new transactions must comply with for them to be valid. 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 166 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 161 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_ACCEPT_DATACARRIER

const bool DEFAULT_ACCEPT_DATACARRIER = true
static

Default for -datacarrier.

Definition at line 67 of file policy.h.

◆ 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 78 of file policy.h.

◆ MANDATORY_SCRIPT_VERIFY_FLAGS

constexpr unsigned int MANDATORY_SCRIPT_VERIFY_FLAGS
staticconstexpr
Initial value:

Mandatory script verification flags that all new transactions must comply with for them to be valid.

Failing one of these tests may trigger a DoS ban; see CheckInputScripts() for details.

Note that this does not affect consensus validity; see GetBlockScriptFlags() for that.

Definition at line 89 of file policy.h.

◆ MAX_OP_RETURN_RELAY

const unsigned int MAX_OP_RETURN_RELAY = 83
static

Default setting for -datacarriersize.

80 bytes of data, +1 for OP_RETURN, +2 for the pushdata opcodes.

Definition at line 72 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 int32_t 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 {65}
staticconstexpr

The minimum non-witness size for transactions we're willing to relay/mine: one larger than 64

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 122 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 119 of file policy.h.

◆ STANDARD_SCRIPT_VERIFY_FLAGS

constexpr unsigned int STANDARD_SCRIPT_VERIFY_FLAGS
staticconstexpr
Initial value:
@ SCRIPT_VERIFY_DISCOURAGE_OP_SUCCESS
Definition: interpreter.h:141
@ SCRIPT_VERIFY_CONST_SCRIPTCODE
Definition: interpreter.h:130
@ SCRIPT_VERIFY_MINIMALIF
Definition: interpreter.h:118
@ SCRIPT_VERIFY_LOW_S
Definition: interpreter.h:61
@ SCRIPT_VERIFY_WITNESS_PUBKEYTYPE
Definition: interpreter.h:126
@ SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_TAPROOT_VERSION
Definition: interpreter.h:138
@ SCRIPT_VERIFY_STRICTENC
Definition: interpreter.h:54
@ SCRIPT_VERIFY_NULLFAIL
Definition: interpreter.h:122
@ SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_PUBKEYTYPE
Definition: interpreter.h:144
@ SCRIPT_VERIFY_CLEANSTACK
Definition: interpreter.h:94
@ SCRIPT_VERIFY_MINIMALDATA
Definition: interpreter.h:73
@ SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS
Definition: interpreter.h:85
@ SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM
Definition: interpreter.h:112
static constexpr unsigned int MANDATORY_SCRIPT_VERIFY_FLAGS
Mandatory script verification flags that all new transactions must comply with for them to be valid.
Definition: policy.h:89

Standard script verification flags that standard transactions will comply with.

However we do not ban/disconnect nodes that forward txs violating the additional (non-mandatory) rules here, to improve forwards and backwards compatibility.

Definition at line 103 of file policy.h.

◆ TX_MAX_STANDARD_VERSION

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

Definition at line 134 of file policy.h.