LCOV - code coverage report
Current view: top level - src/test/fuzz - script_bitcoin_consensus.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 2 31 6.5 %
Date: 2023-11-12 01:39:15 Functions: 1 3 33.3 %
Branches: 2 40 5.0 %

           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 [ +  - ][ +  - ]:          6 : 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                 :            : 
      32                 :          0 :     std::vector<UTXO> spent_outputs;
      33                 :          0 :     std::vector<std::vector<unsigned char>> spent_spks;
      34         [ #  # ]:          0 :     if (n_in <= 24386) {
      35         [ #  # ]:          0 :         spent_outputs.reserve(n_in);
      36         [ #  # ]:          0 :         spent_spks.reserve(n_in);
      37         [ #  # ]:          0 :         for (size_t i = 0; i < n_in; ++i) {
      38         [ #  # ]:          0 :             spent_spks.push_back(ConsumeRandomLengthByteVector(fuzzed_data_provider));
      39                 :          0 :             const CAmount value{ConsumeMoney(fuzzed_data_provider)};
      40                 :          0 :             const auto spk_size{static_cast<unsigned>(spent_spks.back().size())};
      41         [ #  # ]:          0 :             spent_outputs.push_back({.scriptPubKey = spent_spks.back().data(), .scriptPubKeySize = spk_size, .value = value});
      42                 :          0 :         }
      43                 :          0 :     }
      44                 :            : 
      45                 :          0 :     const auto spent_outs_size{static_cast<unsigned>(spent_outputs.size())};
      46                 :            : 
      47         [ #  # ]:          0 :     (void)bitcoinconsensus_verify_script_with_spent_outputs(
      48                 :          0 :             random_bytes_1.data(), random_bytes_1.size(), money, random_bytes_2.data(), random_bytes_2.size(),
      49                 :          0 :             spent_outputs.data(), spent_outs_size, n_in, flags, err_p);
      50         [ #  # ]:          0 : }

Generated by: LCOV version 1.14