/root/bitcoin/src/test/fuzz/chain.cpp
Line | Count | Source |
1 | | // Copyright (c) 2020-2022 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 | 0 | { |
16 | 0 | FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); |
17 | 0 | std::optional<CDiskBlockIndex> disk_block_index = ConsumeDeserializable<CDiskBlockIndex>(fuzzed_data_provider); |
18 | 0 | if (!disk_block_index) { |
19 | 0 | return; |
20 | 0 | } |
21 | | |
22 | 0 | const uint256 zero{}; |
23 | 0 | disk_block_index->phashBlock = &zero; |
24 | 0 | { |
25 | 0 | LOCK(::cs_main); |
26 | 0 | (void)disk_block_index->ConstructBlockHash(); |
27 | 0 | (void)disk_block_index->GetBlockPos(); |
28 | 0 | (void)disk_block_index->GetBlockTime(); |
29 | 0 | (void)disk_block_index->GetBlockTimeMax(); |
30 | 0 | (void)disk_block_index->GetMedianTimePast(); |
31 | 0 | (void)disk_block_index->GetUndoPos(); |
32 | 0 | (void)disk_block_index->HaveNumChainTxs(); |
33 | 0 | (void)disk_block_index->IsValid(); |
34 | 0 | } |
35 | |
|
36 | 0 | const CBlockHeader block_header = disk_block_index->GetBlockHeader(); |
37 | 0 | (void)CDiskBlockIndex{*disk_block_index}; |
38 | 0 | (void)disk_block_index->BuildSkip(); |
39 | |
|
40 | 0 | LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) { |
41 | 0 | const BlockStatus block_status = fuzzed_data_provider.PickValueInArray({ |
42 | 0 | BlockStatus::BLOCK_VALID_UNKNOWN, |
43 | 0 | BlockStatus::BLOCK_VALID_RESERVED, |
44 | 0 | BlockStatus::BLOCK_VALID_TREE, |
45 | 0 | BlockStatus::BLOCK_VALID_TRANSACTIONS, |
46 | 0 | BlockStatus::BLOCK_VALID_CHAIN, |
47 | 0 | BlockStatus::BLOCK_VALID_SCRIPTS, |
48 | 0 | BlockStatus::BLOCK_VALID_MASK, |
49 | 0 | BlockStatus::BLOCK_HAVE_DATA, |
50 | 0 | BlockStatus::BLOCK_HAVE_UNDO, |
51 | 0 | BlockStatus::BLOCK_HAVE_MASK, |
52 | 0 | BlockStatus::BLOCK_FAILED_VALID, |
53 | 0 | BlockStatus::BLOCK_FAILED_CHILD, |
54 | 0 | BlockStatus::BLOCK_FAILED_MASK, |
55 | 0 | BlockStatus::BLOCK_OPT_WITNESS, |
56 | 0 | }); |
57 | 0 | if (block_status & ~BLOCK_VALID_MASK) { |
58 | 0 | continue; |
59 | 0 | } |
60 | 0 | WITH_LOCK(::cs_main, (void)disk_block_index->RaiseValidity(block_status)); |
61 | 0 | } |
62 | |
|
63 | 0 | CBlockIndex block_index{block_header}; |
64 | 0 | block_index.phashBlock = &zero; |
65 | 0 | (void)block_index.GetBlockHash(); |
66 | 0 | (void)block_index.ToString(); |
67 | 0 | } |