From fa11eea4059a608f591db4469c07a341fd33a031 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Fri, 27 Jun 2025 17:29:29 +0200 Subject: [PATCH] fuzz: Avoid non-determinism in process_message(s) target (PeerMan) The PeerManager has several members, such as the FastRandomContext, which need to be reset before every run to avoid leaking state from one run into the next. Also, style fixups in p2p_handshake.cpp, where this code is copied from. --- src/test/fuzz/p2p_handshake.cpp | 4 ++-- src/test/fuzz/process_message.cpp | 21 ++++++++++++++++++--- src/test/fuzz/process_messages.cpp | 21 ++++++++++++++++++--- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/test/fuzz/p2p_handshake.cpp b/src/test/fuzz/p2p_handshake.cpp index d608efd87ac..aec7387eb2f 100644 --- a/src/test/fuzz/p2p_handshake.cpp +++ b/src/test/fuzz/p2p_handshake.cpp @@ -42,14 +42,14 @@ FUZZ_TARGET(p2p_handshake, .init = ::initialize) SeedRandomStateForTest(SeedRand::ZEROS); FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); - ConnmanTestMsg& connman = static_cast(*g_setup->m_node.connman); + auto& connman = static_cast(*g_setup->m_node.connman); auto& chainman = static_cast(*g_setup->m_node.chainman); SetMockTime(1610000000); // any time to successfully reset ibd chainman.ResetIbd(); node::Warnings warnings{}; NetGroupManager netgroupman{{}}; - AddrMan addrman{netgroupman, /*deterministic=*/true, 0}; + AddrMan addrman{netgroupman, /*deterministic=*/true, /*consistency_check_ratio=*/0}; auto peerman = PeerManager::make(connman, addrman, /*banman=*/nullptr, chainman, *g_setup->m_node.mempool, warnings, diff --git a/src/test/fuzz/process_message.cpp b/src/test/fuzz/process_message.cpp index ac521370e8e..05a28b2e6f8 100644 --- a/src/test/fuzz/process_message.cpp +++ b/src/test/fuzz/process_message.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include