|
| 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 <script/bitcoinconsensus.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 | + |
| 11 | +#include <cstdint> |
| 12 | +#include <string> |
| 13 | +#include <vector> |
| 14 | + |
| 15 | +void test_one_input(const std::vector<uint8_t>& buffer) |
| 16 | +{ |
| 17 | + FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); |
| 18 | + const std::vector<uint8_t> random_bytes_1 = ConsumeRandomLengthByteVector(fuzzed_data_provider); |
| 19 | + const std::vector<uint8_t> random_bytes_2 = ConsumeRandomLengthByteVector(fuzzed_data_provider); |
| 20 | + const CAmount money = ConsumeMoney(fuzzed_data_provider); |
| 21 | + bitcoinconsensus_error err; |
| 22 | + bitcoinconsensus_error* err_p = fuzzed_data_provider.ConsumeBool() ? &err : nullptr; |
| 23 | + const unsigned int n_in = fuzzed_data_provider.ConsumeIntegral<unsigned int>(); |
| 24 | + const unsigned int flags = fuzzed_data_provider.ConsumeIntegral<unsigned int>(); |
| 25 | + assert(bitcoinconsensus_version() == BITCOINCONSENSUS_API_VER); |
| 26 | + if ((flags & SCRIPT_VERIFY_WITNESS) != 0 && (flags & SCRIPT_VERIFY_P2SH) == 0) { |
| 27 | + return; |
| 28 | + } |
| 29 | + (void)bitcoinconsensus_verify_script(random_bytes_1.data(), random_bytes_1.size(), random_bytes_2.data(), random_bytes_2.size(), n_in, flags, err_p); |
| 30 | + (void)bitcoinconsensus_verify_script_with_amount(random_bytes_1.data(), random_bytes_1.size(), money, random_bytes_2.data(), random_bytes_2.size(), n_in, flags, err_p); |
| 31 | +} |
0 commit comments