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