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 <coins.h>7#include <consensus/tx_check.h>8#include <consensus/tx_verify.h>9#include <consensus/validation.h>10#include <core_io.h>11#include <core_memusage.h>12#include <policy/policy.h>13#include <policy/settings.h>14#include <primitives/transaction.h>15#include <streams.h>16#include <test/fuzz/fuzz.h>17#include <test/util/random.h>18#include <univalue.h>19#include <util/chaintype.h>20#include <util/rbf.h>21#include <validation.h>23#include <cassert>25void initialize_transaction()26{27SelectParams(ChainType::REGTEST);28}30FUZZ_TARGET(transaction, .init = initialize_transaction)31{32SeedRandomStateForTest(SeedRand::ZEROS);33SpanReader ds{buffer};34bool valid_tx = true;35const CTransaction tx = [&] {36try {37return CTransaction(deserialize, TX_WITH_WITNESS, ds);38} catch (const std::ios_base::failure&) {39valid_tx = false;40return CTransaction{CMutableTransaction{}};41}42}();43bool valid_mutable_tx = true;44CMutableTransaction mutable_tx;45try {46SpanReader{buffer} >> TX_WITH_WITNESS(mutable_tx);47} catch (const std::ios_base::failure&) {48valid_mutable_tx = false;49}50assert(valid_tx == valid_mutable_tx);51if (!valid_tx) {52return;53}55{56TxValidationState state_with_dupe_check;57const bool res{CheckTransaction(tx, state_with_dupe_check)};58Assert(res == state_with_dupe_check.IsValid());59}61const CFeeRate dust_relay_fee{DUST_RELAY_TX_FEE};62std::string reason;63const bool is_standard_with_permit_bare_multisig = IsStandardTx(tx, std::nullopt, /* permit_bare_multisig= */ true, dust_relay_fee, reason);64const bool is_standard_without_permit_bare_multisig = IsStandardTx(tx, std::nullopt, /* permit_bare_multisig= */ false, dust_relay_fee, reason);65if (is_standard_without_permit_bare_multisig) {66assert(is_standard_with_permit_bare_multisig);67}69(void)tx.GetHash();70(void)tx.ComputeTotalSize();71try {72(void)tx.GetValueOut();73} catch (const std::runtime_error&) {74}75(void)tx.GetWitnessHash();76(void)tx.HasWitness();77(void)tx.IsCoinBase();78(void)tx.IsNull();79(void)tx.ToString();81(void)EncodeHexTx(tx);82(void)GetLegacySigOpCount(tx);83(void)GetTransactionWeight(tx);84(void)GetVirtualTransactionSize(tx);85(void)IsFinalTx(tx, /* nBlockHeight= */ 1024, /* nBlockTime= */ 1024);86(void)RecursiveDynamicUsage(tx);87(void)SignalsOptInRBF(tx);89const CCoinsViewCache coins_view_cache{&CoinsViewEmpty::Get()};90(void)ValidateInputsStandardness(tx, coins_view_cache);91(void)IsWitnessStandard(tx, coins_view_cache);93if (tx.ComputeTotalSize() < 250'000) { // Avoid high memory usage (with msan) due to json encoding94{95UniValue u{UniValue::VOBJ};96TxToUniv(tx, /*block_hash=*/uint256::ZERO, /*entry=*/u);97}98{99UniValue u{UniValue::VOBJ};100TxToUniv(tx, /*block_hash=*/uint256::ONE, /*entry=*/u);101}102}103}
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.