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) 2009-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#ifndef BITCOIN_TEST_FUZZ_FUZZ_H6#define BITCOIN_TEST_FUZZ_FUZZ_H8#include <cstdint>9#include <functional>10#include <span>11#include <string_view>13/**14* Can be used to limit a theoretically unbounded loop. This caps the runtime15* to avoid timeouts or OOMs.16*17* This can be used in combination with a check in the condition to confirm18* whether the fuzz engine provided "good" data. If the fuzz input contains19* invalid data, the loop aborts early. This will teach the fuzz engine to look20* for useful data and avoids bloating the fuzz input folder with useless data.21*/22#define LIMITED_WHILE(condition, limit) \23for (unsigned _count{limit}; (condition) && _count; --_count)25using FuzzBufferType = std::span<const uint8_t>;27using TypeTestOneInput = std::function<void(FuzzBufferType)>;28struct FuzzTargetOptions {29std::function<void()> init{[] {}};30bool hidden{false};31};33void FuzzFrameworkRegisterTarget(std::string_view name, TypeTestOneInput target, FuzzTargetOptions opts);35#define FUZZ_TARGET(...) DETAIL_FUZZ(__VA_ARGS__)37#define DETAIL_FUZZ(name, ...) \38void name##_fuzz_target(FuzzBufferType); \39struct name##_Before_Main { \40name##_Before_Main() \41{ \42FuzzFrameworkRegisterTarget(#name, name##_fuzz_target, {__VA_ARGS__}); \43} \44} const static g_##name##_before_main; \45void name##_fuzz_target(FuzzBufferType buffer)47#endif // BITCOIN_TEST_FUZZ_FUZZ_H
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.