Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
test
fuzz
blockfilter.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 <blockfilter.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
11
#include <cstdint>
12
#include <optional>
13
#include <string>
14
#include <vector>
15
16
FUZZ_TARGET
(blockfilter)
17
{
18
SeedRandomStateForTest
(
SeedRand::ZEROS
);
19
FuzzedDataProvider
fuzzed_data_provider(buffer.data(), buffer.size());
20
const
std::optional<BlockFilter> block_filter =
ConsumeDeserializable<BlockFilter>
(fuzzed_data_provider);
21
if
(!block_filter) {
22
return
;
23
}
24
{
25
(void)block_filter->ComputeHeader(
ConsumeUInt256
(fuzzed_data_provider));
26
(void)block_filter->GetBlockHash();
27
(void)block_filter->GetEncodedFilter();
28
(void)block_filter->GetHash();
29
}
30
{
31
const
BlockFilterType
block_filter_type = block_filter->GetFilterType();
32
(void)
BlockFilterTypeName
(block_filter_type);
33
}
34
{
35
const
GCSFilter
gcs_filter = block_filter->GetFilter();
36
(void)gcs_filter.
GetN
();
37
(void)gcs_filter.
GetParams
();
38
(void)gcs_filter.
GetEncoded
();
39
(void)gcs_filter.
Match
(
ConsumeRandomLengthByteVector
(fuzzed_data_provider));
40
GCSFilter::ElementSet
element_set;
41
LIMITED_WHILE
(fuzzed_data_provider.
ConsumeBool
(), 30000)
42
{
43
element_set.insert(
ConsumeRandomLengthByteVector
(fuzzed_data_provider));
44
}
45
gcs_filter.
MatchAny
(element_set);
46
}
47
}
FuzzedDataProvider.h
BlockFilterTypeName
const std::string & BlockFilterTypeName(BlockFilterType filter_type)
Get the human-readable name for a filter type.
Definition
blockfilter.cpp:148
BlockFilterType
BlockFilterType
Definition
blockfilter.h:94
FuzzedDataProvider
Definition
FuzzedDataProvider.h:32
FuzzedDataProvider::ConsumeBool
bool ConsumeBool()
Definition
FuzzedDataProvider.h:289
GCSFilter
This implements a Golomb-coded set as defined in BIP 158.
Definition
blockfilter.h:30
GCSFilter::ElementSet
std::unordered_set< Element, ByteVectorHash > ElementSet
Definition
blockfilter.h:33
GCSFilter::GetParams
const Params & GetParams() const LIFETIMEBOUND
Definition
blockfilter.h:73
GCSFilter::Match
bool Match(const Element &element) const
Checks if the element may be in the set.
Definition
blockfilter.cpp:136
GCSFilter::GetN
uint32_t GetN() const
Definition
blockfilter.h:72
GCSFilter::MatchAny
bool MatchAny(const ElementSet &elements) const
Checks if any of the given elements may be in the set.
Definition
blockfilter.cpp:142
GCSFilter::GetEncoded
const std::vector< unsigned char > & GetEncoded() const LIFETIMEBOUND
Definition
blockfilter.h:74
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
ConsumeRandomLengthByteVector
std::vector< B > ConsumeRandomLengthByteVector(FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt) noexcept
Definition
util.h:57
ConsumeDeserializable
std::optional< T > ConsumeDeserializable(FuzzedDataProvider &fuzzed_data_provider, const P ¶ms, const std::optional< size_t > &max_length=std::nullopt) noexcept
Definition
util.h:100
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
Generated on
for Bitcoin Core by
1.17.0