mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 12:23:34 -05:00

In src/test/fuzz/script_sigcache.cpp, we should really be setting up a full working BasicTestingSetup. The initialize_ function is only run once anyway. In src/test/txvalidationcache_tests.cpp, the Dersig100Setup inherits from BasicTestingSetup, which should have already set up a global script execution cache without the need to explicitly call InitScriptExecutionCache.
56 lines
2.2 KiB
C++
56 lines
2.2 KiB
C++
// Copyright (c) 2020 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <chainparams.h>
|
|
#include <chainparamsbase.h>
|
|
#include <key.h>
|
|
#include <pubkey.h>
|
|
#include <script/sigcache.h>
|
|
#include <test/fuzz/FuzzedDataProvider.h>
|
|
#include <test/fuzz/fuzz.h>
|
|
#include <test/fuzz/util.h>
|
|
#include <test/util/setup_common.h>
|
|
|
|
#include <cstdint>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace {
|
|
const BasicTestingSetup* g_setup;
|
|
} // namespace
|
|
|
|
void initialize_script_sigcache()
|
|
{
|
|
static const auto testing_setup = MakeNoLogFileContext<>();
|
|
g_setup = testing_setup.get();
|
|
}
|
|
|
|
FUZZ_TARGET_INIT(script_sigcache, initialize_script_sigcache)
|
|
{
|
|
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
|
|
|
const std::optional<CMutableTransaction> mutable_transaction = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
|
|
const CTransaction tx{mutable_transaction ? *mutable_transaction : CMutableTransaction{}};
|
|
const unsigned int n_in = fuzzed_data_provider.ConsumeIntegral<unsigned int>();
|
|
const CAmount amount = ConsumeMoney(fuzzed_data_provider);
|
|
const bool store = fuzzed_data_provider.ConsumeBool();
|
|
PrecomputedTransactionData tx_data;
|
|
CachingTransactionSignatureChecker caching_transaction_signature_checker{mutable_transaction ? &tx : nullptr, n_in, amount, store, tx_data};
|
|
if (fuzzed_data_provider.ConsumeBool()) {
|
|
const auto random_bytes = fuzzed_data_provider.ConsumeBytes<unsigned char>(64);
|
|
const XOnlyPubKey pub_key(ConsumeUInt256(fuzzed_data_provider));
|
|
if (random_bytes.size() == 64) {
|
|
(void)caching_transaction_signature_checker.VerifySchnorrSignature(random_bytes, pub_key, ConsumeUInt256(fuzzed_data_provider));
|
|
}
|
|
} else {
|
|
const auto random_bytes = ConsumeRandomLengthByteVector(fuzzed_data_provider);
|
|
const auto pub_key = ConsumeDeserializable<CPubKey>(fuzzed_data_provider);
|
|
if (pub_key) {
|
|
if (!random_bytes.empty()) {
|
|
(void)caching_transaction_signature_checker.VerifyECDSASignature(random_bytes, *pub_key, ConsumeUInt256(fuzzed_data_provider));
|
|
}
|
|
}
|
|
}
|
|
}
|