Branch data Line data Source code
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 [ - + ]: 4 : FUZZ_TARGET(script_bitcoin_consensus) 16 : : { 17 : 0 : FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); 18 : 0 : const std::vector<uint8_t> random_bytes_1 = ConsumeRandomLengthByteVector(fuzzed_data_provider); 19 : 0 : const std::vector<uint8_t> random_bytes_2 = ConsumeRandomLengthByteVector(fuzzed_data_provider); 20 : 0 : const CAmount money = ConsumeMoney(fuzzed_data_provider); 21 : : bitcoinconsensus_error err; 22 [ # # # # ]: 0 : bitcoinconsensus_error* err_p = fuzzed_data_provider.ConsumeBool() ? &err : nullptr; 23 [ # # ]: 0 : const unsigned int n_in = fuzzed_data_provider.ConsumeIntegral<unsigned int>(); 24 [ # # ]: 0 : const unsigned int flags = fuzzed_data_provider.ConsumeIntegral<unsigned int>(); 25 [ + - # # : 2 : assert(bitcoinconsensus_version() == BITCOINCONSENSUS_API_VER); # # ] 26 [ # # # # ]: 0 : if ((flags & SCRIPT_VERIFY_WITNESS) != 0 && (flags & SCRIPT_VERIFY_P2SH) == 0) { 27 : 0 : return; 28 : : } 29 [ # # ]: 0 : (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 [ # # ]: 0 : (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 : }