Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
test
fuzz
rolling_bloom_filter.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 <
common/bloom.h
>
6
#include <
test/fuzz/FuzzedDataProvider.h
>
7
#include <
test/fuzz/fuzz.h
>
8
#include <
test/fuzz/util.h
>
9
#include <
test/util/random.h
>
10
#include <
uint256.h
>
11
12
#include <cassert>
13
#include <cstdint>
14
#include <optional>
15
#include <string>
16
#include <vector>
17
18
FUZZ_TARGET
(rolling_bloom_filter)
19
{
20
SeedRandomStateForTest
(
SeedRand::ZEROS
);
21
FuzzedDataProvider
fuzzed_data_provider(buffer.data(), buffer.size());
22
23
CRollingBloomFilter
rolling_bloom_filter{
24
fuzzed_data_provider.
ConsumeIntegralInRange
<
unsigned
int
>(1, 1000),
25
0.999 / fuzzed_data_provider.
ConsumeIntegralInRange
<
unsigned
int
>(1, std::numeric_limits<unsigned int>::max())};
26
LIMITED_WHILE
(fuzzed_data_provider.
remaining_bytes
() > 0, 3000)
27
{
28
CallOneOf
(
29
fuzzed_data_provider,
30
[&] {
31
const
std::vector<unsigned char> b =
ConsumeRandomLengthByteVector
(fuzzed_data_provider);
32
(void)rolling_bloom_filter.
contains
(b);
33
rolling_bloom_filter.
insert
(b);
34
const
bool
present = rolling_bloom_filter.
contains
(b);
35
assert
(present);
36
},
37
[&] {
38
const
uint256
u256{
ConsumeUInt256
(fuzzed_data_provider)};
39
(void)rolling_bloom_filter.
contains
(u256);
40
rolling_bloom_filter.
insert
(u256);
41
const
bool
present = rolling_bloom_filter.
contains
(u256);
42
assert
(present);
43
},
44
[&] {
45
rolling_bloom_filter.
reset
();
46
});
47
}
48
}
FuzzedDataProvider.h
bloom.h
CRollingBloomFilter
RollingBloomFilter is a probabilistic "keep track of most recently inserted" set.
Definition
bloom.h:109
CRollingBloomFilter::contains
bool contains(std::span< const unsigned char > vKey) const
Definition
bloom.cpp:226
CRollingBloomFilter::reset
void reset()
Definition
bloom.cpp:240
CRollingBloomFilter::insert
void insert(std::span< const unsigned char > vKey)
Definition
bloom.cpp:195
FuzzedDataProvider
Definition
FuzzedDataProvider.h:32
FuzzedDataProvider::remaining_bytes
size_t remaining_bytes()
Definition
FuzzedDataProvider.h:85
FuzzedDataProvider::ConsumeIntegralInRange
T ConsumeIntegralInRange(T min, T max)
Definition
FuzzedDataProvider.h:205
uint256
256-bit opaque blob.
Definition
uint256.h:195
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
util.h
ConsumeUInt256
uint256 ConsumeUInt256(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition
util.h:167
CallOneOf
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)
Definition
util.h:35
ConsumeRandomLengthByteVector
std::vector< B > ConsumeRandomLengthByteVector(FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt) noexcept
Definition
util.h:57
SeedRandomStateForTest
void SeedRandomStateForTest(SeedRand seedtype)
Seed the global RNG state for testing and log the seed value.
Definition
random.cpp:19
random.h
SeedRand::ZEROS
@ ZEROS
Seed with a compile time constant of zeros.
Definition
random.h:19
uint256.h
assert
assert(!tx.IsCoinBase())
Generated on
for Bitcoin Core by
1.17.0