Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
test
fuzz
cuckoocache.cpp
Go to the documentation of this file.
1
// Copyright (c) 2020-present 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
>
7
#include <
test/fuzz/FuzzedDataProvider.h
>
8
#include <
test/fuzz/fuzz.h
>
9
#include <
test/fuzz/util.h
>
10
#include <
test/util/setup_common.h
>
11
#include <
util/byte_units.h
>
12
13
#include <cstdint>
14
#include <string>
15
#include <vector>
16
17
namespace
{
18
FuzzedDataProvider
* fuzzed_data_provider_ptr =
nullptr
;
19
20
struct
RandomHasher {
21
template
<u
int
8_t>
22
uint32_t operator()(
const
bool
&
/* unused */
)
const
23
{
24
assert
(fuzzed_data_provider_ptr !=
nullptr
);
25
return
fuzzed_data_provider_ptr->
ConsumeIntegral
<uint32_t>();
26
}
27
};
28
}
// namespace
29
30
FUZZ_TARGET
(cuckoocache)
31
{
32
FuzzedDataProvider
fuzzed_data_provider(buffer.data(), buffer.size());
33
fuzzed_data_provider_ptr = &fuzzed_data_provider;
34
CuckooCache::cache<int, RandomHasher>
cuckoo_cache{};
35
if
(fuzzed_data_provider.
ConsumeBool
()) {
36
const
size_t
megabytes = fuzzed_data_provider.
ConsumeIntegralInRange
<
size_t
>(0, 16);
37
cuckoo_cache.
setup_bytes
(megabytes * 1_MiB);
38
}
else
{
39
cuckoo_cache.
setup
(fuzzed_data_provider.
ConsumeIntegralInRange
<uint32_t>(0, 4096));
40
}
41
LIMITED_WHILE
(fuzzed_data_provider.
ConsumeBool
(), 10000) {
42
if
(fuzzed_data_provider.
ConsumeBool
()) {
43
cuckoo_cache.
insert
(fuzzed_data_provider.
ConsumeBool
());
44
}
else
{
45
auto
e = fuzzed_data_provider.
ConsumeBool
();
46
auto
erase = fuzzed_data_provider.
ConsumeBool
();
47
cuckoo_cache.
contains
(e, erase);
48
}
49
}
50
fuzzed_data_provider_ptr =
nullptr
;
51
}
FuzzedDataProvider.h
byte_units.h
CuckooCache::cache
cache implements a cache with properties similar to a cuckoo-set.
Definition
cuckoocache.h:163
CuckooCache::cache::setup_bytes
std::pair< uint32_t, size_t > setup_bytes(size_t bytes)
setup_bytes is a convenience function which accounts for internal memory usage when deciding how many...
Definition
cuckoocache.h:365
CuckooCache::cache::setup
uint32_t setup(uint32_t new_size)
setup initializes the container to store no more than new_size elements and no less than 2 elements.
Definition
cuckoocache.h:337
CuckooCache::cache::insert
void insert(Element e)
insert loops at most depth_limit times trying to insert a hash at various locations in the table via ...
Definition
cuckoocache.h:398
CuckooCache::cache::contains
bool contains(const Element &e, const bool erase) const
contains iterates through the hash locations for a given element and checks to see if it is present.
Definition
cuckoocache.h:475
FuzzedDataProvider
Definition
FuzzedDataProvider.h:32
FuzzedDataProvider::ConsumeBool
bool ConsumeBool()
Definition
FuzzedDataProvider.h:289
FuzzedDataProvider::ConsumeIntegralInRange
T ConsumeIntegralInRange(T min, T max)
Definition
FuzzedDataProvider.h:205
FuzzedDataProvider::ConsumeIntegral
T ConsumeIntegral()
Definition
FuzzedDataProvider.h:195
cuckoocache.h
fuzz.h
FUZZ_TARGET
#define FUZZ_TARGET(...)
Definition
fuzz.h:35
LIMITED_WHILE
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
Definition
fuzz.h:22
setup_common.h
sigcache.h
util.h
assert
assert(!tx.IsCoinBase())
Generated on
for Bitcoin Core by
1.18.0