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#include <pubkey.h>6#include <script/interpreter.h>7#include <test/fuzz/FuzzedDataProvider.h>8#include <test/fuzz/fuzz.h>9#include <test/fuzz/util.h>10#include <test/util/script.h>12#include <cstdint>13#include <limits>14#include <string>15#include <vector>17namespace {18class FuzzedSignatureChecker : public BaseSignatureChecker19{20FuzzedDataProvider& m_fuzzed_data_provider;22public:23explicit FuzzedSignatureChecker(FuzzedDataProvider& fuzzed_data_provider) : m_fuzzed_data_provider(fuzzed_data_provider)24{25}27bool CheckECDSASignature(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const override28{29return m_fuzzed_data_provider.ConsumeBool();30}32bool CheckSchnorrSignature(std::span<const unsigned char> sig, std::span<const unsigned char> pubkey, SigVersion sigversion, ScriptExecutionData& execdata, ScriptError* serror = nullptr) const override33{34return m_fuzzed_data_provider.ConsumeBool();35}37bool CheckLockTime(const CScriptNum& nLockTime) const override38{39return m_fuzzed_data_provider.ConsumeBool();40}42bool CheckSequence(const CScriptNum& nSequence) const override43{44return m_fuzzed_data_provider.ConsumeBool();45}47virtual ~FuzzedSignatureChecker() = default;48};49} // namespace51FUZZ_TARGET(signature_checker)52{53FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());54const auto flags = script_verify_flags::from_int(fuzzed_data_provider.ConsumeIntegral<script_verify_flags::value_type>());55const SigVersion sig_version = fuzzed_data_provider.PickValueInArray({SigVersion::BASE, SigVersion::WITNESS_V0});56const auto script_1{ConsumeScript(fuzzed_data_provider)};57const auto script_2{ConsumeScript(fuzzed_data_provider)};58std::vector<std::vector<unsigned char>> stack;59(void)EvalScript(stack, script_1, flags, FuzzedSignatureChecker(fuzzed_data_provider), sig_version, nullptr);60if (!IsValidFlagCombination(flags)) {61return;62}63(void)VerifyScript(script_1, script_2, nullptr, flags, FuzzedSignatureChecker(fuzzed_data_provider), nullptr);64}
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.