Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2020-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <chain.h>6#include <test/fuzz/FuzzedDataProvider.h>7#include <test/fuzz/fuzz.h>8#include <test/fuzz/util.h>10#include <cstdint>11#include <optional>12#include <vector>14FUZZ_TARGET(chain)15{16FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());17std::optional<CDiskBlockIndex> disk_block_index = ConsumeDeserializable<CDiskBlockIndex>(fuzzed_data_provider);18if (!disk_block_index) {19return;20}22const uint256 zero{};23disk_block_index->phashBlock = &zero;24{25LOCK(::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}36const CBlockHeader block_header = disk_block_index->GetBlockHeader();37(void)CDiskBlockIndex{*disk_block_index};38(void)disk_block_index->BuildSkip();40LIMITED_WHILE (fuzzed_data_provider.ConsumeBool(), 10000) {41const BlockStatus block_status = fuzzed_data_provider.PickValueInArray({42BlockStatus::BLOCK_VALID_UNKNOWN,43BlockStatus::BLOCK_VALID_RESERVED,44BlockStatus::BLOCK_VALID_TREE,45BlockStatus::BLOCK_VALID_TRANSACTIONS,46BlockStatus::BLOCK_VALID_CHAIN,47BlockStatus::BLOCK_VALID_SCRIPTS,48BlockStatus::BLOCK_VALID_MASK,49BlockStatus::BLOCK_HAVE_DATA,50BlockStatus::BLOCK_HAVE_UNDO,51BlockStatus::BLOCK_HAVE_MASK,52BlockStatus::BLOCK_FAILED_VALID,53BlockStatus::BLOCK_OPT_WITNESS,54});55if (block_status & ~BLOCK_VALID_MASK) {56continue;57}58WITH_LOCK(::cs_main, (void)disk_block_index->RaiseValidity(block_status));59}61CBlockIndex block_index{block_header};62block_index.phashBlock = &zero;63(void)block_index.GetBlockHash();64(void)block_index.ToString();65}
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.