Bitcoin Core  22.99.0
P2P Digital Currency
Classes | Macros | Functions
util.h File Reference
#include <amount.h>
#include <arith_uint256.h>
#include <attributes.h>
#include <chainparamsbase.h>
#include <coins.h>
#include <compat.h>
#include <consensus/consensus.h>
#include <merkleblock.h>
#include <net.h>
#include <netaddress.h>
#include <netbase.h>
#include <primitives/transaction.h>
#include <script/script.h>
#include <script/standard.h>
#include <serialize.h>
#include <streams.h>
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/util/net.h>
#include <txmempool.h>
#include <uint256.h>
#include <version.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
 
class  FuzzedAutoFileProvider
 
class  FuzzedSock
 

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 & PickValue (FuzzedDataProvider &fuzzed_data_provider, Collection &col)
 
std::vector< uint8_t > ConsumeRandomLengthByteVector (FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt) noexcept
 
std::vector< bool > ConsumeRandomLengthBitVector (FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt) noexcept
 
CDataStream 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< TConsumeRandomLengthIntegralVector (FuzzedDataProvider &fuzzed_data_provider, const size_t max_vector_size=16) noexcept
 
template<typename T >
std::optional< TConsumeDeserializable (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
 
int64_t ConsumeTime (FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min=std::nullopt, const std::optional< int64_t > &max=std::nullopt) noexcept
 
CMutableTransaction ConsumeTransaction (FuzzedDataProvider &fuzzed_data_provider, const std::optional< std::vector< uint256 >> &prevout_txids, const int max_num_in=10, const int max_num_out=10) noexcept
 
CScriptWitness ConsumeScriptWitness (FuzzedDataProvider &fuzzed_data_provider, const size_t max_stack_elem_size=32) noexcept
 
CScript ConsumeScript (FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt, const 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
 
CTxMemPoolEntry ConsumeTxMemPoolEntry (FuzzedDataProvider &fuzzed_data_provider, const CTransaction &tx) noexcept
 
CTxDestination ConsumeTxDestination (FuzzedDataProvider &fuzzed_data_provider) noexcept
 
template<typename T >
bool MultiplicationOverflow (const T i, const T j) noexcept
 
template<class T >
bool AdditionOverflow (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
 
std::vector< uint8_t > 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...
 
CNetAddr ConsumeNetAddr (FuzzedDataProvider &fuzzed_data_provider) noexcept
 
CSubNet ConsumeSubNet (FuzzedDataProvider &fuzzed_data_provider) noexcept
 
CService ConsumeService (FuzzedDataProvider &fuzzed_data_provider) noexcept
 
CAddress ConsumeAddress (FuzzedDataProvider &fuzzed_data_provider) noexcept
 
template<bool ReturnUniquePtr = false>
auto ConsumeNode (FuzzedDataProvider &fuzzed_data_provider, const std::optional< NodeId > &node_id_in=std::nullopt) noexcept
 
std::unique_ptr< CNodeConsumeNodeAsUniquePtr (FuzzedDataProvider &fdp, const std::optional< NodeId > &node_id_in=std::nullopt)
 
void FillNode (FuzzedDataProvider &fuzzed_data_provider, CNode &node, bool init_version) noexcept
 
FuzzedFileProvider ConsumeFile (FuzzedDataProvider &fuzzed_data_provider) noexcept
 
FuzzedAutoFileProvider ConsumeAutoFile (FuzzedDataProvider &fuzzed_data_provider) noexcept
 
template<typename Stream >
void WriteToStream (FuzzedDataProvider &fuzzed_data_provider, Stream &stream) noexcept
 
template<typename Stream >
void ReadFromStream (FuzzedDataProvider &fuzzed_data_provider, Stream &stream) noexcept
 
FuzzedSock ConsumeSock (FuzzedDataProvider &fuzzed_data_provider)
 

Macro Definition Documentation

◆ READ_FROM_STREAM_CASE

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

Definition at line 357 of file util.h.

◆ WRITE_TO_STREAM_CASE

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

Definition at line 327 of file util.h.

Function Documentation

◆ AdditionOverflow()

template<class T >
bool AdditionOverflow ( const T  i,
const T  j 
)
noexcept

Definition at line 195 of file util.h.

Here is the caller graph for this function:

◆ CallOneOf()

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

Definition at line 40 of file util.h.

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

◆ ConsumeAddress()

CAddress ConsumeAddress ( FuzzedDataProvider fuzzed_data_provider)
inlinenoexcept

Definition at line 252 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 162 of file util.h.

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

◆ ConsumeAutoFile()

FuzzedAutoFileProvider ConsumeAutoFile ( FuzzedDataProvider fuzzed_data_provider)
inlinenoexcept

Definition at line 322 of file util.h.

Here is the caller graph for this function:

◆ ConsumeDataStream()

CDataStream 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()

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

Definition at line 101 of file util.h.

Here is the call graph for this function:

◆ ConsumeFile()

FuzzedFileProvider ConsumeFile ( FuzzedDataProvider fuzzed_data_provider)
inlinenoexcept

Definition at line 301 of file util.h.

Here is the caller graph for this function:

◆ ConsumeFixedLengthByteVector()

std::vector<uint8_t> 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 230 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 221 of file util.cpp.

Here is the caller graph for this function:

◆ ConsumeNetAddr()

CNetAddr ConsumeNetAddr ( FuzzedDataProvider fuzzed_data_provider)
noexcept

Definition at line 373 of file util.cpp.

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

◆ ConsumeNode()

template<bool ReturnUniquePtr = false>
auto ConsumeNode ( FuzzedDataProvider fuzzed_data_provider,
const std::optional< NodeId > &  node_id_in = std::nullopt 
)
noexcept

Definition at line 258 of file util.h.

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

◆ ConsumeNodeAsUniquePtr()

std::unique_ptr<CNode> ConsumeNodeAsUniquePtr ( FuzzedDataProvider fdp,
const std::optional< NodeId > &  node_id_in = std::nullopt 
)
inline

Definition at line 276 of file util.h.

Here is the caller graph for this function:

◆ ConsumeOpcodeType()

opcodetype ConsumeOpcodeType ( FuzzedDataProvider fuzzed_data_provider)
inlinenoexcept

Definition at line 122 of file util.h.

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

◆ ConsumeRandomLengthBitVector()

std::vector<bool> ConsumeRandomLengthBitVector ( FuzzedDataProvider fuzzed_data_provider,
const std::optional< size_t > &  max_length = std::nullopt 
)
inlinenoexcept

Definition at line 69 of file util.h.

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

◆ ConsumeRandomLengthByteVector()

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

Definition at line 61 of file util.h.

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 90 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,
const std::optional< size_t > &  max_length = std::nullopt,
const bool  maybe_p2wsh = false 
)
noexcept

Definition at line 285 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 139 of file util.h.

Here is the caller graph for this function:

◆ ConsumeScriptWitness()

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

Definition at line 275 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 298 of file util.cpp.

Here is the caller graph for this function:

◆ ConsumeService()

CService ConsumeService ( FuzzedDataProvider fuzzed_data_provider)
inlinenoexcept

Definition at line 247 of file util.h.

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

◆ ConsumeSock()

FuzzedSock ConsumeSock ( FuzzedDataProvider fuzzed_data_provider)
inline

Definition at line 420 of file util.h.

Here is the caller graph for this function:

◆ ConsumeSubNet()

CSubNet ConsumeSubNet ( FuzzedDataProvider fuzzed_data_provider)
inlinenoexcept

Definition at line 242 of file util.h.

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

◆ ConsumeTime()

int64_t 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 226 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< uint256 >> &  prevout_txids,
const int  max_num_in = 10,
const int  max_num_out = 10 
)
noexcept

Definition at line 234 of file util.cpp.

Here is the call graph for this function:

◆ ConsumeTxDestination()

CTxDestination ConsumeTxDestination ( FuzzedDataProvider fuzzed_data_provider)
noexcept

Definition at line 309 of file util.cpp.

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

◆ ConsumeTxMemPoolEntry()

CTxMemPoolEntry ConsumeTxMemPoolEntry ( FuzzedDataProvider fuzzed_data_provider,
const CTransaction tx 
)
noexcept

Definition at line 347 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 144 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 153 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 115 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 362 of file util.cpp.

Here is the call graph for this function:

◆ FillNode()

void FillNode ( FuzzedDataProvider fuzzed_data_provider,
CNode node,
bool  init_version 
)
noexcept

Definition at line 202 of file util.cpp.

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 172 of file util.h.

Here is the caller graph for this function:

◆ PickValue()

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

Definition at line 52 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 363 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 221 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 211 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 333 of file util.h.

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