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) 2019-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 <chainparams.h>6#include <consensus/merkle.h>7#include <consensus/validation.h>8#include <core_io.h>9#include <core_memusage.h>10#include <primitives/block.h>11#include <pubkey.h>12#include <streams.h>13#include <test/fuzz/fuzz.h>14#include <util/chaintype.h>15#include <validation.h>17#include <cassert>18#include <string>20void initialize_block()21{22SelectParams(ChainType::REGTEST);23}25FUZZ_TARGET(block, .init = initialize_block)26{27CBlock block;28try {29SpanReader{buffer} >> TX_WITH_WITNESS(block);30} catch (const std::ios_base::failure&) {31return;32}33const Consensus::Params& consensus_params = Params().GetConsensus();34BlockValidationState validation_state_pow_and_merkle;35const bool valid_incl_pow_and_merkle = CheckBlock(block, validation_state_pow_and_merkle, consensus_params, /* fCheckPOW= */ true, /* fCheckMerkleRoot= */ true);36assert(validation_state_pow_and_merkle.IsValid() || validation_state_pow_and_merkle.IsInvalid() || validation_state_pow_and_merkle.IsError());37(void)validation_state_pow_and_merkle.Error("");38BlockValidationState validation_state_pow;39const bool valid_incl_pow = CheckBlock(block, validation_state_pow, consensus_params, /* fCheckPOW= */ true, /* fCheckMerkleRoot= */ false);40assert(validation_state_pow.IsValid() || validation_state_pow.IsInvalid() || validation_state_pow.IsError());41BlockValidationState validation_state_merkle;42const bool valid_incl_merkle = CheckBlock(block, validation_state_merkle, consensus_params, /* fCheckPOW= */ false, /* fCheckMerkleRoot= */ true);43assert(validation_state_merkle.IsValid() || validation_state_merkle.IsInvalid() || validation_state_merkle.IsError());44BlockValidationState validation_state_none;45const bool valid_incl_none = CheckBlock(block, validation_state_none, consensus_params, /* fCheckPOW= */ false, /* fCheckMerkleRoot= */ false);46assert(validation_state_none.IsValid() || validation_state_none.IsInvalid() || validation_state_none.IsError());47if (valid_incl_pow_and_merkle) {48assert(valid_incl_pow && valid_incl_merkle && valid_incl_none);49} else if (valid_incl_merkle || valid_incl_pow) {50assert(valid_incl_none);51}52(void)block.GetHash();53(void)block.ToString();54(void)BlockMerkleRoot(block);55if (!block.vtx.empty()) {56(void)BlockWitnessMerkleRoot(block);57}58(void)GetBlockWeight(block);59(void)GetWitnessCommitmentIndex(block);60const size_t raw_memory_size = RecursiveDynamicUsage(block);61const size_t raw_memory_size_as_shared_ptr = RecursiveDynamicUsage(std::make_shared<CBlock>(block));62assert(raw_memory_size_as_shared_ptr > raw_memory_size);63CBlock block_copy = block;64block_copy.SetNull();65const bool is_null = block_copy.IsNull();66assert(is_null);67}
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.