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) 2020-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 <consensus/amount.h>6#include <primitives/transaction.h>7#include <pubkey.h>8#include <script/interpreter.h>9#include <script/sigcache.h>10#include <span.h>11#include <test/fuzz/FuzzedDataProvider.h>12#include <test/fuzz/fuzz.h>13#include <test/fuzz/util.h>14#include <test/util/setup_common.h>15#include <uint256.h>17#include <cstddef>18#include <optional>19#include <vector>21void initialize_script_sigcache()22{23static const auto testing_setup = MakeNoLogFileContext<>();24}26FUZZ_TARGET(script_sigcache, .init = initialize_script_sigcache)27{28SeedRandomStateForTest(SeedRand::ZEROS);29FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());31const auto max_sigcache_bytes{fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, DEFAULT_SIGNATURE_CACHE_BYTES)};32SignatureCache signature_cache{max_sigcache_bytes};34const std::optional<CMutableTransaction> mutable_transaction = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider, TX_WITH_WITNESS);35const CTransaction tx{mutable_transaction ? *mutable_transaction : CMutableTransaction{}};36const unsigned int n_in = fuzzed_data_provider.ConsumeIntegral<unsigned int>();37const CAmount amount = ConsumeMoney(fuzzed_data_provider);38const bool store = fuzzed_data_provider.ConsumeBool();39PrecomputedTransactionData tx_data;40CachingTransactionSignatureChecker caching_transaction_signature_checker{mutable_transaction ? &tx : nullptr, n_in, amount, store, signature_cache, tx_data};41if (fuzzed_data_provider.ConsumeBool()) {42const auto random_bytes = fuzzed_data_provider.ConsumeBytes<unsigned char>(64);43const XOnlyPubKey pub_key(ConsumeUInt256(fuzzed_data_provider));44if (random_bytes.size() == 64) {45(void)caching_transaction_signature_checker.VerifySchnorrSignature(random_bytes, pub_key, ConsumeUInt256(fuzzed_data_provider));46}47} else {48const auto random_bytes = ConsumeRandomLengthByteVector(fuzzed_data_provider);49const auto pub_key = ConsumeDeserializable<CPubKey>(fuzzed_data_provider);50if (pub_key) {51if (!random_bytes.empty()) {52(void)caching_transaction_signature_checker.VerifyECDSASignature(random_bytes, *pub_key, ConsumeUInt256(fuzzed_data_provider));53}54}55}56}
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.