Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
test
fuzz
block_header.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 <
primitives/block.h
>
6
#include <
test/fuzz/FuzzedDataProvider.h
>
7
#include <
test/fuzz/fuzz.h
>
8
#include <
test/fuzz/util.h
>
9
#include <
uint256.h
>
10
11
#include <cassert>
12
#include <cstdint>
13
#include <optional>
14
#include <string>
15
#include <vector>
16
17
FUZZ_TARGET
(block_header)
18
{
19
FuzzedDataProvider
fuzzed_data_provider(buffer.data(), buffer.size());
20
const
std::optional<CBlockHeader> block_header =
ConsumeDeserializable<CBlockHeader>
(fuzzed_data_provider);
21
if
(!block_header) {
22
return
;
23
}
24
{
25
const
uint256
hash = block_header->GetHash();
26
constexpr
uint256
u256_max{
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
};
27
assert
(hash != u256_max);
28
assert
(block_header->GetBlockTime() == block_header->nTime);
29
assert
(block_header->IsNull() == (block_header->nBits == 0));
30
}
31
{
32
CBlockHeader
mut_block_header = *block_header;
33
mut_block_header.
SetNull
();
34
assert
(mut_block_header.
IsNull
());
35
CBlock
block{*block_header};
36
assert
(block.
GetHash
() == block_header->GetHash());
37
(void)block.
ToString
();
38
block.
SetNull
();
39
assert
(block.
GetHash
() == mut_block_header.
GetHash
());
40
}
41
{
42
std::optional<CBlockLocator> block_locator =
ConsumeDeserializable<CBlockLocator>
(fuzzed_data_provider);
43
if
(block_locator) {
44
(void)block_locator->IsNull();
45
block_locator->SetNull();
46
assert
(block_locator->IsNull());
47
}
48
}
49
}
FuzzedDataProvider.h
block.h
CBlockHeader
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition
block.h:27
CBlockHeader::SetNull
void SetNull()
Definition
block.h:44
CBlockHeader::GetHash
uint256 GetHash() const
Definition
block.cpp:15
CBlockHeader::IsNull
bool IsNull() const
Definition
block.h:54
CBlock
Definition
block.h:74
CBlock::SetNull
void SetNull()
Definition
block.h:100
CBlock::ToString
std::string ToString() const
Definition
block.cpp:20
FuzzedDataProvider
Definition
FuzzedDataProvider.h:32
uint256
256-bit opaque blob.
Definition
uint256.h:195
fuzz.h
FUZZ_TARGET
#define FUZZ_TARGET(...)
Definition
fuzz.h:35
util.h
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
uint256.h
assert
assert(!tx.IsCoinBase())
Generated on
for Bitcoin Core by
1.17.0