Bitcoin
Functions | Variables
policy.h File Reference
#include <consensus/consensus.h>
#include <policy/feerate.h>
#include <script/interpreter.h>
#include <script/standard.h>
#include <string>

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, txnouttype &whichType)
 
bool IsStandardTx (const CTransaction &tx, bool permit_bare_multisig, const CFeeRate &dust_relay_fee, std::string &reason)
 
bool AreInputsStandard (const CTransaction &tx, const CCoinsViewCache &mapInputs)
 
bool IsWitnessStandard (const CTransaction &tx, const CCoinsViewCache &mapInputs)
 
int64_t GetVirtualTransactionSize (int64_t nWeight, int64_t nSigOpCost, unsigned int bytes_per_sigop)
 
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 const unsigned int DEFAULT_BLOCK_MAX_WEIGHT = MAX_BLOCK_WEIGHT - 4000
 
static const unsigned int DEFAULT_BLOCK_MIN_TX_FEE = 1000
 
static const unsigned int MAX_STANDARD_TX_WEIGHT = 400000
 
static const unsigned int MIN_STANDARD_TX_NONWITNESS_SIZE = 82
 
static const unsigned int MAX_P2SH_SIGOPS = 15
 
static const unsigned int MAX_STANDARD_TX_SIGOPS_COST = MAX_BLOCK_SIGOPS_COST/5
 
static const unsigned int DEFAULT_MAX_MEMPOOL_SIZE = 300
 
static const unsigned int DEFAULT_INCREMENTAL_RELAY_FEE = 1000
 
static const unsigned int DEFAULT_BYTES_PER_SIGOP = 20
 
static const bool DEFAULT_PERMIT_BAREMULTISIG = true
 
static const unsigned int MAX_STANDARD_P2WSH_STACK_ITEMS = 100
 
static const unsigned int MAX_STANDARD_P2WSH_STACK_ITEM_SIZE = 80
 
static const unsigned int MAX_STANDARD_P2WSH_SCRIPT_SIZE = 3600
 
static const unsigned int DUST_RELAY_TX_FEE = 3000
 
static constexpr unsigned int STANDARD_SCRIPT_VERIFY_FLAGS
 
static constexpr unsigned int STANDARD_NOT_MANDATORY_VERIFY_FLAGS = STANDARD_SCRIPT_VERIFY_FLAGS & ~MANDATORY_SCRIPT_VERIFY_FLAGS
 
static constexpr unsigned int STANDARD_LOCKTIME_VERIFY_FLAGS
 

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 transaction inputs to mitigate two potential denial-of-service attacks:

  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

◆ GetDustThreshold()

CAmount GetDustThreshold ( const CTxOut txout,
const CFeeRate dustRelayFee 
)

◆ GetVirtualTransactionInputSize() [1/2]

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

◆ GetVirtualTransactionInputSize() [2/2]

static int64_t GetVirtualTransactionInputSize ( const CTxIn tx)
inlinestatic

◆ GetVirtualTransactionSize() [1/3]

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

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

◆ GetVirtualTransactionSize() [2/3]

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

◆ GetVirtualTransactionSize() [3/3]

static int64_t GetVirtualTransactionSize ( const CTransaction tx)
inlinestatic

◆ IsDust()

bool IsDust ( const CTxOut txout,
const CFeeRate dustRelayFee 
)

◆ IsStandard()

bool IsStandard ( const CScript scriptPubKey,
txnouttype whichType 
)

◆ IsStandardTx()

bool IsStandardTx ( const CTransaction tx,
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

◆ 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 multi-signature up to n-of-100 using OP_CHECKSIG, OP_ADD, and OP_EQUAL,

Variable Documentation

◆ DEFAULT_BLOCK_MAX_WEIGHT

const unsigned int DEFAULT_BLOCK_MAX_WEIGHT = MAX_BLOCK_WEIGHT - 4000
static

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

◆ DEFAULT_BLOCK_MIN_TX_FEE

const unsigned int DEFAULT_BLOCK_MIN_TX_FEE = 1000
static

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

◆ DEFAULT_BYTES_PER_SIGOP

const unsigned int DEFAULT_BYTES_PER_SIGOP = 20
static

Default for -bytespersigop

◆ DEFAULT_INCREMENTAL_RELAY_FEE

const unsigned int DEFAULT_INCREMENTAL_RELAY_FEE = 1000
static

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

◆ DEFAULT_MAX_MEMPOOL_SIZE

const unsigned int DEFAULT_MAX_MEMPOOL_SIZE = 300
static

Default for -maxmempool, maximum megabytes of mempool memory usage

◆ DEFAULT_PERMIT_BAREMULTISIG

const bool DEFAULT_PERMIT_BAREMULTISIG = true
static

Default for -permitbaremultisig

◆ DUST_RELAY_TX_FEE

const unsigned int DUST_RELAY_TX_FEE = 3000
static

Min feerate for defining dust. Historically this has been based on the minRelayTxFee, however 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

◆ MAX_P2SH_SIGOPS

const unsigned int MAX_P2SH_SIGOPS = 15
static

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

◆ MAX_STANDARD_P2WSH_SCRIPT_SIZE

const unsigned int MAX_STANDARD_P2WSH_SCRIPT_SIZE = 3600
static

The maximum size of a standard witnessScript

◆ MAX_STANDARD_P2WSH_STACK_ITEM_SIZE

const unsigned int MAX_STANDARD_P2WSH_STACK_ITEM_SIZE = 80
static

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

◆ MAX_STANDARD_P2WSH_STACK_ITEMS

const unsigned int MAX_STANDARD_P2WSH_STACK_ITEMS = 100
static

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

◆ MAX_STANDARD_TX_SIGOPS_COST

const unsigned int MAX_STANDARD_TX_SIGOPS_COST = MAX_BLOCK_SIGOPS_COST/5
static

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

◆ MAX_STANDARD_TX_WEIGHT

const unsigned int MAX_STANDARD_TX_WEIGHT = 400000
static

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

◆ MIN_STANDARD_TX_NONWITNESS_SIZE

const unsigned int MIN_STANDARD_TX_NONWITNESS_SIZE = 82
static

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

◆ STANDARD_LOCKTIME_VERIFY_FLAGS

constexpr unsigned int STANDARD_LOCKTIME_VERIFY_FLAGS
static
Initial value:
static constexpr unsigned int LOCKTIME_VERIFY_SEQUENCE
Definition: consensus.h:28
static constexpr unsigned int LOCKTIME_MEDIAN_TIME_PAST
Definition: consensus.h:30

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

◆ STANDARD_NOT_MANDATORY_VERIFY_FLAGS

constexpr unsigned int STANDARD_NOT_MANDATORY_VERIFY_FLAGS = STANDARD_SCRIPT_VERIFY_FLAGS & ~MANDATORY_SCRIPT_VERIFY_FLAGS
static

For convenience, standard but not mandatory verify flags.

◆ STANDARD_SCRIPT_VERIFY_FLAGS

constexpr unsigned int STANDARD_SCRIPT_VERIFY_FLAGS
static
Initial value:

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.