Branch data Line data Source code
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 [ + - ]: 725 : FUZZ_TARGET(chain)
15 : : {
16 : 271 : FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
17 : 271 : std::optional<CDiskBlockIndex> disk_block_index = ConsumeDeserializable<CDiskBlockIndex>(fuzzed_data_provider);
18 [ + + ]: 271 : if (!disk_block_index) {
19 : : return;
20 : : }
21 : :
22 : 225 : const uint256 zero{};
23 : 225 : disk_block_index->phashBlock = &zero;
24 : 225 : {
25 : 225 : LOCK(::cs_main);
26 [ + - ]: 225 : (void)disk_block_index->ConstructBlockHash();
27 : 225 : (void)disk_block_index->GetBlockPos();
28 : 225 : (void)disk_block_index->GetBlockTime();
29 : 225 : (void)disk_block_index->GetBlockTimeMax();
30 : 225 : (void)disk_block_index->GetMedianTimePast();
31 [ + - ]: 225 : (void)disk_block_index->GetUndoPos();
32 : 225 : (void)disk_block_index->HaveNumChainTxs();
33 [ + - ]: 225 : (void)disk_block_index->IsValid(BLOCK_VALID_TRANSACTIONS);
34 : 225 : }
35 : :
36 : 225 : const CBlockHeader block_header = disk_block_index->GetBlockHeader();
37 : 225 : (void)CDiskBlockIndex{*disk_block_index};
38 : 225 : (void)disk_block_index->BuildSkip();
39 : :
40 [ + + + + ]: 23739 : LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
41 : 23514 : 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 : 23514 : });
55 [ + + ]: 23514 : if (block_status & ~BLOCK_VALID_MASK) {
56 : 252 : continue;
57 : : }
58 [ + - ]: 46524 : WITH_LOCK(::cs_main, (void)disk_block_index->RaiseValidity(block_status));
59 : : }
60 : :
61 : 225 : CBlockIndex block_index{block_header};
62 : 225 : block_index.phashBlock = &zero;
63 : 225 : (void)block_index.GetBlockHash();
64 : 225 : (void)block_index.ToString();
65 : : }
|