Merge bitcoin/bitcoin#28470: fuzz: Rework addr fuzzing

fad52baf1e fuzz: Rework addr fuzzing (MarcoFalke)
fa5b6d29ee fuzz: Drop unused params from serialize helpers (MarcoFalke)

Pull request description:

  Some minor fixups to addr fuzzing

ACKs for top commit:
  dergoegge:
    utACK fad52baf1e

Tree-SHA512: 6a2b07fb1a65cf855d5e7c0a52bfcb81d46dbc5d4b3e72cef359987cbd28dbfeb2fc54f210e9737cb131b40ac5f88a90e9af284e441e0b37196121590bbaf015
pull/28515/head
fanquake 1 year ago
commit 1bf915db99
No known key found for this signature in database
GPG Key ID: 2EEB9F5CC09526C1

@ -91,9 +91,9 @@ void DeserializeFromFuzzingInput(FuzzBufferType buffer, T&& obj, const P& params
}
template <typename T>
CDataStream Serialize(const T& obj, const int version = INIT_PROTO_VERSION, const int ser_type = SER_NETWORK)
CDataStream Serialize(const T& obj)
{
CDataStream ds(ser_type, version);
CDataStream ds{SER_NETWORK, INIT_PROTO_VERSION};
ds << obj;
return ds;
}
@ -107,12 +107,10 @@ T Deserialize(CDataStream ds)
}
template <typename T>
void DeserializeFromFuzzingInput(FuzzBufferType buffer, T&& obj, const std::optional<int> protocol_version = std::nullopt, const int ser_type = SER_NETWORK)
void DeserializeFromFuzzingInput(FuzzBufferType buffer, T&& obj)
{
CDataStream ds(buffer, ser_type, INIT_PROTO_VERSION);
if (protocol_version) {
ds.SetVersion(*protocol_version);
} else {
CDataStream ds{buffer, SER_NETWORK, INIT_PROTO_VERSION};
{
try {
int version;
ds >> version;
@ -135,9 +133,9 @@ void AssertEqualAfterSerializeDeserialize(const T& obj, const P& params)
assert(Deserialize<T>(Serialize(obj, params), params) == obj);
}
template <typename T>
void AssertEqualAfterSerializeDeserialize(const T& obj, const int version = INIT_PROTO_VERSION, const int ser_type = SER_NETWORK)
void AssertEqualAfterSerializeDeserialize(const T& obj)
{
assert(Deserialize<T>(Serialize(obj, version, ser_type)) == obj);
assert(Deserialize<T>(Serialize(obj)) == obj);
}
} // namespace
@ -254,7 +252,7 @@ FUZZ_TARGET(netaddr_deserialize, .init = initialize_deserialize)
if (!maybe_na) return;
const CNetAddr& na{*maybe_na};
if (na.IsAddrV1Compatible()) {
AssertEqualAfterSerializeDeserialize(na, ConsumeDeserializationParams<CNetAddr::SerParams>(fdp));
AssertEqualAfterSerializeDeserialize(na, CNetAddr::V1);
}
AssertEqualAfterSerializeDeserialize(na, CNetAddr::V2);
}
@ -266,7 +264,7 @@ FUZZ_TARGET(service_deserialize, .init = initialize_deserialize)
if (!maybe_s) return;
const CService& s{*maybe_s};
if (s.IsAddrV1Compatible()) {
AssertEqualAfterSerializeDeserialize(s, ConsumeDeserializationParams<CNetAddr::SerParams>(fdp));
AssertEqualAfterSerializeDeserialize(s, CNetAddr::V1);
}
AssertEqualAfterSerializeDeserialize(s, CNetAddr::V2);
if (ser_params.enc == CNetAddr::Encoding::V1) {
@ -281,8 +279,8 @@ FUZZ_TARGET_DESERIALIZE(messageheader_deserialize, {
FUZZ_TARGET(address_deserialize, .init = initialize_deserialize)
{
FuzzedDataProvider fdp{buffer.data(), buffer.size()};
const auto ser_enc{ConsumeDeserializationParams<CNetAddr::SerParams>(fdp)};
const auto maybe_a{ConsumeDeserializable<CAddress>(fdp, CAddress::SerParams{{ser_enc}, CAddress::Format::Network})};
const auto ser_enc{ConsumeDeserializationParams<CAddress::SerParams>(fdp)};
const auto maybe_a{ConsumeDeserializable<CAddress>(fdp, ser_enc)};
if (!maybe_a) return;
const CAddress& a{*maybe_a};
// A CAddress in V1 mode will roundtrip

Loading…
Cancel
Save