Bitcoin Core  22.99.0
P2P Digital Currency
cuckoocache.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <cuckoocache.h>
6 #include <script/sigcache.h>
8 #include <test/fuzz/fuzz.h>
9 #include <test/fuzz/util.h>
10 #include <test/util/setup_common.h>
11 
12 #include <cstdint>
13 #include <string>
14 #include <vector>
15 
16 namespace {
17 FuzzedDataProvider* fuzzed_data_provider_ptr = nullptr;
18 
19 struct RandomHasher {
20  template <uint8_t>
21  uint32_t operator()(const bool& /* unused */) const
22  {
23  assert(fuzzed_data_provider_ptr != nullptr);
24  return fuzzed_data_provider_ptr->ConsumeIntegral<uint32_t>();
25  }
26 };
27 } // namespace
28 
29 FUZZ_TARGET(cuckoocache)
30 {
31  FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
32  fuzzed_data_provider_ptr = &fuzzed_data_provider;
34  if (fuzzed_data_provider.ConsumeBool()) {
35  const size_t megabytes = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 16);
36  cuckoo_cache.setup_bytes(megabytes << 20);
37  } else {
38  cuckoo_cache.setup(fuzzed_data_provider.ConsumeIntegralInRange<uint32_t>(0, 4096));
39  }
40  while (fuzzed_data_provider.ConsumeBool()) {
41  if (fuzzed_data_provider.ConsumeBool()) {
42  cuckoo_cache.insert(fuzzed_data_provider.ConsumeBool());
43  } else {
44  cuckoo_cache.contains(fuzzed_data_provider.ConsumeBool(), fuzzed_data_provider.ConsumeBool());
45  }
46  }
47  fuzzed_data_provider_ptr = nullptr;
48 }
assert
assert(!tx.IsCoinBase())
CuckooCache::cache
cache implements a cache with properties similar to a cuckoo-set.
Definition: cuckoocache.h:158
setup_common.h
util.h
cuckoocache.h
FuzzedDataProvider.h
fuzz.h
FuzzedDataProvider
Definition: FuzzedDataProvider.h:31
FuzzedDataProvider::ConsumeIntegral
T ConsumeIntegral()
Definition: FuzzedDataProvider.h:194
sigcache.h
FUZZ_TARGET
FUZZ_TARGET(cuckoocache)
Definition: cuckoocache.cpp:29
FuzzedDataProvider::ConsumeBool
bool ConsumeBool()
Definition: FuzzedDataProvider.h:288
FuzzedDataProvider::ConsumeIntegralInRange
T ConsumeIntegralInRange(T min, T max)
Definition: FuzzedDataProvider.h:204