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