Bitcoin Core 22.99.0
P2P Digital Currency
util.cpp
Go to the documentation of this file.
1// Copyright (c) 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#include <consensus/amount.h>
6#include <pubkey.h>
7#include <test/fuzz/util.h>
8#include <test/util/script.h>
9#include <util/rbf.h>
10#include <util/time.h>
11#include <version.h>
12
14 : m_fuzzed_data_provider{fuzzed_data_provider}
15{
17}
18
20{
21 // Sock::~Sock() will be called after FuzzedSock::~FuzzedSock() and it will call
22 // Sock::Reset() (not FuzzedSock::Reset()!) which will call CloseSocket(m_socket).
23 // Avoid closing an arbitrary file descriptor (m_socket is just a random very high number which
24 // theoretically may concide with a real opened file descriptor).
25 Reset();
26}
27
29{
30 assert(false && "Move of Sock into FuzzedSock not allowed.");
31 return *this;
32}
33
35{
37}
38
39ssize_t FuzzedSock::Send(const void* data, size_t len, int flags) const
40{
41 constexpr std::array send_errnos{
42 EACCES,
43 EAGAIN,
44 EALREADY,
45 EBADF,
46 ECONNRESET,
47 EDESTADDRREQ,
48 EFAULT,
49 EINTR,
50 EINVAL,
51 EISCONN,
52 EMSGSIZE,
53 ENOBUFS,
54 ENOMEM,
55 ENOTCONN,
56 ENOTSOCK,
57 EOPNOTSUPP,
58 EPIPE,
59 EWOULDBLOCK,
60 };
62 return len;
63 }
64 const ssize_t r = m_fuzzed_data_provider.ConsumeIntegralInRange<ssize_t>(-1, len);
65 if (r == -1) {
67 }
68 return r;
69}
70
71ssize_t FuzzedSock::Recv(void* buf, size_t len, int flags) const
72{
73 // Have a permanent error at recv_errnos[0] because when the fuzzed data is exhausted
74 // SetFuzzedErrNo() will always return the first element and we want to avoid Recv()
75 // returning -1 and setting errno to EAGAIN repeatedly.
76 constexpr std::array recv_errnos{
77 ECONNREFUSED,
78 EAGAIN,
79 EBADF,
80 EFAULT,
81 EINTR,
82 EINVAL,
83 ENOMEM,
84 ENOTCONN,
85 ENOTSOCK,
86 EWOULDBLOCK,
87 };
88 assert(buf != nullptr || len == 0);
89 if (len == 0 || m_fuzzed_data_provider.ConsumeBool()) {
90 const ssize_t r = m_fuzzed_data_provider.ConsumeBool() ? 0 : -1;
91 if (r == -1) {
93 }
94 return r;
95 }
96 std::vector<uint8_t> random_bytes;
97 bool pad_to_len_bytes{m_fuzzed_data_provider.ConsumeBool()};
98 if (m_peek_data.has_value()) {
99 // `MSG_PEEK` was used in the preceding `Recv()` call, return `m_peek_data`.
100 random_bytes.assign({m_peek_data.value()});
101 if ((flags & MSG_PEEK) == 0) {
102 m_peek_data.reset();
103 }
104 pad_to_len_bytes = false;
105 } else if ((flags & MSG_PEEK) != 0) {
106 // New call with `MSG_PEEK`.
107 random_bytes = m_fuzzed_data_provider.ConsumeBytes<uint8_t>(1);
108 if (!random_bytes.empty()) {
109 m_peek_data = random_bytes[0];
110 pad_to_len_bytes = false;
111 }
112 } else {
113 random_bytes = m_fuzzed_data_provider.ConsumeBytes<uint8_t>(
115 }
116 if (random_bytes.empty()) {
117 const ssize_t r = m_fuzzed_data_provider.ConsumeBool() ? 0 : -1;
118 if (r == -1) {
120 }
121 return r;
122 }
123 std::memcpy(buf, random_bytes.data(), random_bytes.size());
124 if (pad_to_len_bytes) {
125 if (len > random_bytes.size()) {
126 std::memset((char*)buf + random_bytes.size(), 0, len - random_bytes.size());
127 }
128 return len;
129 }
130 if (m_fuzzed_data_provider.ConsumeBool() && std::getenv("FUZZED_SOCKET_FAKE_LATENCY") != nullptr) {
131 std::this_thread::sleep_for(std::chrono::milliseconds{2});
132 }
133 return random_bytes.size();
134}
135
136int FuzzedSock::Connect(const sockaddr*, socklen_t) const
137{
138 // Have a permanent error at connect_errnos[0] because when the fuzzed data is exhausted
139 // SetFuzzedErrNo() will always return the first element and we want to avoid Connect()
140 // returning -1 and setting errno to EAGAIN repeatedly.
141 constexpr std::array connect_errnos{
142 ECONNREFUSED,
143 EAGAIN,
144 ECONNRESET,
145 EHOSTUNREACH,
146 EINPROGRESS,
147 EINTR,
148 ENETUNREACH,
149 ETIMEDOUT,
150 };
152 SetFuzzedErrNo(m_fuzzed_data_provider, connect_errnos);
153 return -1;
154 }
155 return 0;
156}
157
158int FuzzedSock::GetSockOpt(int level, int opt_name, void* opt_val, socklen_t* opt_len) const
159{
160 constexpr std::array getsockopt_errnos{
161 ENOMEM,
162 ENOBUFS,
163 };
165 SetFuzzedErrNo(m_fuzzed_data_provider, getsockopt_errnos);
166 return -1;
167 }
168 if (opt_val == nullptr) {
169 return 0;
170 }
171 std::memcpy(opt_val,
173 *opt_len);
174 return 0;
175}
176
177bool FuzzedSock::Wait(std::chrono::milliseconds timeout, Event requested, Event* occurred) const
178{
179 constexpr std::array wait_errnos{
180 EBADF,
181 EINTR,
182 EINVAL,
183 };
186 return false;
187 }
188 if (occurred != nullptr) {
189 *occurred = m_fuzzed_data_provider.ConsumeBool() ? requested : 0;
190 }
191 return true;
192}
193
194bool FuzzedSock::IsConnected(std::string& errmsg) const
195{
197 return true;
198 }
199 errmsg = "disconnected at random by the fuzzer";
200 return false;
201}
202
203void FillNode(FuzzedDataProvider& fuzzed_data_provider, CNode& node, bool init_version) noexcept
204{
205 const ServiceFlags remote_services = ConsumeWeakEnum(fuzzed_data_provider, ALL_SERVICE_FLAGS);
206 const NetPermissionFlags permission_flags = ConsumeWeakEnum(fuzzed_data_provider, ALL_NET_PERMISSION_FLAGS);
207 const int32_t version = fuzzed_data_provider.ConsumeIntegralInRange<int32_t>(MIN_PEER_PROTO_VERSION, std::numeric_limits<int32_t>::max());
208 const bool filter_txs = fuzzed_data_provider.ConsumeBool();
209
210 node.nServices = remote_services;
211 node.m_permissionFlags = permission_flags;
212 if (init_version) {
213 node.nVersion = version;
214 node.SetCommonVersion(std::min(version, PROTOCOL_VERSION));
215 }
216 if (node.m_tx_relay != nullptr) {
217 LOCK(node.m_tx_relay->cs_filter);
218 node.m_tx_relay->fRelayTxes = filter_txs;
219 }
220}
221
222CAmount ConsumeMoney(FuzzedDataProvider& fuzzed_data_provider, const std::optional<CAmount>& max) noexcept
223{
224 return fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(0, max.value_or(MAX_MONEY));
225}
226
227int64_t ConsumeTime(FuzzedDataProvider& fuzzed_data_provider, const std::optional<int64_t>& min, const std::optional<int64_t>& max) noexcept
228{
229 // Avoid t=0 (1970-01-01T00:00:00Z) since SetMockTime(0) disables mocktime.
230 static const int64_t time_min = ParseISO8601DateTime("1970-01-01T00:00:01Z");
231 static const int64_t time_max = ParseISO8601DateTime("9999-12-31T23:59:59Z");
232 return fuzzed_data_provider.ConsumeIntegralInRange<int64_t>(min.value_or(time_min), max.value_or(time_max));
233}
234
235CMutableTransaction ConsumeTransaction(FuzzedDataProvider& fuzzed_data_provider, const std::optional<std::vector<uint256>>& prevout_txids, const int max_num_in, const int max_num_out) noexcept
236{
237 CMutableTransaction tx_mut;
238 const auto p2wsh_op_true = fuzzed_data_provider.ConsumeBool();
239 tx_mut.nVersion = fuzzed_data_provider.ConsumeBool() ?
241 fuzzed_data_provider.ConsumeIntegral<int32_t>();
242 tx_mut.nLockTime = fuzzed_data_provider.ConsumeIntegral<uint32_t>();
243 const auto num_in = fuzzed_data_provider.ConsumeIntegralInRange<int>(0, max_num_in);
244 const auto num_out = fuzzed_data_provider.ConsumeIntegralInRange<int>(0, max_num_out);
245 for (int i = 0; i < num_in; ++i) {
246 const auto& txid_prev = prevout_txids ?
247 PickValue(fuzzed_data_provider, *prevout_txids) :
248 ConsumeUInt256(fuzzed_data_provider);
249 const auto index_out = fuzzed_data_provider.ConsumeIntegralInRange<uint32_t>(0, max_num_out);
250 const auto sequence = ConsumeSequence(fuzzed_data_provider);
251 const auto script_sig = p2wsh_op_true ? CScript{} : ConsumeScript(fuzzed_data_provider);
252 CScriptWitness script_wit;
253 if (p2wsh_op_true) {
254 script_wit.stack = std::vector<std::vector<uint8_t>>{WITNESS_STACK_ELEM_OP_TRUE};
255 } else {
256 script_wit = ConsumeScriptWitness(fuzzed_data_provider);
257 }
258 CTxIn in;
259 in.prevout = COutPoint{txid_prev, index_out};
260 in.nSequence = sequence;
261 in.scriptSig = script_sig;
262 in.scriptWitness = script_wit;
263
264 tx_mut.vin.push_back(in);
265 }
266 for (int i = 0; i < num_out; ++i) {
267 const auto amount = fuzzed_data_provider.ConsumeIntegralInRange<CAmount>(-10, 50 * COIN + 10);
268 const auto script_pk = p2wsh_op_true ?
270 ConsumeScript(fuzzed_data_provider, /* max_length */ 128, /* maybe_p2wsh */ true);
271 tx_mut.vout.emplace_back(amount, script_pk);
272 }
273 return tx_mut;
274}
275
276CScriptWitness ConsumeScriptWitness(FuzzedDataProvider& fuzzed_data_provider, const size_t max_stack_elem_size) noexcept
277{
278 CScriptWitness ret;
279 const auto n_elements = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, max_stack_elem_size);
280 for (size_t i = 0; i < n_elements; ++i) {
281 ret.stack.push_back(ConsumeRandomLengthByteVector(fuzzed_data_provider));
282 }
283 return ret;
284}
285
286CScript ConsumeScript(FuzzedDataProvider& fuzzed_data_provider, const std::optional<size_t>& max_length, const bool maybe_p2wsh) noexcept
287{
288 const std::vector<uint8_t> b = ConsumeRandomLengthByteVector(fuzzed_data_provider, max_length);
289 CScript r_script{b.begin(), b.end()};
290 if (maybe_p2wsh && fuzzed_data_provider.ConsumeBool()) {
291 uint256 script_hash;
292 CSHA256().Write(r_script.data(), r_script.size()).Finalize(script_hash.begin());
293 r_script.clear();
294 r_script << OP_0 << ToByteVector(script_hash);
295 }
296 return r_script;
297}
298
299uint32_t ConsumeSequence(FuzzedDataProvider& fuzzed_data_provider) noexcept
300{
301 return fuzzed_data_provider.ConsumeBool() ?
302 fuzzed_data_provider.PickValueInArray({
306 }) :
307 fuzzed_data_provider.ConsumeIntegral<uint32_t>();
308}
309
311{
312 CTxDestination tx_destination;
313 const size_t call_size{CallOneOf(
314 fuzzed_data_provider,
315 [&] {
316 tx_destination = CNoDestination{};
317 },
318 [&] {
319 tx_destination = PKHash{ConsumeUInt160(fuzzed_data_provider)};
320 },
321 [&] {
322 tx_destination = ScriptHash{ConsumeUInt160(fuzzed_data_provider)};
323 },
324 [&] {
325 tx_destination = WitnessV0ScriptHash{ConsumeUInt256(fuzzed_data_provider)};
326 },
327 [&] {
328 tx_destination = WitnessV0KeyHash{ConsumeUInt160(fuzzed_data_provider)};
329 },
330 [&] {
331 tx_destination = WitnessV1Taproot{XOnlyPubKey{ConsumeUInt256(fuzzed_data_provider)}};
332 },
333 [&] {
334 WitnessUnknown witness_unknown{};
335 witness_unknown.version = fuzzed_data_provider.ConsumeIntegralInRange(2, 16);
336 std::vector<uint8_t> witness_unknown_program_1{fuzzed_data_provider.ConsumeBytes<uint8_t>(40)};
337 if (witness_unknown_program_1.size() < 2) {
338 witness_unknown_program_1 = {0, 0};
339 }
340 witness_unknown.length = witness_unknown_program_1.size();
341 std::copy(witness_unknown_program_1.begin(), witness_unknown_program_1.end(), witness_unknown.program);
342 tx_destination = witness_unknown;
343 })};
344 Assert(call_size == std::variant_size_v<CTxDestination>);
345 return tx_destination;
346}
347
349{
350 // Avoid:
351 // policy/feerate.cpp:28:34: runtime error: signed integer overflow: 34873208148477500 * 1000 cannot be represented in type 'long'
352 //
353 // Reproduce using CFeeRate(348732081484775, 10).GetFeePerK()
354 const CAmount fee = std::min<CAmount>(ConsumeMoney(fuzzed_data_provider), std::numeric_limits<CAmount>::max() / static_cast<CAmount>(100000));
355 assert(MoneyRange(fee));
356 const int64_t time = fuzzed_data_provider.ConsumeIntegral<int64_t>();
357 const unsigned int entry_height = fuzzed_data_provider.ConsumeIntegral<unsigned int>();
358 const bool spends_coinbase = fuzzed_data_provider.ConsumeBool();
359 const unsigned int sig_op_cost = fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(0, MAX_BLOCK_SIGOPS_COST);
360 return CTxMemPoolEntry{MakeTransactionRef(tx), fee, time, entry_height, spends_coinbase, sig_op_cost, {}};
361}
362
363bool ContainsSpentInput(const CTransaction& tx, const CCoinsViewCache& inputs) noexcept
364{
365 for (const CTxIn& tx_in : tx.vin) {
366 const Coin& coin = inputs.AccessCoin(tx_in.prevout);
367 if (coin.IsSpent()) {
368 return true;
369 }
370 }
371 return false;
372}
373
374CNetAddr ConsumeNetAddr(FuzzedDataProvider& fuzzed_data_provider) noexcept
375{
376 const Network network = fuzzed_data_provider.PickValueInArray({Network::NET_IPV4, Network::NET_IPV6, Network::NET_INTERNAL, Network::NET_ONION});
377 CNetAddr net_addr;
378 if (network == Network::NET_IPV4) {
379 in_addr v4_addr = {};
380 v4_addr.s_addr = fuzzed_data_provider.ConsumeIntegral<uint32_t>();
381 net_addr = CNetAddr{v4_addr};
382 } else if (network == Network::NET_IPV6) {
383 if (fuzzed_data_provider.remaining_bytes() >= 16) {
384 in6_addr v6_addr = {};
385 memcpy(v6_addr.s6_addr, fuzzed_data_provider.ConsumeBytes<uint8_t>(16).data(), 16);
386 net_addr = CNetAddr{v6_addr, fuzzed_data_provider.ConsumeIntegral<uint32_t>()};
387 }
388 } else if (network == Network::NET_INTERNAL) {
389 net_addr.SetInternal(fuzzed_data_provider.ConsumeBytesAsString(32));
390 } else if (network == Network::NET_ONION) {
391 net_addr.SetSpecial(fuzzed_data_provider.ConsumeBytesAsString(32));
392 }
393 return net_addr;
394}
395
397{
400 return nullptr;
401 }
402 std::string mode;
403 CallOneOf(
405 [&] {
406 mode = "r";
407 },
408 [&] {
409 mode = "r+";
410 },
411 [&] {
412 mode = "w";
413 },
414 [&] {
415 mode = "w+";
416 },
417 [&] {
418 mode = "a";
419 },
420 [&] {
421 mode = "a+";
422 });
423#if defined _GNU_SOURCE && !defined __ANDROID__
424 const cookie_io_functions_t io_hooks = {
429 };
430 return fopencookie(this, mode.c_str(), io_hooks);
431#else
432 (void)mode;
433 return nullptr;
434#endif
435}
436
437ssize_t FuzzedFileProvider::read(void* cookie, char* buf, size_t size)
438{
439 FuzzedFileProvider* fuzzed_file = (FuzzedFileProvider*)cookie;
441 if (buf == nullptr || size == 0 || fuzzed_file->m_fuzzed_data_provider.ConsumeBool()) {
442 return fuzzed_file->m_fuzzed_data_provider.ConsumeBool() ? 0 : -1;
443 }
444 const std::vector<uint8_t> random_bytes = fuzzed_file->m_fuzzed_data_provider.ConsumeBytes<uint8_t>(size);
445 if (random_bytes.empty()) {
446 return 0;
447 }
448 std::memcpy(buf, random_bytes.data(), random_bytes.size());
449 if (AdditionOverflow(fuzzed_file->m_offset, (int64_t)random_bytes.size())) {
450 return fuzzed_file->m_fuzzed_data_provider.ConsumeBool() ? 0 : -1;
451 }
452 fuzzed_file->m_offset += random_bytes.size();
453 return random_bytes.size();
454}
455
456ssize_t FuzzedFileProvider::write(void* cookie, const char* buf, size_t size)
457{
458 FuzzedFileProvider* fuzzed_file = (FuzzedFileProvider*)cookie;
460 const ssize_t n = fuzzed_file->m_fuzzed_data_provider.ConsumeIntegralInRange<ssize_t>(0, size);
461 if (AdditionOverflow(fuzzed_file->m_offset, (int64_t)n)) {
462 return fuzzed_file->m_fuzzed_data_provider.ConsumeBool() ? 0 : -1;
463 }
464 fuzzed_file->m_offset += n;
465 return n;
466}
467
468int FuzzedFileProvider::seek(void* cookie, int64_t* offset, int whence)
469{
470 assert(whence == SEEK_SET || whence == SEEK_CUR || whence == SEEK_END);
471 FuzzedFileProvider* fuzzed_file = (FuzzedFileProvider*)cookie;
473 int64_t new_offset = 0;
474 if (whence == SEEK_SET) {
475 new_offset = *offset;
476 } else if (whence == SEEK_CUR) {
477 if (AdditionOverflow(fuzzed_file->m_offset, *offset)) {
478 return -1;
479 }
480 new_offset = fuzzed_file->m_offset + *offset;
481 } else if (whence == SEEK_END) {
482 const int64_t n = fuzzed_file->m_fuzzed_data_provider.ConsumeIntegralInRange<int64_t>(0, 4096);
483 if (AdditionOverflow(n, *offset)) {
484 return -1;
485 }
486 new_offset = n + *offset;
487 }
488 if (new_offset < 0) {
489 return -1;
490 }
491 fuzzed_file->m_offset = new_offset;
492 *offset = new_offset;
493 return fuzzed_file->m_fuzzed_data_provider.ConsumeIntegralInRange<int>(-1, 0);
494}
495
497{
498 FuzzedFileProvider* fuzzed_file = (FuzzedFileProvider*)cookie;
500 return fuzzed_file->m_fuzzed_data_provider.ConsumeIntegralInRange<int>(-1, 0);
501}
static constexpr CAmount MAX_MONEY
No amount larger than this (in satoshi) is valid.
Definition: amount.h:26
bool MoneyRange(const CAmount &nValue)
Definition: amount.h:27
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
static constexpr CAmount COIN
The amount of satoshis in one BTC.
Definition: amount.h:15
int flags
Definition: bitcoin-tx.cpp:525
#define Assert(val)
Identity function.
Definition: check.h:57
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:214
Network address.
Definition: netaddress.h:119
bool SetSpecial(const std::string &addr)
Parse a Tor or I2P address and set this object to it.
Definition: netaddress.cpp:212
bool SetInternal(const std::string &name)
Create an "internal" address that represents a name or FQDN.
Definition: netaddress.cpp:173
Information about a peer.
Definition: net.h:394
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:27
A hasher class for SHA-256.
Definition: sha256.h:14
void Finalize(unsigned char hash[OUTPUT_SIZE])
Definition: sha256.cpp:663
CSHA256 & Write(const unsigned char *data, size_t len)
Definition: sha256.cpp:637
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:406
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:260
static const int32_t CURRENT_VERSION
Definition: transaction.h:263
An input of a transaction.
Definition: transaction.h:66
uint32_t nSequence
Definition: transaction.h:70
static const uint32_t SEQUENCE_FINAL
Definition: transaction.h:75
CScript scriptSig
Definition: transaction.h:69
CScriptWitness scriptWitness
Only serialized through CTransaction.
Definition: transaction.h:71
COutPoint prevout
Definition: transaction.h:68
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
Definition: txmempool.h:80
A UTXO entry.
Definition: coins.h:31
bool IsSpent() const
Either this coin never existed (see e.g.
Definition: coins.h:79
std::vector< T > ConsumeBytes(size_t num_bytes)
T ConsumeIntegralInRange(T min, T max)
static ssize_t write(void *cookie, const char *buf, size_t size)
Definition: util.cpp:456
FuzzedDataProvider & m_fuzzed_data_provider
Definition: util.h:282
int64_t m_offset
Definition: util.h:283
static int seek(void *cookie, int64_t *offset, int whence)
Definition: util.cpp:468
static int close(void *cookie)
Definition: util.cpp:496
static ssize_t read(void *cookie, char *buf, size_t size)
Definition: util.cpp:437
FILE * open()
Definition: util.cpp:396
int GetSockOpt(int level, int opt_name, void *opt_val, socklen_t *opt_len) const override
getsockopt(2) wrapper.
Definition: util.cpp:158
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:177
bool IsConnected(std::string &errmsg) const override
Check if still connected.
Definition: util.cpp:194
int Connect(const sockaddr *, socklen_t) const override
connect(2) wrapper.
Definition: util.cpp:136
ssize_t Send(const void *data, size_t len, int flags) const override
send(2) wrapper.
Definition: util.cpp:39
FuzzedSock & operator=(Sock &&other) override
Move assignment operator, grab the socket from another object and close ours (if set).
Definition: util.cpp:28
std::optional< uint8_t > m_peek_data
Data to return when MSG_PEEK is used as a Recv() flag.
Definition: util.h:396
FuzzedDataProvider & m_fuzzed_data_provider
Definition: util.h:389
void Reset() override
Close if non-empty.
Definition: util.cpp:34
ssize_t Recv(void *buf, size_t len, int flags) const override
recv(2) wrapper.
Definition: util.cpp:71
~FuzzedSock() override
Definition: util.cpp:19
FuzzedSock(FuzzedDataProvider &fuzzed_data_provider)
Definition: util.cpp:13
RAII helper class that manages a socket.
Definition: sock.h:26
SOCKET m_socket
Contained socket.
Definition: sock.h:176
uint8_t Event
Definition: sock.h:109
unsigned char * begin()
Definition: uint256.h:58
iterator begin()
Definition: prevector.h:290
256-bit opaque blob.
Definition: uint256.h:124
#define INVALID_SOCKET
Definition: compat.h:53
unsigned int SOCKET
Definition: compat.h:41
static const int64_t MAX_BLOCK_SIGOPS_COST
The maximum allowed number of signature check operations in a block (network rule)
Definition: consensus.h:17
NetPermissionFlags
Network
A network type.
Definition: netaddress.h:45
@ NET_ONION
TOR (v2 or v3)
Definition: netaddress.h:56
@ NET_IPV6
IPv6.
Definition: netaddress.h:53
@ NET_IPV4
IPv4.
Definition: netaddress.h:50
@ NET_INTERNAL
A set of addresses that represent the hash of a string or FQDN.
Definition: netaddress.h:66
static CTransactionRef MakeTransactionRef(Tx &&txIn)
Definition: transaction.h:387
ServiceFlags
nServices flags
Definition: protocol.h:271
@ OP_0
Definition: script.h:69
std::vector< unsigned char > ToByteVector(const T &in)
Definition: script.h:60
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:157
A mutable version of CTransaction.
Definition: transaction.h:345
std::vector< CTxOut > vout
Definition: transaction.h:347
std::vector< CTxIn > vin
Definition: transaction.h:346
std::vector< std::vector< unsigned char > > stack
Definition: script.h:561
CTxDestination subtype to encode any future Witness version.
Definition: standard.h:126
unsigned int version
Definition: standard.h:127
#define LOCK(cs)
Definition: sync.h:226
uint32_t ConsumeSequence(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.cpp:299
int64_t ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
Definition: util.cpp:227
bool ContainsSpentInput(const CTransaction &tx, const CCoinsViewCache &inputs) noexcept
Definition: util.cpp:363
CScriptWitness ConsumeScriptWitness(FuzzedDataProvider &fuzzed_data_provider, const size_t max_stack_elem_size) noexcept
Definition: util.cpp:276
CNetAddr ConsumeNetAddr(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.cpp:374
CScript ConsumeScript(FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length, const bool maybe_p2wsh) noexcept
Definition: util.cpp:286
void FillNode(FuzzedDataProvider &fuzzed_data_provider, CNode &node, bool init_version) noexcept
Definition: util.cpp:203
CMutableTransaction ConsumeTransaction(FuzzedDataProvider &fuzzed_data_provider, const std::optional< std::vector< uint256 > > &prevout_txids, const int max_num_in, const int max_num_out) noexcept
Definition: util.cpp:235
CTxDestination ConsumeTxDestination(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.cpp:310
CAmount ConsumeMoney(FuzzedDataProvider &fuzzed_data_provider, const std::optional< CAmount > &max) noexcept
Definition: util.cpp:222
CTxMemPoolEntry ConsumeTxMemPoolEntry(FuzzedDataProvider &fuzzed_data_provider, const CTransaction &tx) noexcept
Definition: util.cpp:348
WeakEnumType ConsumeWeakEnum(FuzzedDataProvider &fuzzed_data_provider, const WeakEnumType(&all_types)[size]) noexcept
Definition: util.h:115
auto & PickValue(FuzzedDataProvider &fuzzed_data_provider, Collection &col)
Definition: util.h:52
uint256 ConsumeUInt256(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.h:153
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)
Definition: util.h:40
bool AdditionOverflow(const T i, const T j) noexcept
Definition: util.h:195
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
uint160 ConsumeUInt160(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.h:144
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
std::vector< uint8_t > ConsumeRandomLengthByteVector(FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt) noexcept
Definition: util.h:61
constexpr ServiceFlags ALL_SERVICE_FLAGS[]
Definition: net.h:47
constexpr NetPermissionFlags ALL_NET_PERMISSION_FLAGS[]
Definition: net.h:56
static const std::vector< uint8_t > WITNESS_STACK_ELEM_OP_TRUE
Definition: script.h:11
static const CScript P2WSH_OP_TRUE
Definition: script.h:12
int64_t ParseISO8601DateTime(const std::string &str)
Definition: time.cpp:158
static constexpr uint32_t MAX_BIP125_RBF_SEQUENCE
Definition: rbf.h:12
assert(!tx.IsCoinBase())
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:12
static const int MIN_PEER_PROTO_VERSION
disconnect from peers older than this proto version
Definition: version.h:18