LCOV - code coverage report
Current view: top level - src/test/fuzz - script_sigcache.cpp (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 90.0 % 30 27
Test Date: 2024-09-01 05:20:30 Functions: 66.7 % 3 2
Branches: 56.2 % 48 27

             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 <consensus/amount.h>
       6                 :             : #include <primitives/transaction.h>
       7                 :             : #include <pubkey.h>
       8                 :             : #include <script/interpreter.h>
       9                 :             : #include <script/sigcache.h>
      10                 :             : #include <span.h>
      11                 :             : #include <test/fuzz/FuzzedDataProvider.h>
      12                 :             : #include <test/fuzz/fuzz.h>
      13                 :             : #include <test/fuzz/util.h>
      14                 :             : #include <test/util/setup_common.h>
      15                 :             : #include <uint256.h>
      16                 :             : 
      17                 :             : #include <cstddef>
      18                 :             : #include <optional>
      19                 :             : #include <vector>
      20                 :             : 
      21                 :           0 : void initialize_script_sigcache()
      22                 :             : {
      23   [ #  #  #  #  :           0 :     static const auto testing_setup = MakeNoLogFileContext<>();
                   #  # ]
      24                 :           0 : }
      25                 :             : 
      26         [ +  - ]:         696 : FUZZ_TARGET(script_sigcache, .init = initialize_script_sigcache)
      27                 :             : {
      28                 :         694 :     FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
      29                 :             : 
      30                 :         694 :     const auto max_sigcache_bytes{fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, DEFAULT_SIGNATURE_CACHE_BYTES)};
      31                 :         694 :     SignatureCache signature_cache{max_sigcache_bytes};
      32                 :             : 
      33                 :         694 :     const std::optional<CMutableTransaction> mutable_transaction = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider, TX_WITH_WITNESS);
      34   [ +  +  +  -  :         694 :     const CTransaction tx{mutable_transaction ? *mutable_transaction : CMutableTransaction{}};
             +  -  +  - ]
      35         [ +  - ]:         694 :     const unsigned int n_in = fuzzed_data_provider.ConsumeIntegral<unsigned int>();
      36                 :         694 :     const CAmount amount = ConsumeMoney(fuzzed_data_provider);
      37         [ +  - ]:         694 :     const bool store = fuzzed_data_provider.ConsumeBool();
      38         [ +  - ]:         694 :     PrecomputedTransactionData tx_data;
      39   [ +  +  +  - ]:         694 :     CachingTransactionSignatureChecker caching_transaction_signature_checker{mutable_transaction ? &tx : nullptr, n_in, amount, store, signature_cache, tx_data};
      40   [ +  -  +  + ]:         694 :     if (fuzzed_data_provider.ConsumeBool()) {
      41         [ +  - ]:         122 :         const auto random_bytes = fuzzed_data_provider.ConsumeBytes<unsigned char>(64);
      42   [ +  -  +  - ]:         122 :         const XOnlyPubKey pub_key(ConsumeUInt256(fuzzed_data_provider));
      43         [ +  + ]:         122 :         if (random_bytes.size() == 64) {
      44   [ +  -  +  - ]:          79 :             (void)caching_transaction_signature_checker.VerifySchnorrSignature(random_bytes, pub_key, ConsumeUInt256(fuzzed_data_provider));
      45                 :          79 :         }
      46                 :         122 :     } else {
      47                 :         572 :         const auto random_bytes = ConsumeRandomLengthByteVector(fuzzed_data_provider);
      48                 :         572 :         const auto pub_key = ConsumeDeserializable<CPubKey>(fuzzed_data_provider);
      49         [ +  + ]:         572 :         if (pub_key) {
      50         [ +  + ]:         150 :             if (!random_bytes.empty()) {
      51         [ +  - ]:         147 :                 (void)caching_transaction_signature_checker.VerifyECDSASignature(random_bytes, *pub_key, ConsumeUInt256(fuzzed_data_provider));
      52                 :         147 :             }
      53                 :         150 :         }
      54                 :         572 :     }
      55                 :         694 : }
        

Generated by: LCOV version 2.0-1