|
| 1 | +// Copyright (c) 2020 The Bitcoin Core developers |
| 2 | +// Distributed under the MIT software license, see the accompanying |
| 3 | +// file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 4 | + |
| 5 | +#include <chainparams.h> |
| 6 | +#include <chainparamsbase.h> |
| 7 | +#include <key.h> |
| 8 | +#include <pubkey.h> |
| 9 | +#include <script/sigcache.h> |
| 10 | +#include <test/fuzz/FuzzedDataProvider.h> |
| 11 | +#include <test/fuzz/fuzz.h> |
| 12 | +#include <test/fuzz/util.h> |
| 13 | + |
| 14 | +#include <cstdint> |
| 15 | +#include <optional> |
| 16 | +#include <string> |
| 17 | +#include <vector> |
| 18 | + |
| 19 | +void initialize() |
| 20 | +{ |
| 21 | + static const ECCVerifyHandle ecc_verify_handle; |
| 22 | + ECC_Start(); |
| 23 | + SelectParams(CBaseChainParams::REGTEST); |
| 24 | + InitSignatureCache(); |
| 25 | +} |
| 26 | + |
| 27 | +void test_one_input(const std::vector<uint8_t>& buffer) |
| 28 | +{ |
| 29 | + FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); |
| 30 | + |
| 31 | + const std::optional<CMutableTransaction> mutable_transaction = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider); |
| 32 | + const CTransaction tx = mutable_transaction ? CTransaction{*mutable_transaction} : CTransaction{}; |
| 33 | + const unsigned int n_in = fuzzed_data_provider.ConsumeIntegral<unsigned int>(); |
| 34 | + const CAmount amount = ConsumeMoney(fuzzed_data_provider); |
| 35 | + const bool store = fuzzed_data_provider.ConsumeBool(); |
| 36 | + PrecomputedTransactionData tx_data; |
| 37 | + CachingTransactionSignatureChecker caching_transaction_signature_checker{mutable_transaction ? &tx : nullptr, n_in, amount, store, tx_data}; |
| 38 | + const std::optional<CPubKey> pub_key = ConsumeDeserializable<CPubKey>(fuzzed_data_provider); |
| 39 | + if (pub_key) { |
| 40 | + const std::vector<uint8_t> random_bytes = ConsumeRandomLengthByteVector(fuzzed_data_provider); |
| 41 | + if (!random_bytes.empty()) { |
| 42 | + (void)caching_transaction_signature_checker.VerifySignature(random_bytes, *pub_key, ConsumeUInt256(fuzzed_data_provider)); |
| 43 | + } |
| 44 | + } |
| 45 | +} |
0 commit comments