LCOV - code coverage report
Current view: top level - src/test/fuzz - script_sigcache.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 3 33 9.1 %
Date: 2023-11-06 23:13:05 Functions: 1 7 14.3 %
Branches: 3 52 5.8 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (c) 2020-2022 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 <key.h>
       7                 :            : #include <pubkey.h>
       8                 :            : #include <script/sigcache.h>
       9                 :            : #include <test/fuzz/FuzzedDataProvider.h>
      10                 :            : #include <test/fuzz/fuzz.h>
      11                 :            : #include <test/fuzz/util.h>
      12                 :            : #include <test/util/setup_common.h>
      13                 :            : 
      14                 :            : #include <cstdint>
      15                 :            : #include <optional>
      16                 :            : #include <string>
      17         [ +  - ]:          2 : #include <vector>
      18         [ +  - ]:          2 : 
      19                 :            : namespace {
      20                 :            : const BasicTestingSetup* g_setup;
      21                 :            : } // namespace
      22                 :            : 
      23                 :          0 : void initialize_script_sigcache()
      24                 :            : {
      25 [ #  # ][ #  # ]:          0 :     static const auto testing_setup = MakeNoLogFileContext<>();
                 [ #  # ]
      26                 :          0 :     g_setup = testing_setup.get();
      27                 :          0 : }
      28                 :            : 
      29         [ +  - ]:          4 : FUZZ_TARGET(script_sigcache, .init = initialize_script_sigcache)
      30                 :            : {
      31                 :          0 :     FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
      32                 :            : 
      33                 :          0 :     const std::optional<CMutableTransaction> mutable_transaction = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
      34 [ #  # ][ #  # ]:          0 :     const CTransaction tx{mutable_transaction ? *mutable_transaction : CMutableTransaction{}};
         [ #  # ][ #  # ]
      35         [ #  # ]:          0 :     const unsigned int n_in = fuzzed_data_provider.ConsumeIntegral<unsigned int>();
      36                 :          0 :     const CAmount amount = ConsumeMoney(fuzzed_data_provider);
      37         [ #  # ]:          0 :     const bool store = fuzzed_data_provider.ConsumeBool();
      38         [ #  # ]:          0 :     PrecomputedTransactionData tx_data;
      39 [ #  # ][ #  # ]:          0 :     CachingTransactionSignatureChecker caching_transaction_signature_checker{mutable_transaction ? &tx : nullptr, n_in, amount, store, tx_data};
      40 [ #  # ][ #  # ]:          0 :     if (fuzzed_data_provider.ConsumeBool()) {
      41         [ #  # ]:          0 :         const auto random_bytes = fuzzed_data_provider.ConsumeBytes<unsigned char>(64);
      42 [ #  # ][ #  # ]:          0 :         const XOnlyPubKey pub_key(ConsumeUInt256(fuzzed_data_provider));
      43         [ #  # ]:          0 :         if (random_bytes.size() == 64) {
      44 [ #  # ][ #  # ]:          0 :             (void)caching_transaction_signature_checker.VerifySchnorrSignature(random_bytes, pub_key, ConsumeUInt256(fuzzed_data_provider));
      45                 :          0 :         }
      46                 :          0 :     } else {
      47                 :          0 :         const auto random_bytes = ConsumeRandomLengthByteVector(fuzzed_data_provider);
      48                 :          0 :         const auto pub_key = ConsumeDeserializable<CPubKey>(fuzzed_data_provider);
      49         [ #  # ]:          0 :         if (pub_key) {
      50         [ #  # ]:          0 :             if (!random_bytes.empty()) {
      51         [ #  # ]:          0 :                 (void)caching_transaction_signature_checker.VerifyECDSASignature(random_bytes, *pub_key, ConsumeUInt256(fuzzed_data_provider));
      52                 :          0 :             }
      53                 :          0 :         }
      54                 :          0 :     }
      55                 :          0 : }

Generated by: LCOV version 1.14