9#include <blockfilter.h>
45 static const auto testing_setup = MakeNoLogFileContext<>();
46 g_setup = testing_setup.get();
49#define FUZZ_TARGET_DESERIALIZE(name, code) \
50 FUZZ_TARGET(name, .init = initialize_deserialize) \
54 } catch (const invalid_fuzzing_input_exception&) { \
60struct invalid_fuzzing_input_exception :
public std::exception {
63template <
typename T,
typename P>
71template <
typename T,
typename P>
79template <
typename T,
typename P>
80void DeserializeFromFuzzingInput(
FuzzBufferType buffer,
T&& obj,
const P& params)
85 }
catch (
const std::ios_base::failure&) {
86 throw invalid_fuzzing_input_exception();
113 }
catch (
const std::ios_base::failure&) {
114 throw invalid_fuzzing_input_exception();
119template <
typename T,
typename P>
120void AssertEqualAfterSerializeDeserialize(
const T& obj,
const P& params)
125void AssertEqualAfterSerializeDeserialize(
const T& obj)
134 DeserializeFromFuzzingInput(buffer, block_filter);
139 (void)ConsumeDeserializable<AddrInfo>(fdp, ConsumeDeserializationParams<CAddress::SerParams>(fdp));
143 DeserializeFromFuzzingInput(buffer, block_file_info);
147 DeserializeFromFuzzingInput(buffer, block_header_and_short_txids);
151 DeserializeFromFuzzingInput(buffer, fee_rate);
152 AssertEqualAfterSerializeDeserialize(fee_rate);
156 DeserializeFromFuzzingInput(buffer, merkle_block);
160 DeserializeFromFuzzingInput(buffer, out_point);
161 AssertEqualAfterSerializeDeserialize(out_point);
165 DeserializeFromFuzzingInput(buffer, partial_merkle_tree);
169 DeserializeFromFuzzingInput(buffer, pub_key);
170 AssertEqualAfterSerializeDeserialize(pub_key);
174 DeserializeFromFuzzingInput(buffer,
script);
178 DeserializeFromFuzzingInput(buffer, tx_in);
179 AssertEqualAfterSerializeDeserialize(tx_in);
183 DeserializeFromFuzzingInput(buffer, flat_file_pos);
184 AssertEqualAfterSerializeDeserialize(flat_file_pos);
188 DeserializeFromFuzzingInput(buffer, key_origin_info);
189 AssertEqualAfterSerializeDeserialize(key_origin_info);
193 DeserializeFromFuzzingInput(buffer, partially_signed_transaction);
197 DeserializeFromFuzzingInput(buffer, prefilled_transaction);
201 DeserializeFromFuzzingInput(buffer, psbt_input);
205 DeserializeFromFuzzingInput(buffer, psbt_output);
213 DeserializeFromFuzzingInput(buffer, bl);
223 DeserializeFromFuzzingInput(buffer, bh);
227 DeserializeFromFuzzingInput(buffer, tu);
231 DeserializeFromFuzzingInput(buffer, bu);
235 DeserializeFromFuzzingInput(buffer, coin);
240 const auto maybe_na{ConsumeDeserializable<CNetAddr>(fdp, ConsumeDeserializationParams<CNetAddr::SerParams>(fdp))};
241 if (!maybe_na)
return;
243 if (na.IsAddrV1Compatible()) {
251 const auto ser_params{ConsumeDeserializationParams<CNetAddr::SerParams>(fdp)};
252 const auto maybe_s{ConsumeDeserializable<CService>(fdp, ser_params)};
253 if (!maybe_s)
return;
255 if (
s.IsAddrV1Compatible()) {
260 assert(
s.IsAddrV1Compatible());
265 DeserializeFromFuzzingInput(buffer, mh);
271 const auto ser_enc{ConsumeDeserializationParams<CAddress::SerParams>(fdp)};
272 const auto maybe_a{ConsumeDeserializable<CAddress>(fdp, ser_enc)};
273 if (!maybe_a)
return;
285 if (a.IsAddrV1Compatible()) {
295 DeserializeFromFuzzingInput(buffer, i);
299 DeserializeFromFuzzingInput(buffer, bf);
303 DeserializeFromFuzzingInput(buffer, dbi);
307 auto toc = Using<TxOutCompression>(to);
308 DeserializeFromFuzzingInput(buffer, toc);
312 DeserializeFromFuzzingInput(buffer, bt);
316 DeserializeFromFuzzingInput(buffer, btr);
321 DeserializeFromFuzzingInput(buffer, snapshot_metadata);
325 DeserializeFromFuzzingInput(buffer, u160);
326 AssertEqualAfterSerializeDeserialize(u160);
330 DeserializeFromFuzzingInput(buffer, u256);
331 AssertEqualAfterSerializeDeserialize(u256);
const CChainParams & Params()
Return the currently selected parameters.
Complete block filter struct as defined in BIP 157.
A CService with information about it as peer.
static constexpr SerParams V1_NETWORK
static constexpr SerParams V2_NETWORK
static constexpr SerParams V1_DISK
static constexpr SerParams V2_DISK
Undo information for a CBlock.
BloomFilter is a probabilistic filter which SPV clients provide so that we can filter the transaction...
const MessageStartChars & MessageStart() const
Used to marshal pointers into hashes for db storage.
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
Used to relay blocks as header + vector<merkle branch> to filtered nodes.
static constexpr SerParams V1
static constexpr SerParams V2
An outpoint - a combination of a transaction hash and an index n into its vout.
Data structure that represents a partial merkle tree.
An encapsulated public key.
Serialized script, used inside transaction inputs and outputs.
A combination of a network address (CNetAddr) and a (TCP) port.
An input of a transaction.
An output of a transaction.
Undo information for a CTransaction.
Double ended buffer combining vector and stream-like interfaces.
#define FUZZ_TARGET_DESERIALIZE(name, code)
void initialize_deserialize()
std::span< const uint8_t > FuzzBufferType
#define T(expected, seed, data)
uint256 BlockMerkleRoot(const CBlock &block, bool *mutated)
static constexpr TransactionSerParams TX_WITH_WITNESS
void Serialize(Stream &, V)=delete
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
A structure for PSBTs which contains per output information.
A version of CTransaction with the PSBT format.