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