Bitcoin Core  23.99.0
P2P Digital Currency
util.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2021 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_TEST_FUZZ_UTIL_H
6 #define BITCOIN_TEST_FUZZ_UTIL_H
7 
8 #include <arith_uint256.h>
9 #include <chainparamsbase.h>
10 #include <coins.h>
11 #include <compat.h>
12 #include <consensus/amount.h>
13 #include <consensus/consensus.h>
14 #include <merkleblock.h>
15 #include <net.h>
16 #include <netaddress.h>
17 #include <netbase.h>
18 #include <primitives/transaction.h>
19 #include <script/script.h>
20 #include <script/standard.h>
21 #include <serialize.h>
22 #include <streams.h>
24 #include <test/fuzz/fuzz.h>
25 #include <test/util/net.h>
26 #include <txmempool.h>
27 #include <uint256.h>
28 #include <version.h>
29 
30 #include <algorithm>
31 #include <array>
32 #include <cstdint>
33 #include <cstdio>
34 #include <optional>
35 #include <string>
36 #include <vector>
37 
38 class PeerManager;
39 
40 class FuzzedSock : public Sock
41 {
43 
49  mutable std::optional<uint8_t> m_peek_data;
50 
51 public:
52  explicit FuzzedSock(FuzzedDataProvider& fuzzed_data_provider);
53 
54  ~FuzzedSock() override;
55 
56  FuzzedSock& operator=(Sock&& other) override;
57 
58  void Reset() override;
59 
60  ssize_t Send(const void* data, size_t len, int flags) const override;
61 
62  ssize_t Recv(void* buf, size_t len, int flags) const override;
63 
64  int Connect(const sockaddr*, socklen_t) const override;
65 
66  std::unique_ptr<Sock> Accept(sockaddr* addr, socklen_t* addr_len) const override;
67 
68  int GetSockOpt(int level, int opt_name, void* opt_val, socklen_t* opt_len) const override;
69 
70  int SetSockOpt(int level, int opt_name, const void* opt_val, socklen_t opt_len) const override;
71 
72  bool Wait(std::chrono::milliseconds timeout, Event requested, Event* occurred = nullptr) const override;
73 
74  bool IsConnected(std::string& errmsg) const override;
75 };
76 
77 [[nodiscard]] inline FuzzedSock ConsumeSock(FuzzedDataProvider& fuzzed_data_provider)
78 {
79  return FuzzedSock{fuzzed_data_provider};
80 }
81 
82 template <typename... Callables>
83 size_t CallOneOf(FuzzedDataProvider& fuzzed_data_provider, Callables... callables)
84 {
85  constexpr size_t call_size{sizeof...(callables)};
86  static_assert(call_size >= 1);
87  const size_t call_index{fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, call_size - 1)};
88 
89  size_t i{0};
90  ((i++ == call_index ? callables() : void()), ...);
91  return call_size;
92 }
93 
94 template <typename Collection>
95 auto& PickValue(FuzzedDataProvider& fuzzed_data_provider, Collection& col)
96 {
97  const auto sz = col.size();
98  assert(sz >= 1);
99  auto it = col.begin();
100  std::advance(it, fuzzed_data_provider.ConsumeIntegralInRange<decltype(sz)>(0, sz - 1));
101  return *it;
102 }
103 
104 [[nodiscard]] inline std::vector<uint8_t> ConsumeRandomLengthByteVector(FuzzedDataProvider& fuzzed_data_provider, const std::optional<size_t>& max_length = std::nullopt) noexcept
105 {
106  const std::string s = max_length ?
107  fuzzed_data_provider.ConsumeRandomLengthString(*max_length) :
108  fuzzed_data_provider.ConsumeRandomLengthString();
109  return {s.begin(), s.end()};
110 }
111 
112 [[nodiscard]] inline std::vector<bool> ConsumeRandomLengthBitVector(FuzzedDataProvider& fuzzed_data_provider, const std::optional<size_t>& max_length = std::nullopt) noexcept
113 {
114  return BytesToBits(ConsumeRandomLengthByteVector(fuzzed_data_provider, max_length));
115 }
116 
117 [[nodiscard]] inline CDataStream ConsumeDataStream(FuzzedDataProvider& fuzzed_data_provider, const std::optional<size_t>& max_length = std::nullopt) noexcept
118 {
119  return CDataStream{ConsumeRandomLengthByteVector(fuzzed_data_provider, max_length), SER_NETWORK, INIT_PROTO_VERSION};
120 }
121 
122 [[nodiscard]] inline std::vector<std::string> ConsumeRandomLengthStringVector(FuzzedDataProvider& fuzzed_data_provider, const size_t max_vector_size = 16, const size_t max_string_length = 16) noexcept
123 {
124  const size_t n_elements = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, max_vector_size);
125  std::vector<std::string> r;
126  for (size_t i = 0; i < n_elements; ++i) {
127  r.push_back(fuzzed_data_provider.ConsumeRandomLengthString(max_string_length));
128  }
129  return r;
130 }
131 
132 template <typename T>
133 [[nodiscard]] inline std::vector<T> ConsumeRandomLengthIntegralVector(FuzzedDataProvider& fuzzed_data_provider, const size_t max_vector_size = 16) noexcept
134 {
135  const size_t n_elements = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, max_vector_size);
136  std::vector<T> r;
137  for (size_t i = 0; i < n_elements; ++i) {
138  r.push_back(fuzzed_data_provider.ConsumeIntegral<T>());
139  }
140  return r;
141 }
142 
143 template <typename T>
144 [[nodiscard]] inline std::optional<T> ConsumeDeserializable(FuzzedDataProvider& fuzzed_data_provider, const std::optional<size_t>& max_length = std::nullopt) noexcept
145 {
146  const std::vector<uint8_t> buffer = ConsumeRandomLengthByteVector(fuzzed_data_provider, max_length);
148  T obj;
149  try {
150  ds >> obj;
151  } catch (const std::ios_base::failure&) {
152  return std::nullopt;
153  }
154  return obj;
155 }
156 
157 template <typename WeakEnumType, size_t size>
158 [[nodiscard]] WeakEnumType ConsumeWeakEnum(FuzzedDataProvider& fuzzed_data_provider, const WeakEnumType (&all_types)[size]) noexcept
159 {
160  return fuzzed_data_provider.ConsumeBool() ?
161  fuzzed_data_provider.PickValueInArray<WeakEnumType>(all_types) :
162  WeakEnumType(fuzzed_data_provider.ConsumeIntegral<typename std::underlying_type<WeakEnumType>::type>());
163 }
164 
165 [[nodiscard]] inline opcodetype ConsumeOpcodeType(FuzzedDataProvider& fuzzed_data_provider) noexcept
166 {
167  return static_cast<opcodetype>(fuzzed_data_provider.ConsumeIntegralInRange<uint32_t>(0, MAX_OPCODE));
168 }
169 
170 [[nodiscard]] CAmount ConsumeMoney(FuzzedDataProvider& fuzzed_data_provider, const std::optional<CAmount>& max = std::nullopt) noexcept;
171 
172 [[nodiscard]] int64_t ConsumeTime(FuzzedDataProvider& fuzzed_data_provider, const std::optional<int64_t>& min = std::nullopt, const std::optional<int64_t>& max = std::nullopt) noexcept;
173 
174 [[nodiscard]] 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;
175 
176 [[nodiscard]] CScriptWitness ConsumeScriptWitness(FuzzedDataProvider& fuzzed_data_provider, const size_t max_stack_elem_size = 32) noexcept;
177 
178 [[nodiscard]] CScript ConsumeScript(FuzzedDataProvider& fuzzed_data_provider, const bool maybe_p2wsh = false) noexcept;
179 
180 [[nodiscard]] uint32_t ConsumeSequence(FuzzedDataProvider& fuzzed_data_provider) noexcept;
181 
182 [[nodiscard]] inline CScriptNum ConsumeScriptNum(FuzzedDataProvider& fuzzed_data_provider) noexcept
183 {
184  return CScriptNum{fuzzed_data_provider.ConsumeIntegral<int64_t>()};
185 }
186 
187 [[nodiscard]] inline uint160 ConsumeUInt160(FuzzedDataProvider& fuzzed_data_provider) noexcept
188 {
189  const std::vector<uint8_t> v160 = fuzzed_data_provider.ConsumeBytes<uint8_t>(160 / 8);
190  if (v160.size() != 160 / 8) {
191  return {};
192  }
193  return uint160{v160};
194 }
195 
196 [[nodiscard]] inline uint256 ConsumeUInt256(FuzzedDataProvider& fuzzed_data_provider) noexcept
197 {
198  const std::vector<uint8_t> v256 = fuzzed_data_provider.ConsumeBytes<uint8_t>(256 / 8);
199  if (v256.size() != 256 / 8) {
200  return {};
201  }
202  return uint256{v256};
203 }
204 
205 [[nodiscard]] inline arith_uint256 ConsumeArithUInt256(FuzzedDataProvider& fuzzed_data_provider) noexcept
206 {
207  return UintToArith256(ConsumeUInt256(fuzzed_data_provider));
208 }
209 
210 [[nodiscard]] CTxMemPoolEntry ConsumeTxMemPoolEntry(FuzzedDataProvider& fuzzed_data_provider, const CTransaction& tx) noexcept;
211 
212 [[nodiscard]] CTxDestination ConsumeTxDestination(FuzzedDataProvider& fuzzed_data_provider) noexcept;
213 
214 template <typename T>
215 [[nodiscard]] bool MultiplicationOverflow(const T i, const T j) noexcept
216 {
217  static_assert(std::is_integral<T>::value, "Integral required.");
218  if (std::numeric_limits<T>::is_signed) {
219  if (i > 0) {
220  if (j > 0) {
221  return i > (std::numeric_limits<T>::max() / j);
222  } else {
223  return j < (std::numeric_limits<T>::min() / i);
224  }
225  } else {
226  if (j > 0) {
227  return i < (std::numeric_limits<T>::min() / j);
228  } else {
229  return i != 0 && (j < (std::numeric_limits<T>::max() / i));
230  }
231  }
232  } else {
233  return j != 0 && i > std::numeric_limits<T>::max() / j;
234  }
235 }
236 
237 [[nodiscard]] bool ContainsSpentInput(const CTransaction& tx, const CCoinsViewCache& inputs) noexcept;
238 
242 template <typename T, size_t size>
243 void SetFuzzedErrNo(FuzzedDataProvider& fuzzed_data_provider, const std::array<T, size>& errnos)
244 {
245  errno = fuzzed_data_provider.PickValueInArray(errnos);
246 }
247 
248 /*
249  * Sets a fuzzed errno in the range [0, 133 (EHWPOISON)]. Can be used from functions emulating
250  * standard library functions that set errno, or in other contexts where the value of errno
251  * might be relevant for the execution path that will be taken.
252  */
253 inline void SetFuzzedErrNo(FuzzedDataProvider& fuzzed_data_provider) noexcept
254 {
255  errno = fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 133);
256 }
257 
262 [[nodiscard]] inline std::vector<uint8_t> ConsumeFixedLengthByteVector(FuzzedDataProvider& fuzzed_data_provider, const size_t length) noexcept
263 {
264  std::vector<uint8_t> result(length);
265  const std::vector<uint8_t> random_bytes = fuzzed_data_provider.ConsumeBytes<uint8_t>(length);
266  if (!random_bytes.empty()) {
267  std::memcpy(result.data(), random_bytes.data(), random_bytes.size());
268  }
269  return result;
270 }
271 
272 CNetAddr ConsumeNetAddr(FuzzedDataProvider& fuzzed_data_provider) noexcept;
273 
274 inline CSubNet ConsumeSubNet(FuzzedDataProvider& fuzzed_data_provider) noexcept
275 {
276  return {ConsumeNetAddr(fuzzed_data_provider), fuzzed_data_provider.ConsumeIntegral<uint8_t>()};
277 }
278 
279 inline CService ConsumeService(FuzzedDataProvider& fuzzed_data_provider) noexcept
280 {
281  return {ConsumeNetAddr(fuzzed_data_provider), fuzzed_data_provider.ConsumeIntegral<uint16_t>()};
282 }
283 
284 inline CAddress ConsumeAddress(FuzzedDataProvider& fuzzed_data_provider) noexcept
285 {
286  return {ConsumeService(fuzzed_data_provider), ConsumeWeakEnum(fuzzed_data_provider, ALL_SERVICE_FLAGS), fuzzed_data_provider.ConsumeIntegral<uint32_t>()};
287 }
288 
289 template <bool ReturnUniquePtr = false>
290 auto ConsumeNode(FuzzedDataProvider& fuzzed_data_provider, const std::optional<NodeId>& node_id_in = std::nullopt) noexcept
291 {
292  const NodeId node_id = node_id_in.value_or(fuzzed_data_provider.ConsumeIntegralInRange<NodeId>(0, std::numeric_limits<NodeId>::max()));
293  const ServiceFlags local_services = ConsumeWeakEnum(fuzzed_data_provider, ALL_SERVICE_FLAGS);
294  const auto sock = std::make_shared<FuzzedSock>(fuzzed_data_provider);
295  const CAddress address = ConsumeAddress(fuzzed_data_provider);
296  const uint64_t keyed_net_group = fuzzed_data_provider.ConsumeIntegral<uint64_t>();
297  const uint64_t local_host_nonce = fuzzed_data_provider.ConsumeIntegral<uint64_t>();
298  const CAddress addr_bind = ConsumeAddress(fuzzed_data_provider);
299  const std::string addr_name = fuzzed_data_provider.ConsumeRandomLengthString(64);
300  const ConnectionType conn_type = fuzzed_data_provider.PickValueInArray(ALL_CONNECTION_TYPES);
301  const bool inbound_onion{conn_type == ConnectionType::INBOUND ? fuzzed_data_provider.ConsumeBool() : false};
302  if constexpr (ReturnUniquePtr) {
303  return std::make_unique<CNode>(node_id,
304  local_services,
305  sock,
306  address,
307  keyed_net_group,
308  local_host_nonce,
309  addr_bind,
310  addr_name,
311  conn_type,
312  inbound_onion);
313  } else {
314  return CNode{node_id,
315  local_services,
316  sock,
317  address,
318  keyed_net_group,
319  local_host_nonce,
320  addr_bind,
321  addr_name,
322  conn_type,
323  inbound_onion};
324  }
325 }
326 inline std::unique_ptr<CNode> ConsumeNodeAsUniquePtr(FuzzedDataProvider& fdp, const std::optional<NodeId>& node_id_in = std::nullopt) { return ConsumeNode<true>(fdp, node_id_in); }
327 
328 void FillNode(FuzzedDataProvider& fuzzed_data_provider, ConnmanTestMsg& connman, PeerManager& peerman, CNode& node) noexcept;
329 
331 {
333  int64_t m_offset = 0;
334 
335 public:
336  FuzzedFileProvider(FuzzedDataProvider& fuzzed_data_provider) : m_fuzzed_data_provider{fuzzed_data_provider}
337  {
338  }
339 
340  FILE* open();
341 
342  static ssize_t read(void* cookie, char* buf, size_t size);
343 
344  static ssize_t write(void* cookie, const char* buf, size_t size);
345 
346  static int seek(void* cookie, int64_t* offset, int whence);
347 
348  static int close(void* cookie);
349 };
350 
351 [[nodiscard]] inline FuzzedFileProvider ConsumeFile(FuzzedDataProvider& fuzzed_data_provider) noexcept
352 {
353  return {fuzzed_data_provider};
354 }
355 
357 {
360 
361 public:
362  FuzzedAutoFileProvider(FuzzedDataProvider& fuzzed_data_provider) : m_fuzzed_data_provider{fuzzed_data_provider}, m_fuzzed_file_provider{fuzzed_data_provider}
363  {
364  }
365 
367  {
369  }
370 };
371 
372 [[nodiscard]] inline FuzzedAutoFileProvider ConsumeAutoFile(FuzzedDataProvider& fuzzed_data_provider) noexcept
373 {
374  return {fuzzed_data_provider};
375 }
376 
377 #define WRITE_TO_STREAM_CASE(type, consume) \
378  [&] { \
379  type o = consume; \
380  stream << o; \
381  }
382 template <typename Stream>
383 void WriteToStream(FuzzedDataProvider& fuzzed_data_provider, Stream& stream) noexcept
384 {
385  while (fuzzed_data_provider.ConsumeBool()) {
386  try {
387  CallOneOf(
388  fuzzed_data_provider,
389  WRITE_TO_STREAM_CASE(bool, fuzzed_data_provider.ConsumeBool()),
390  WRITE_TO_STREAM_CASE(int8_t, fuzzed_data_provider.ConsumeIntegral<int8_t>()),
391  WRITE_TO_STREAM_CASE(uint8_t, fuzzed_data_provider.ConsumeIntegral<uint8_t>()),
392  WRITE_TO_STREAM_CASE(int16_t, fuzzed_data_provider.ConsumeIntegral<int16_t>()),
393  WRITE_TO_STREAM_CASE(uint16_t, fuzzed_data_provider.ConsumeIntegral<uint16_t>()),
394  WRITE_TO_STREAM_CASE(int32_t, fuzzed_data_provider.ConsumeIntegral<int32_t>()),
395  WRITE_TO_STREAM_CASE(uint32_t, fuzzed_data_provider.ConsumeIntegral<uint32_t>()),
396  WRITE_TO_STREAM_CASE(int64_t, fuzzed_data_provider.ConsumeIntegral<int64_t>()),
397  WRITE_TO_STREAM_CASE(uint64_t, fuzzed_data_provider.ConsumeIntegral<uint64_t>()),
398  WRITE_TO_STREAM_CASE(std::string, fuzzed_data_provider.ConsumeRandomLengthString(32)),
399  WRITE_TO_STREAM_CASE(std::vector<uint8_t>, ConsumeRandomLengthIntegralVector<uint8_t>(fuzzed_data_provider)));
400  } catch (const std::ios_base::failure&) {
401  break;
402  }
403  }
404 }
405 
406 #define READ_FROM_STREAM_CASE(type) \
407  [&] { \
408  type o; \
409  stream >> o; \
410  }
411 template <typename Stream>
412 void ReadFromStream(FuzzedDataProvider& fuzzed_data_provider, Stream& stream) noexcept
413 {
414  while (fuzzed_data_provider.ConsumeBool()) {
415  try {
416  CallOneOf(
417  fuzzed_data_provider,
418  READ_FROM_STREAM_CASE(bool),
419  READ_FROM_STREAM_CASE(int8_t),
420  READ_FROM_STREAM_CASE(uint8_t),
421  READ_FROM_STREAM_CASE(int16_t),
422  READ_FROM_STREAM_CASE(uint16_t),
423  READ_FROM_STREAM_CASE(int32_t),
424  READ_FROM_STREAM_CASE(uint32_t),
425  READ_FROM_STREAM_CASE(int64_t),
426  READ_FROM_STREAM_CASE(uint64_t),
427  READ_FROM_STREAM_CASE(std::string),
428  READ_FROM_STREAM_CASE(std::vector<uint8_t>));
429  } catch (const std::ios_base::failure&) {
430  break;
431  }
432  }
433 }
434 
435 #endif // BITCOIN_TEST_FUZZ_UTIL_H
NodeId
int64_t NodeId
Definition: net.h:91
ConsumeRandomLengthStringVector
std::vector< std::string > ConsumeRandomLengthStringVector(FuzzedDataProvider &fuzzed_data_provider, const size_t max_vector_size=16, const size_t max_string_length=16) noexcept
Definition: util.h:122
ConsumeUInt256
uint256 ConsumeUInt256(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.h:196
CService
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:520
arith_uint256.h
merkleblock.h
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: util.cpp:293
assert
assert(!tx.IsCoinBase())
flags
int flags
Definition: bitcoin-tx.cpp:525
FuzzedSock::Reset
void Reset() override
Close if non-empty.
Definition: util.cpp:39
streams.h
ConsumeScript
CScript ConsumeScript(FuzzedDataProvider &fuzzed_data_provider, const bool maybe_p2wsh=false) noexcept
Definition: util.cpp:352
transaction.h
FuzzedSock::Send
ssize_t Send(const void *data, size_t len, int flags) const override
send(2) wrapper.
Definition: util.cpp:44
FuzzedSock
Definition: util.h:40
CNetAddr
Network address.
Definition: netaddress.h:117
uint256.h
arith_uint256
256-bit unsigned big integer.
Definition: arith_uint256.h:245
FuzzedFileProvider::seek
static int seek(void *cookie, int64_t *offset, int whence)
Definition: util.cpp:587
chainparamsbase.h
ConsumeSock
FuzzedSock ConsumeSock(FuzzedDataProvider &fuzzed_data_provider)
Definition: util.h:77
CNode
Information about a peer.
Definition: net.h:410
FuzzedFileProvider::write
static ssize_t write(void *cookie, const char *buf, size_t size)
Definition: util.cpp:575
FuzzedDataProvider::ConsumeRandomLengthString
std::string ConsumeRandomLengthString(size_t max_length)
Definition: FuzzedDataProvider.h:152
FuzzedDataProvider::PickValueInArray
T PickValueInArray(const T(&array)[size])
Definition: FuzzedDataProvider.h:303
FuzzedSock::m_fuzzed_data_provider
FuzzedDataProvider & m_fuzzed_data_provider
Definition: util.h:42
opcodetype
opcodetype
Script opcodes.
Definition: script.h:69
FuzzedAutoFileProvider::m_fuzzed_file_provider
FuzzedFileProvider m_fuzzed_file_provider
Definition: util.h:359
ServiceFlags
ServiceFlags
nServices flags
Definition: protocol.h:271
ConsumeSequence
uint32_t ConsumeSequence(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.cpp:418
FuzzedSock::~FuzzedSock
~FuzzedSock() override
Definition: util.cpp:24
version.h
ConsumeOpcodeType
opcodetype ConsumeOpcodeType(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.h:165
WRITE_TO_STREAM_CASE
#define WRITE_TO_STREAM_CASE(type, consume)
Definition: util.h:377
CTransaction
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:279
txmempool.h
Sock
RAII helper class that manages a socket.
Definition: sock.h:26
CScriptWitness
Definition: script.h:562
ConnmanTestMsg
Definition: net.h:19
ConsumeNetAddr
CNetAddr ConsumeNetAddr(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.cpp:493
ConsumeRandomLengthBitVector
std::vector< bool > ConsumeRandomLengthBitVector(FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt) noexcept
Definition: util.h:112
SetFuzzedErrNo
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: util.h:243
CAutoFile
Non-refcounted RAII wrapper for FILE*.
Definition: streams.h:475
CScriptNum
Definition: script.h:222
ConnectionType::INBOUND
@ INBOUND
Inbound connections are those initiated by a peer.
ConsumeSubNet
CSubNet ConsumeSubNet(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.h:274
MultiplicationOverflow
bool MultiplicationOverflow(const T i, const T j) noexcept
Definition: util.h:215
CTxDestination
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:158
ConsumeTxMemPoolEntry
CTxMemPoolEntry ConsumeTxMemPoolEntry(FuzzedDataProvider &fuzzed_data_provider, const CTransaction &tx) noexcept
Definition: util.cpp:467
ConsumeFile
FuzzedFileProvider ConsumeFile(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.h:351
CallOneOf
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)
Definition: util.h:83
net.h
compat.h
ConsumeDataStream
CDataStream ConsumeDataStream(FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt) noexcept
Definition: util.h:117
netaddress.h
FuzzedSock::GetSockOpt
int GetSockOpt(int level, int opt_name, void *opt_val, socklen_t *opt_len) const override
getsockopt(2) wrapper.
Definition: util.cpp:177
consensus.h
ALL_SERVICE_FLAGS
constexpr ServiceFlags ALL_SERVICE_FLAGS[]
Definition: net.h:48
FuzzedDataProvider.h
ConsumeArithUInt256
arith_uint256 ConsumeArithUInt256(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.h:205
FuzzedAutoFileProvider::m_fuzzed_data_provider
FuzzedDataProvider & m_fuzzed_data_provider
Definition: util.h:358
CAmount
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
ConsumeRandomLengthByteVector
std::vector< uint8_t > ConsumeRandomLengthByteVector(FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt) noexcept
Definition: util.h:104
standard.h
FuzzedAutoFileProvider
Definition: util.h:356
FuzzedFileProvider::FuzzedFileProvider
FuzzedFileProvider(FuzzedDataProvider &fuzzed_data_provider)
Definition: util.h:336
CSubNet
Definition: netaddress.h:467
READ_FROM_STREAM_CASE
#define READ_FROM_STREAM_CASE(type)
Definition: util.h:406
ConsumeUInt160
uint160 ConsumeUInt160(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.h:187
ConsumeNode
auto ConsumeNode(FuzzedDataProvider &fuzzed_data_provider, const std::optional< NodeId > &node_id_in=std::nullopt) noexcept
Definition: util.h:290
ALL_CONNECTION_TYPES
constexpr ConnectionType ALL_CONNECTION_TYPES[]
Definition: net.h:70
PeerManager
Definition: net_processing.h:39
FuzzedFileProvider::open
FILE * open()
Definition: util.cpp:515
uint256
256-bit opaque blob.
Definition: uint256.h:126
BytesToBits
std::vector< bool > BytesToBits(const std::vector< unsigned char > &bytes)
Definition: merkleblock.cpp:21
ConsumeMoney
CAmount ConsumeMoney(FuzzedDataProvider &fuzzed_data_provider, const std::optional< CAmount > &max=std::nullopt) noexcept
Definition: util.cpp:288
ConsumeService
CService ConsumeService(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.h:279
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:410
script.h
coins.h
FuzzedSock::IsConnected
bool IsConnected(std::string &errmsg) const override
Check if still connected.
Definition: util.cpp:226
FillNode
void FillNode(FuzzedDataProvider &fuzzed_data_provider, ConnmanTestMsg &connman, PeerManager &peerman, CNode &node) noexcept
Definition: util.cpp:235
FuzzedFileProvider::read
static ssize_t read(void *cookie, char *buf, size_t size)
Definition: util.cpp:556
uint160
160-bit opaque blob.
Definition: uint256.h:115
FuzzedFileProvider::close
static int close(void *cookie)
Definition: util.cpp:615
CAddress
A CService with information about it as peer.
Definition: protocol.h:358
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: util.cpp:301
CCoinsViewCache
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:213
FuzzedSock::m_peek_data
std::optional< uint8_t > m_peek_data
Data to return when MSG_PEEK is used as a Recv() flag.
Definition: util.h:49
ConsumeAutoFile
FuzzedAutoFileProvider ConsumeAutoFile(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.h:372
FuzzedAutoFileProvider::FuzzedAutoFileProvider
FuzzedAutoFileProvider(FuzzedDataProvider &fuzzed_data_provider)
Definition: util.h:362
ContainsSpentInput
bool ContainsSpentInput(const CTransaction &tx, const CCoinsViewCache &inputs) noexcept
Definition: util.cpp:482
fuzz.h
UintToArith256
arith_uint256 UintToArith256(const uint256 &a)
Definition: arith_uint256.cpp:248
CTxMemPoolEntry
Definition: txmempool.h:85
FuzzedDataProvider
Definition: FuzzedDataProvider.h:31
FuzzedSock::Accept
std::unique_ptr< Sock > Accept(sockaddr *addr, socklen_t *addr_len) const override
accept(2) wrapper.
Definition: util.cpp:163
FuzzedDataProvider::ConsumeIntegral
T ConsumeIntegral()
Definition: FuzzedDataProvider.h:194
Sock::Event
uint8_t Event
Definition: sock.h:128
ReadFromStream
void ReadFromStream(FuzzedDataProvider &fuzzed_data_provider, Stream &stream) noexcept
Definition: util.h:412
ConsumeNodeAsUniquePtr
std::unique_ptr< CNode > ConsumeNodeAsUniquePtr(FuzzedDataProvider &fdp, const std::optional< NodeId > &node_id_in=std::nullopt)
Definition: util.h:326
ConsumeScriptWitness
CScriptWitness ConsumeScriptWitness(FuzzedDataProvider &fuzzed_data_provider, const size_t max_stack_elem_size=32) noexcept
Definition: util.cpp:342
WriteToStream
void WriteToStream(FuzzedDataProvider &fuzzed_data_provider, Stream &stream) noexcept
Definition: util.h:383
FuzzedSock::FuzzedSock
FuzzedSock(FuzzedDataProvider &fuzzed_data_provider)
Definition: util.cpp:18
node
Definition: init.h:22
serialize.h
FuzzedSock::Recv
ssize_t Recv(void *buf, size_t len, int flags) const override
recv(2) wrapper.
Definition: util.cpp:76
CDataStream
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:185
FuzzedSock::Wait
bool Wait(std::chrono::milliseconds timeout, Event requested, Event *occurred=nullptr) const override
Wait for readiness for input (recv) or output (send).
Definition: util.cpp:209
FuzzedFileProvider::m_offset
int64_t m_offset
Definition: util.h:333
SER_NETWORK
@ SER_NETWORK
Definition: serialize.h:131
ConsumeTxDestination
CTxDestination ConsumeTxDestination(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.cpp:429
ConsumeDeserializable
std::optional< T > ConsumeDeserializable(FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt) noexcept
Definition: util.h:144
netbase.h
FuzzedSock::SetSockOpt
int SetSockOpt(int level, int opt_name, const void *opt_val, socklen_t opt_len) const override
setsockopt(2) wrapper.
Definition: util.cpp:196
ConsumeFixedLengthByteVector
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 th...
Definition: util.h:262
FuzzedDataProvider::ConsumeBool
bool ConsumeBool()
Definition: FuzzedDataProvider.h:288
FuzzedFileProvider
Definition: util.h:330
ConsumeWeakEnum
WeakEnumType ConsumeWeakEnum(FuzzedDataProvider &fuzzed_data_provider, const WeakEnumType(&all_types)[size]) noexcept
Definition: util.h:158
CMutableTransaction
A mutable version of CTransaction.
Definition: transaction.h:364
FuzzedSock::operator=
FuzzedSock & operator=(Sock &&other) override
Move assignment operator, grab the socket from another object and close ours (if set).
Definition: util.cpp:33
FuzzedSock::Connect
int Connect(const sockaddr *, socklen_t) const override
connect(2) wrapper.
Definition: util.cpp:141
T
#define T(expected, seed, data)
ConsumeScriptNum
CScriptNum ConsumeScriptNum(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.h:182
FuzzedFileProvider::m_fuzzed_data_provider
FuzzedDataProvider & m_fuzzed_data_provider
Definition: util.h:332
amount.h
ConnectionType
ConnectionType
Different types of connections to a peer.
Definition: net.h:131
FuzzedAutoFileProvider::open
CAutoFile open()
Definition: util.h:366
ConsumeRandomLengthIntegralVector
std::vector< T > ConsumeRandomLengthIntegralVector(FuzzedDataProvider &fuzzed_data_provider, const size_t max_vector_size=16) noexcept
Definition: util.h:133
FuzzedDataProvider::ConsumeIntegralInRange
T ConsumeIntegralInRange(T min, T max)
Definition: FuzzedDataProvider.h:204
FuzzedDataProvider::ConsumeBytes
std::vector< T > ConsumeBytes(size_t num_bytes)
Definition: FuzzedDataProvider.h:108
ConsumeAddress
CAddress ConsumeAddress(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.h:284
PickValue
auto & PickValue(FuzzedDataProvider &fuzzed_data_provider, Collection &col)
Definition: util.h:95
INIT_PROTO_VERSION
static const int INIT_PROTO_VERSION
initial proto version, to be increased after version/verack negotiation
Definition: version.h:15
MAX_OPCODE
static const unsigned int MAX_OPCODE
Definition: script.h:212