From b539c3dc78a1dd6fd7106128d411ec0a9f047759 Mon Sep 17 00:00:00 2001 From: DCG-Claude Date: Wed, 23 Sep 2026 00:26:29 -0500 Subject: [PATCH 1/4] Merge bitcoin/bitcoin#27549: fuzz: addrman, add coverage for `network` field in `Select()`, `Size()` and `GetAddr()` 35a2175ad8bec92b409ae2202c124e39b2f3f838 fuzz: addrman, add coverage for `network` field in `Select()`, `Size()` and `GetAddr()` (brunoerg) Pull request description: This PR adds fuzz coverage for `network` field in `Select()`, `Size()` and `GetAddr()`, there was only call to them without passing a network. https://marcofalke.github.io/b-c-cov/fuzz.coverage/src/addrman.cpp.gcov.html ACKs for top commit: amitiuttarwar: for the record, ACK 35a2175ad8bec92b409ae2202c124e39b2f3f838 - only small changes from the version (previously) proposed in 27213 achow101: ACK 35a2175ad8bec92b409ae2202c124e39b2f3f838 mzumsande: Code Review ACK 35a2175ad8bec92b409ae2202c124e39b2f3f838, haven't tested this yet, but I will let the fuzzer run for a while now. Tree-SHA512: dddb8322298d6c373c8e68d57538470b11825a9a310a355828c351d5c0b19ff6779d024a800e3ea90126d0c050e86f71fd22cd23d1a306c784cef0f82c45e3ca Dash adaptations: - src/test/fuzz/addrman.cpp: Dash's AddrMan::GetAddr() takes an extra trailing `filtered` parameter not present upstream; upstream's `network` argument replaces `std::nullopt` in position 3 while the pre-existing `/*filtered=*/fuzzed_data_provider.ConsumeBool()` argument is retained (and its comment normalized to the `/*name=*/` style upstream uses on the lines it rewrote) --- src/test/fuzz/addrman.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/test/fuzz/addrman.cpp b/src/test/fuzz/addrman.cpp index 0a2295e3aacd..eddd958094bb 100644 --- a/src/test/fuzz/addrman.cpp +++ b/src/test/fuzz/addrman.cpp @@ -280,13 +280,21 @@ FUZZ_TARGET(addrman, .init = initialize_addrman) }); } const AddrMan& const_addr_man{addr_man}; + std::optional network; + if (fuzzed_data_provider.ConsumeBool()) { + network = fuzzed_data_provider.PickValueInArray(ALL_NETWORKS); + } (void)const_addr_man.GetAddr( - /* max_addresses */ fuzzed_data_provider.ConsumeIntegralInRange(0, 4096), - /* max_pct */ fuzzed_data_provider.ConsumeIntegralInRange(0, 4096), - /* network */ std::nullopt, - /* filtered =*/ fuzzed_data_provider.ConsumeBool()); - (void)const_addr_man.Select(fuzzed_data_provider.ConsumeBool()); - (void)const_addr_man.Size(); + /*max_addresses=*/fuzzed_data_provider.ConsumeIntegralInRange(0, 4096), + /*max_pct=*/fuzzed_data_provider.ConsumeIntegralInRange(0, 4096), + network, + /*filtered=*/fuzzed_data_provider.ConsumeBool()); + (void)const_addr_man.Select(fuzzed_data_provider.ConsumeBool(), network); + std::optional in_new; + if (fuzzed_data_provider.ConsumeBool()) { + in_new = fuzzed_data_provider.ConsumeBool(); + } + (void)const_addr_man.Size(network, in_new); CDataStream data_stream(SER_NETWORK, PROTOCOL_VERSION); data_stream << const_addr_man; } From 98b9304452663f36a509b7dd9aa57df13f347797 Mon Sep 17 00:00:00 2001 From: DCG-Claude Date: Wed, 23 Sep 2026 00:26:29 -0500 Subject: [PATCH 2/4] Merge bitcoin/bitcoin#27425: test: move remaining rand code from util/setup_common to util/random MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1cd45d4e08c3dfd1d6423620c79169f1404ac12b test: move random.h include header from setup_common.h to cpp (Jon Atack) 1b246fdd145a95f5da479159f5e8eaf5a76bdc3a test: move remaining random test util code from setup_common to random (jonatack) Pull request description: and drop the `util/random` dependency on `util/setup_common`. This improves code separation and allows `util/setup_common` to call `util/random` functions without creating a circular dependency, thereby addressing https://github.com/bitcoin/bitcoin/pull/26940#issuecomment-1497266140 by glozow (thanks!) ACKs for top commit: MarcoFalke: lgtm ACK 1cd45d4e08c3dfd1d6423620c79169f1404ac12b 🌂 Tree-SHA512: 6ce63d9103ba9b04eebbd8ad02fe9aa79e356296533404034a1ae88e9b7ca0bc9a5c51fd754b71cf4e7b55b18bcd4d5474b2d588edee3851e3b3ce0e4d309a93 Dash adaptations: - src/test/util/setup_common.h: upstream's hunk 1 context includes `#include ` + `#include ` right after pubkey.h; Dash has no util/chaintype.h and already lists in the C++-stdlib include block below, so only the intended `#include ` removal was applied - src/test/util/setup_common.h: Dash's thread-safety doc comment on g_insecure_rand_ctx was a trimmed variant (no thread_local sentence); the moved copy now in test/util/random.h carries upstream's full wording, matching upstream's post-move state - src/test/net_peer_connection_tests.cpp: added `#include ` — uses g_insecure_rand_ctx and got the declaration via setup_common.h; upstream's tree didn't need it at this commit because its /setup_common.h include graph differed - src/wallet/test/platformkeys_tests.cpp: Dash-only test using g_insecure_rand_ctx.rand256(); added `#include ` since setup_common.h no longer declares it Replayed onto a newer base. Dash adaptations: - src/wallet/test/wallet_tests.cpp: kept the Dash-only #include that the new base added at the same line upstream inserts ; both retained in alphabetical order - src/test/net_peer_connection_tests.cpp: Dash-only call site not in the upstream commit; uses g_insecure_rand_ctx via setup_common.h, so it needs the new include - src/wallet/test/platformkeys_tests.cpp: Dash-only test file using InsecureRand helpers; given the same include upstream added to its equivalents - src/test/util/setup_common.h: Dash's copy of the g_insecure_rand_ctx doc comment had shorter wording than upstream's; the block moved to test/util/random.h uses upstream's full wording, matching the upstream destination text - src/Makefile.test_util.include: test/util/random.cpp inserted after test/util/net.cpp, which in Dash follows the Dash-only test/util/masternode.cpp entry --- src/Makefile.test_util.include | 1 + src/test/denialofservice_tests.cpp | 1 + src/test/miniscript_tests.cpp | 1 + src/test/net_peer_connection_tests.cpp | 1 + src/test/random_tests.cpp | 1 + src/test/util/random.cpp | 33 ++++++++++++++++++++++++++ src/test/util/random.h | 32 ++++++++++++++++++++++++- src/test/util/setup_common.cpp | 22 ++--------------- src/test/util/setup_common.h | 32 +------------------------ src/wallet/test/platformkeys_tests.cpp | 1 + src/wallet/test/wallet_tests.cpp | 1 + 11 files changed, 74 insertions(+), 52 deletions(-) create mode 100644 src/test/util/random.cpp diff --git a/src/Makefile.test_util.include b/src/Makefile.test_util.include index b6441a1e3e15..91a9ca2788dc 100644 --- a/src/Makefile.test_util.include +++ b/src/Makefile.test_util.include @@ -43,6 +43,7 @@ libtest_util_a_SOURCES = \ test/util/masternode.cpp \ test/util/mining.cpp \ test/util/net.cpp \ + test/util/random.cpp \ test/util/script.cpp \ test/util/setup_common.cpp \ test/util/str.cpp \ diff --git a/src/test/denialofservice_tests.cpp b/src/test/denialofservice_tests.cpp index 4806bb2ec801..9286528571f1 100644 --- a/src/test/denialofservice_tests.cpp +++ b/src/test/denialofservice_tests.cpp @@ -13,6 +13,7 @@ #include