diff options
author | practicalswift <practicalswift@users.noreply.github.com> | 2020-11-19 10:43:00 +0000 |
---|---|---|
committer | practicalswift <practicalswift@users.noreply.github.com> | 2020-11-19 17:21:55 +0000 |
commit | 17a5f172fa9ec509b1c3f950ee8dfb6f025534d2 (patch) | |
tree | 084e4fafaa6c1672c3f91d95c91b2d96f3e2ef01 /src/test | |
parent | 3457054c61d5b74800797e2c26a8126a21352382 (diff) | |
download | bitcoin-17a5f172fa9ec509b1c3f950ee8dfb6f025534d2.tar.xz |
fuzz: Make addrman fuzzing harness deterministic
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/fuzz/addrman.cpp | 14 | ||||
-rw-r--r-- | src/test/fuzz/util.h | 3 |
2 files changed, 14 insertions, 3 deletions
diff --git a/src/test/fuzz/addrman.cpp b/src/test/fuzz/addrman.cpp index 0ceeea2d36..ae595be742 100644 --- a/src/test/fuzz/addrman.cpp +++ b/src/test/fuzz/addrman.cpp @@ -22,12 +22,22 @@ void initialize() SelectParams(CBaseChainParams::REGTEST); } +class CAddrManDeterministic : public CAddrMan +{ +public: + void MakeDeterministic(const uint256& random_seed) + { + insecure_rand = FastRandomContext{random_seed}; + Clear(); + } +}; + void test_one_input(const std::vector<uint8_t>& buffer) { FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); - SetMockTime(ConsumeTime(fuzzed_data_provider)); - CAddrMan addr_man; + CAddrManDeterministic addr_man; + addr_man.MakeDeterministic(ConsumeUInt256(fuzzed_data_provider)); if (fuzzed_data_provider.ConsumeBool()) { addr_man.m_asmap = ConsumeRandomLengthBitVector(fuzzed_data_provider); if (!SanityCheckASMap(addr_man.m_asmap)) { diff --git a/src/test/fuzz/util.h b/src/test/fuzz/util.h index e99ed8d72d..452651d93f 100644 --- a/src/test/fuzz/util.h +++ b/src/test/fuzz/util.h @@ -98,7 +98,8 @@ NODISCARD inline CAmount ConsumeMoney(FuzzedDataProvider& fuzzed_data_provider) NODISCARD inline int64_t ConsumeTime(FuzzedDataProvider& fuzzed_data_provider) noexcept { - static const int64_t time_min = ParseISO8601DateTime("1970-01-01T00:00:00Z"); + // Avoid t=0 (1970-01-01T00:00:00Z) since SetMockTime(0) is a no-op. + static const int64_t time_min = ParseISO8601DateTime("1970-01-01T00:00:01Z"); static const int64_t time_max = ParseISO8601DateTime("9999-12-31T23:59:59Z"); return fuzzed_data_provider.ConsumeIntegralInRange<int64_t>(time_min, time_max); } |