mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-11 04:12:36 -03:00
tests: Add fuzzing harness for functions in script/sigcache.h
This commit is contained in:
parent
d3d8adb79f
commit
c91d2f0615
2 changed files with 52 additions and 0 deletions
|
@ -116,6 +116,7 @@ FUZZ_TARGETS = \
|
|||
test/fuzz/script_flags \
|
||||
test/fuzz/script_interpreter \
|
||||
test/fuzz/script_ops \
|
||||
test/fuzz/script_sigcache \
|
||||
test/fuzz/scriptnum_ops \
|
||||
test/fuzz/service_deserialize \
|
||||
test/fuzz/signature_checker \
|
||||
|
@ -980,6 +981,12 @@ test_fuzz_script_ops_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
|||
test_fuzz_script_ops_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
||||
test_fuzz_script_ops_SOURCES = test/fuzz/script_ops.cpp
|
||||
|
||||
test_fuzz_script_sigcache_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||
test_fuzz_script_sigcache_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
test_fuzz_script_sigcache_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
||||
test_fuzz_script_sigcache_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
||||
test_fuzz_script_sigcache_SOURCES = test/fuzz/script_sigcache.cpp
|
||||
|
||||
test_fuzz_scriptnum_ops_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||
test_fuzz_scriptnum_ops_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
test_fuzz_scriptnum_ops_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
||||
|
|
45
src/test/fuzz/script_sigcache.cpp
Normal file
45
src/test/fuzz/script_sigcache.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
// 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 <cstdint>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
void initialize()
|
||||
{
|
||||
static const ECCVerifyHandle ecc_verify_handle;
|
||||
ECC_Start();
|
||||
SelectParams(CBaseChainParams::REGTEST);
|
||||
InitSignatureCache();
|
||||
}
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||
|
||||
const std::optional<CMutableTransaction> mutable_transaction = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
|
||||
const CTransaction tx = mutable_transaction ? CTransaction{*mutable_transaction} : CTransaction{};
|
||||
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};
|
||||
const std::optional<CPubKey> pub_key = ConsumeDeserializable<CPubKey>(fuzzed_data_provider);
|
||||
if (pub_key) {
|
||||
const std::vector<uint8_t> random_bytes = ConsumeRandomLengthByteVector(fuzzed_data_provider);
|
||||
if (!random_bytes.empty()) {
|
||||
(void)caching_transaction_signature_checker.VerifySignature(random_bytes, *pub_key, ConsumeUInt256(fuzzed_data_provider));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue