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 <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>11#include <cassert>12#include <cstdint>13#include <optional>14#include <string>15#include <vector>17FUZZ_TARGET(block_header)18{19FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());20const std::optional<CBlockHeader> block_header = ConsumeDeserializable<CBlockHeader>(fuzzed_data_provider);21if (!block_header) {22return;23}24{25const uint256 hash = block_header->GetHash();26constexpr uint256 u256_max{"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"};27assert(hash != u256_max);28assert(block_header->GetBlockTime() == block_header->nTime);29assert(block_header->IsNull() == (block_header->nBits == 0));30}31{32CBlockHeader mut_block_header = *block_header;33mut_block_header.SetNull();34assert(mut_block_header.IsNull());35CBlock block{*block_header};36assert(block.GetHash() == block_header->GetHash());37(void)block.ToString();38block.SetNull();39assert(block.GetHash() == mut_block_header.GetHash());40}41{42std::optional<CBlockLocator> block_locator = ConsumeDeserializable<CBlockLocator>(fuzzed_data_provider);43if (block_locator) {44(void)block_locator->IsNull();45block_locator->SetNull();46assert(block_locator->IsNull());47}48}49}
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.