Bitcoin Core 32.99.0
P2P Digital Currency
Classes | Macros | Functions
util.h File Reference
#include <addresstype.h>
#include <arith_uint256.h>
#include <coins.h>
#include <compat/compat.h>
#include <consensus/amount.h>
#include <consensus/consensus.h>
#include <key.h>
#include <merkleblock.h>
#include <pow.h>
#include <primitives/transaction.h>
#include <script/script.h>
#include <serialize.h>
#include <streams.h>
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <uint256.h>
#include <validation.h>
#include <algorithm>
#include <array>
#include <cstdint>
#include <cstdio>
#include <optional>
#include <string>
#include <vector>
Include dependency graph for util.h:

Go to the source code of this file.

Classes

class  FuzzedFileProvider
 

Macros

#define WRITE_TO_STREAM_CASE(type, consume)
 
#define READ_FROM_STREAM_CASE(type)
 

Functions

template<typename... Callables>
size_t CallOneOf (FuzzedDataProvider &fuzzed_data_provider, Callables... callables)
 
template<typename Collection >
auto PickIterator (FuzzedDataProvider &fuzzed_data_provider, Collection &col)
 
template<typename Collection >
auto & PickValue (FuzzedDataProvider &fuzzed_data_provider, Collection &col)
 
template<typename B = uint8_t>
std::vector< B > ConsumeRandomLengthByteVector (FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt) noexcept
 
DataStream ConsumeDataStream (FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt) noexcept
 
std::vector< std::string > ConsumeRandomLengthStringVector (FuzzedDataProvider &fuzzed_data_provider, const size_t max_vector_size=16, const size_t max_string_length=16) noexcept
 
template<typename T >
std::vector< T > ConsumeRandomLengthIntegralVector (FuzzedDataProvider &fuzzed_data_provider, const size_t max_vector_size=16) noexcept
 
template<typename P >
P ConsumeDeserializationParams (FuzzedDataProvider &fuzzed_data_provider) noexcept
 
template<typename T , typename P >
std::optional< T > ConsumeDeserializable (FuzzedDataProvider &fuzzed_data_provider, const P &params, const std::optional< size_t > &max_length=std::nullopt) noexcept
 
template<typename T >
std::optional< T > ConsumeDeserializable (FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt) noexcept
 
template<typename T >
std::optional< T > ConsumeDeserializableConstructor (FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt) noexcept
 
template<typename WeakEnumType , size_t size>
WeakEnumType ConsumeWeakEnum (FuzzedDataProvider &fuzzed_data_provider, const WeakEnumType(&all_types)[size]) noexcept
 
opcodetype ConsumeOpcodeType (FuzzedDataProvider &fuzzed_data_provider) noexcept
 
CAmount ConsumeMoney (FuzzedDataProvider &fuzzed_data_provider, const std::optional< CAmount > &max=std::nullopt) noexcept
 
NodeSeconds ConsumeTime (FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min=std::nullopt, const std::optional< int64_t > &max=std::nullopt) noexcept
 
template<class Dur >
Dur ConsumeDuration (FuzzedDataProvider &fuzzed_data_provider, std::common_type_t< Dur > min, std::common_type_t< Dur > max) noexcept
 
CMutableTransaction ConsumeTransaction (FuzzedDataProvider &fuzzed_data_provider, const std::optional< std::vector< Txid > > &prevout_txids, int max_num_in=10, int max_num_out=10) noexcept
 
CScriptWitness ConsumeScriptWitness (FuzzedDataProvider &fuzzed_data_provider, size_t max_stack_elem_size=32) noexcept
 
CScript ConsumeScript (FuzzedDataProvider &fuzzed_data_provider, bool maybe_p2wsh=false) noexcept
 
uint32_t ConsumeSequence (FuzzedDataProvider &fuzzed_data_provider) noexcept
 
CScriptNum ConsumeScriptNum (FuzzedDataProvider &fuzzed_data_provider) noexcept
 
uint160 ConsumeUInt160 (FuzzedDataProvider &fuzzed_data_provider) noexcept
 
uint256 ConsumeUInt256 (FuzzedDataProvider &fuzzed_data_provider) noexcept
 
arith_uint256 ConsumeArithUInt256 (FuzzedDataProvider &fuzzed_data_provider) noexcept
 
arith_uint256 ConsumeArithUInt256InRange (FuzzedDataProvider &fuzzed_data_provider, const arith_uint256 &min, const arith_uint256 &max) noexcept
 
std::map< COutPoint, Coin > ConsumeCoins (FuzzedDataProvider &fuzzed_data_provider) noexcept
 
CTxDestination ConsumeTxDestination (FuzzedDataProvider &fuzzed_data_provider) noexcept
 
CKey ConsumePrivateKey (FuzzedDataProvider &fuzzed_data_provider, std::optional< bool > compressed=std::nullopt) noexcept
 
template<typename T >
bool MultiplicationOverflow (const T i, const T j) noexcept
 
bool ContainsSpentInput (const CTransaction &tx, const CCoinsViewCache &inputs) noexcept
 
template<typename T , size_t size>
void SetFuzzedErrNo (FuzzedDataProvider &fuzzed_data_provider, const std::array< T, size > &errnos)
 Sets errno to a value selected from the given std::array errnos. More...
 
void SetFuzzedErrNo (FuzzedDataProvider &fuzzed_data_provider) noexcept
 
template<typename B = uint8_t>
std::vector< B > ConsumeFixedLengthByteVector (FuzzedDataProvider &fuzzed_data_provider, const size_t length) noexcept
 Returns a byte vector of specified size regardless of the number of remaining bytes available from the fuzzer. More...
 
template<typename Stream >
void WriteToStream (FuzzedDataProvider &fuzzed_data_provider, Stream &stream) noexcept
 
template<typename Stream >
void ReadFromStream (FuzzedDataProvider &fuzzed_data_provider, Stream &stream) noexcept
 
void FinalizeHeader (CBlockHeader &header, const ChainstateManager &chainman)
 

Macro Definition Documentation

◆ READ_FROM_STREAM_CASE

#define READ_FROM_STREAM_CASE (   type)
Value:
[&] { \
type o; \
stream >> o; \
}

Definition at line 338 of file util.h.

◆ WRITE_TO_STREAM_CASE

#define WRITE_TO_STREAM_CASE (   type,
  consume 
)
Value:
[&] { \
type o = consume; \
stream << o; \
}

Definition at line 309 of file util.h.

Function Documentation

◆ CallOneOf()

template<typename... Callables>
size_t CallOneOf ( FuzzedDataProvider &  fuzzed_data_provider,
Callables...  callables 
)

Definition at line 37 of file util.h.

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

◆ ConsumeArithUInt256()

arith_uint256 ConsumeArithUInt256 ( FuzzedDataProvider &  fuzzed_data_provider)
inlinenoexcept

Definition at line 204 of file util.h.

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

◆ ConsumeArithUInt256InRange()

arith_uint256 ConsumeArithUInt256InRange ( FuzzedDataProvider &  fuzzed_data_provider,
const arith_uint256 &  min,
const arith_uint256 &  max 
)
inlinenoexcept

Definition at line 209 of file util.h.

Here is the call graph for this function:

◆ ConsumeCoins()

std::map< COutPoint, Coin > ConsumeCoins ( FuzzedDataProvider &  fuzzed_data_provider)
noexcept

Definition at line 166 of file util.cpp.

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

◆ ConsumeDataStream()

DataStream ConsumeDataStream ( FuzzedDataProvider &  fuzzed_data_provider,
const std::optional< size_t > &  max_length = std::nullopt 
)
inlinenoexcept

Definition at line 74 of file util.h.

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

◆ ConsumeDeserializable() [1/2]

template<typename T , typename P >
std::optional< T > ConsumeDeserializable ( FuzzedDataProvider &  fuzzed_data_provider,
const P &  params,
const std::optional< size_t > &  max_length = std::nullopt 
)
noexcept

Definition at line 106 of file util.h.

Here is the call graph for this function:

◆ ConsumeDeserializable() [2/2]

template<typename T >
std::optional< T > ConsumeDeserializable ( FuzzedDataProvider &  fuzzed_data_provider,
const std::optional< size_t > &  max_length = std::nullopt 
)
inlinenoexcept

Definition at line 120 of file util.h.

Here is the call graph for this function:

◆ ConsumeDeserializableConstructor()

template<typename T >
std::optional< T > ConsumeDeserializableConstructor ( FuzzedDataProvider &  fuzzed_data_provider,
const std::optional< size_t > &  max_length = std::nullopt 
)
inlinenoexcept

Definition at line 134 of file util.h.

Here is the call graph for this function:

◆ ConsumeDeserializationParams()

template<typename P >
template CAddress::SerParams ConsumeDeserializationParams ( FuzzedDataProvider &  fuzzed_data_provider)
noexcept

Definition at line 94 of file net.cpp.

Here is the call graph for this function:

◆ ConsumeDuration()

template<class Dur >
Dur ConsumeDuration ( FuzzedDataProvider &  fuzzed_data_provider,
std::common_type_t< Dur >  min,
std::common_type_t< Dur >  max 
)
noexcept

Definition at line 168 of file util.h.

Here is the call graph for this function:

◆ ConsumeFixedLengthByteVector()

template<typename B = uint8_t>
std::vector< B > ConsumeFixedLengthByteVector ( FuzzedDataProvider &  fuzzed_data_provider,
const size_t  length 
)
inlinenoexcept

Returns a byte vector of specified size regardless of the number of remaining bytes available from the fuzzer.

Pads with zero value bytes if needed to achieve the specified size.

Definition at line 280 of file util.h.

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

◆ ConsumeMoney()

CAmount ConsumeMoney ( FuzzedDataProvider &  fuzzed_data_provider,
const std::optional< CAmount > &  max = std::nullopt 
)
noexcept

Definition at line 29 of file util.cpp.

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

◆ ConsumeOpcodeType()

opcodetype ConsumeOpcodeType ( FuzzedDataProvider &  fuzzed_data_provider)
inlinenoexcept

Definition at line 154 of file util.h.

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

◆ ConsumePrivateKey()

CKey ConsumePrivateKey ( FuzzedDataProvider &  fuzzed_data_provider,
std::optional< bool >  compressed = std::nullopt 
)
noexcept

Definition at line 230 of file util.cpp.

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

◆ ConsumeRandomLengthByteVector()

template<typename B = uint8_t>
std::vector< B > ConsumeRandomLengthByteVector ( FuzzedDataProvider &  fuzzed_data_provider,
const std::optional< size_t > &  max_length = std::nullopt 
)
inlinenoexcept

Definition at line 63 of file util.h.

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

◆ ConsumeRandomLengthIntegralVector()

template<typename T >
std::vector< T > ConsumeRandomLengthIntegralVector ( FuzzedDataProvider &  fuzzed_data_provider,
const size_t  max_vector_size = 16 
)
inlinenoexcept

Definition at line 91 of file util.h.

Here is the call graph for this function:

◆ ConsumeRandomLengthStringVector()

std::vector< std::string > ConsumeRandomLengthStringVector ( FuzzedDataProvider &  fuzzed_data_provider,
const size_t  max_vector_size = 16,
const size_t  max_string_length = 16 
)
inlinenoexcept

Definition at line 79 of file util.h.

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

◆ ConsumeScript()

CScript ConsumeScript ( FuzzedDataProvider &  fuzzed_data_provider,
bool  maybe_p2wsh = false 
)
noexcept

Definition at line 93 of file util.cpp.

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

◆ ConsumeScriptNum()

CScriptNum ConsumeScriptNum ( FuzzedDataProvider &  fuzzed_data_provider)
inlinenoexcept

Definition at line 181 of file util.h.

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

◆ ConsumeScriptWitness()

CScriptWitness ConsumeScriptWitness ( FuzzedDataProvider &  fuzzed_data_provider,
size_t  max_stack_elem_size = 32 
)
noexcept

Definition at line 83 of file util.cpp.

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

◆ ConsumeSequence()

uint32_t ConsumeSequence ( FuzzedDataProvider &  fuzzed_data_provider)
noexcept

Definition at line 155 of file util.cpp.

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

◆ ConsumeTime()

NodeSeconds ConsumeTime ( FuzzedDataProvider &  fuzzed_data_provider,
const std::optional< int64_t > &  min = std::nullopt,
const std::optional< int64_t > &  max = std::nullopt 
)
noexcept

Definition at line 34 of file util.cpp.

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

◆ ConsumeTransaction()

CMutableTransaction ConsumeTransaction ( FuzzedDataProvider &  fuzzed_data_provider,
const std::optional< std::vector< Txid > > &  prevout_txids,
int  max_num_in = 10,
int  max_num_out = 10 
)
noexcept

Definition at line 42 of file util.cpp.

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

◆ ConsumeTxDestination()

CTxDestination ConsumeTxDestination ( FuzzedDataProvider &  fuzzed_data_provider)
noexcept

Definition at line 184 of file util.cpp.

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

◆ ConsumeUInt160()

uint160 ConsumeUInt160 ( FuzzedDataProvider &  fuzzed_data_provider)
inlinenoexcept

Definition at line 186 of file util.h.

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

◆ ConsumeUInt256()

uint256 ConsumeUInt256 ( FuzzedDataProvider &  fuzzed_data_provider)
inlinenoexcept

Definition at line 195 of file util.h.

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

◆ ConsumeWeakEnum()

template<typename WeakEnumType , size_t size>
WeakEnumType ConsumeWeakEnum ( FuzzedDataProvider &  fuzzed_data_provider,
const WeakEnumType(&)  all_types[size] 
)
noexcept

Definition at line 147 of file util.h.

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

◆ ContainsSpentInput()

bool ContainsSpentInput ( const CTransaction &  tx,
const CCoinsViewCache &  inputs 
)
noexcept

Definition at line 240 of file util.cpp.

Here is the call graph for this function:

◆ FinalizeHeader()

void FinalizeHeader ( CBlockHeader &  header,
const ChainstateManager &  chainman 
)
inline

Definition at line 367 of file util.h.

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

◆ MultiplicationOverflow()

template<typename T >
bool MultiplicationOverflow ( const T  i,
const T  j 
)
noexcept

Definition at line 232 of file util.h.

Here is the caller graph for this function:

◆ PickIterator()

template<typename Collection >
auto PickIterator ( FuzzedDataProvider &  fuzzed_data_provider,
Collection &  col 
)

Definition at line 49 of file util.h.

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

◆ PickValue()

template<typename Collection >
auto & PickValue ( FuzzedDataProvider &  fuzzed_data_provider,
Collection &  col 
)

Definition at line 57 of file util.h.

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

◆ ReadFromStream()

template<typename Stream >
void ReadFromStream ( FuzzedDataProvider &  fuzzed_data_provider,
Stream &  stream 
)
noexcept

Definition at line 344 of file util.h.

Here is the call graph for this function:

◆ SetFuzzedErrNo() [1/2]

void SetFuzzedErrNo ( FuzzedDataProvider &  fuzzed_data_provider)
inlinenoexcept

Definition at line 270 of file util.h.

Here is the call graph for this function:

◆ SetFuzzedErrNo() [2/2]

template<typename T , size_t size>
void SetFuzzedErrNo ( FuzzedDataProvider &  fuzzed_data_provider,
const std::array< T, size > &  errnos 
)

Sets errno to a value selected from the given std::array errnos.

Definition at line 260 of file util.h.

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

◆ WriteToStream()

template<typename Stream >
void WriteToStream ( FuzzedDataProvider &  fuzzed_data_provider,
Stream &  stream 
)
noexcept

Definition at line 315 of file util.h.

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