aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2020-12-01 14:04:06 +0100
committerMarcoFalke <falke.marco@gmail.com>2020-12-01 14:04:10 +0100
commitdfd0b700886cab7cd2fcf4958a214b098fe18152 (patch)
tree14fb85bfd40d0b6695ef9d3deeca62782fa5b3d4 /src/test
parent277c225b842168c132e4ca1efe360f811dade5d3 (diff)
parent17a5f172fa9ec509b1c3f950ee8dfb6f025534d2 (diff)
Merge #20425: fuzz: Make CAddrMan fuzzing harness deterministic
17a5f172fa9ec509b1c3f950ee8dfb6f025534d2 fuzz: Make addrman fuzzing harness deterministic (practicalswift) Pull request description: Make `CAddrMan` fuzzing harness deterministic. See [`doc/fuzzing.md`](https://github.com/bitcoin/bitcoin/blob/master/doc/fuzzing.md) for information on how to fuzz Bitcoin Core. Don't forget to contribute any coverage increasing inputs you find to the [Bitcoin Core fuzzing corpus repo](https://github.com/bitcoin-core/qa-assets). Happy fuzzing :) ACKs for top commit: Crypt-iQ: utACK 17a5f172fa9ec509b1c3f950ee8dfb6f025534d2 Tree-SHA512: 725f983745233e9b616782247fa18847e483c074ca4336a5beea8a9009128c3a74b4d50a12662d8ca2177c2e1fc5fc121834df6b459ac0af43c931d77ef7c4d8
Diffstat (limited to 'src/test')
-rw-r--r--src/test/fuzz/addrman.cpp14
-rw-r--r--src/test/fuzz/util.h3
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 37e136dbb3..cf666a8b93 100644
--- a/src/test/fuzz/util.h
+++ b/src/test/fuzz/util.h
@@ -98,7 +98,8 @@ template <typename T>
[[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);
}