Bitcoin Core
31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
src
test
fuzz
chain.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 <chain.h>
6
#include <
test/fuzz/FuzzedDataProvider.h
>
7
#include <
test/fuzz/fuzz.h
>
8
#include <
test/fuzz/util.h
>
9
10
#include <cstdint>
11
#include <optional>
12
#include <vector>
13
14
FUZZ_TARGET
(chain)
15
{
16
FuzzedDataProvider
fuzzed_data_provider
(buffer.data(), buffer.size());
17
std::optional<CDiskBlockIndex>
disk_block_index
=
ConsumeDeserializable<CDiskBlockIndex>
(
fuzzed_data_provider
);
18
if
(!
disk_block_index
) {
19
return
;
20
}
21
22
const
uint256
zero
{};
23
disk_block_index
->phashBlock = &
zero
;
24
{
25
LOCK
(
::cs_main
);
26
(
void
)
disk_block_index
->ConstructBlockHash();
27
(
void
)
disk_block_index
->GetBlockPos();
28
(
void
)
disk_block_index
->GetBlockTime();
29
(
void
)
disk_block_index
->GetBlockTimeMax();
30
(
void
)
disk_block_index
->GetMedianTimePast();
31
(
void
)
disk_block_index
->GetUndoPos();
32
(
void
)
disk_block_index
->HaveNumChainTxs();
33
(
void
)
disk_block_index
->IsValid(
BLOCK_VALID_TRANSACTIONS
);
34
}
35
36
const
CBlockHeader
block_header
=
disk_block_index
->GetBlockHeader();
37
(
void
)
CDiskBlockIndex
{*
disk_block_index
};
38
(
void
)
disk_block_index
->
BuildSkip
();
39
40
LIMITED_WHILE
(
fuzzed_data_provider
.
ConsumeBool
(), 10000) {
41
const
BlockStatus
block_status
=
fuzzed_data_provider
.
PickValueInArray
({
42
BlockStatus::BLOCK_VALID_UNKNOWN
,
43
BlockStatus::BLOCK_VALID_RESERVED
,
44
BlockStatus::BLOCK_VALID_TREE
,
45
BlockStatus::BLOCK_VALID_TRANSACTIONS
,
46
BlockStatus::BLOCK_VALID_CHAIN
,
47
BlockStatus::BLOCK_VALID_SCRIPTS
,
48
BlockStatus::BLOCK_VALID_MASK
,
49
BlockStatus::BLOCK_HAVE_DATA
,
50
BlockStatus::BLOCK_HAVE_UNDO
,
51
BlockStatus::BLOCK_HAVE_MASK
,
52
BlockStatus::BLOCK_FAILED_VALID
,
53
BlockStatus::BLOCK_OPT_WITNESS
,
54
});
55
if
(
block_status
& ~
BLOCK_VALID_MASK
) {
56
continue
;
57
}
58
WITH_LOCK
(
::cs_main
, (
void
)
disk_block_index
->RaiseValidity(
block_status
));
59
}
60
61
CBlockIndex
block_index
{
block_header
};
62
block_index
.
phashBlock
= &
zero
;
63
(
void
)
block_index
.GetBlockHash();
64
(
void
)
block_index
.
ToString
();
65
}
FuzzedDataProvider.h
BlockStatus
BlockStatus
Definition
chain.h:42
BLOCK_VALID_CHAIN
@ BLOCK_VALID_CHAIN
Outputs do not overspend inputs, no double spends, coinbase output ok, no immature coinbase spends,...
Definition
chain.h:65
BLOCK_VALID_MASK
@ BLOCK_VALID_MASK
All validity bits.
Definition
chain.h:72
BLOCK_VALID_TRANSACTIONS
@ BLOCK_VALID_TRANSACTIONS
Only first tx is coinbase, 2 <= coinbase input script length <= 100, transactions valid,...
Definition
chain.h:61
BLOCK_VALID_SCRIPTS
@ BLOCK_VALID_SCRIPTS
Scripts & signatures ok.
Definition
chain.h:69
BLOCK_VALID_RESERVED
@ BLOCK_VALID_RESERVED
Reserved (was BLOCK_VALID_HEADER).
Definition
chain.h:47
BLOCK_VALID_TREE
@ BLOCK_VALID_TREE
All parent headers found, difficulty matches, timestamp >= median previous.
Definition
chain.h:51
BLOCK_HAVE_UNDO
@ BLOCK_HAVE_UNDO
undo data available in rev*.dat
Definition
chain.h:76
BLOCK_HAVE_DATA
@ BLOCK_HAVE_DATA
full block available in blk*.dat
Definition
chain.h:75
BLOCK_FAILED_VALID
@ BLOCK_FAILED_VALID
stage after last reached validness failed
Definition
chain.h:79
BLOCK_OPT_WITNESS
@ BLOCK_OPT_WITNESS
block data in blk*.dat was received with a witness-enforcing client
Definition
chain.h:82
BLOCK_HAVE_MASK
@ BLOCK_HAVE_MASK
Definition
chain.h:77
BLOCK_VALID_UNKNOWN
@ BLOCK_VALID_UNKNOWN
Unused.
Definition
chain.h:44
CBlockHeader
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition
block.h:27
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition
chain.h:94
CBlockIndex::BuildSkip
void BuildSkip()
Build the skiplist pointer for this entry.
Definition
chain.cpp:115
CBlockIndex::phashBlock
const uint256 * phashBlock
pointer to the hash of the block, if any. Memory is owned by this CBlockIndex
Definition
chain.h:97
CDiskBlockIndex
Used to marshal pointers into hashes for db storage.
Definition
chain.h:318
FuzzedDataProvider
Definition
FuzzedDataProvider.h:32
FuzzedDataProvider::ConsumeBool
bool ConsumeBool()
Definition
FuzzedDataProvider.h:289
FuzzedDataProvider::PickValueInArray
T PickValueInArray(const T(&array)[size])
Definition
FuzzedDataProvider.h:304
base_blob::ToString
std::string ToString() const
Definition
uint256.cpp:21
uint256
256-bit opaque blob.
Definition
uint256.h:195
cs_main
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition
cs_main.cpp:8
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
LOCK
#define LOCK(cs)
Definition
sync.h:258
WITH_LOCK
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition
sync.h:289
util.h
Ticks
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition
time.h:73
fuzzed_data_provider
FuzzedDataProvider & fuzzed_data_provider
Definition
fees.cpp:38
Generated on Thu Apr 16 2026 09:42:38 for Bitcoin Core by
1.10.0