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) 2024-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 <test/fuzz/util/check_globals.h>7#include <test/util/random.h>8#include <util/time.h>10#include <iostream>11#include <memory>12#include <optional>13#include <string>15struct CheckGlobalsImpl {16CheckGlobalsImpl()17{18g_used_g_prng = false;19g_seeded_g_prng_zero = false;20g_used_system_time = false;21SetMockTime(0s);22MockableSteadyClock::ClearMockTime();23}24~CheckGlobalsImpl()25{26if (g_used_g_prng && !g_seeded_g_prng_zero) {27std::cerr << "\n\n"28"The current fuzz target used the global random state.\n\n"30"This is acceptable, but requires the fuzz target to call \n"31"SeedRandomStateForTest(SeedRand::ZEROS) in the first line \n"32"of the FUZZ_TARGET function.\n\n"34"An alternative solution would be to avoid any use of globals.\n\n"36"Without a solution, fuzz instability and non-determinism can lead \n"37"to non-reproducible bugs or inefficient fuzzing.\n\n"38<< std::endl;39std::abort(); // Abort, because AFL may try to recover from a std::exit40}42if (g_used_system_time) {43std::cerr << "\n\n"44"The current fuzz target accessed system time.\n\n"46"This is acceptable, but requires the fuzz target to use \n"47"a FakeNodeClock, FakeSteadyClock or call \n"48"SetMockTime() at the \n" "beginning of processing the \n"49"fuzz input.\n\n"51"Without setting mock time, time-dependent behavior can lead \n"52"to non-reproducible bugs or inefficient fuzzing.\n\n"53<< std::endl;54std::abort();55}56}57};59CheckGlobals::CheckGlobals() : m_impl(std::make_unique<CheckGlobalsImpl>()) {}60CheckGlobals::~CheckGlobals() = default;
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.