LCOV - code coverage report
Current view: top level - src/test/fuzz - signature_checker.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 7 29 24.1 %
Date: 2023-09-26 12:08:55 Functions: 4 12 33.3 %

          Line data    Source code
       1             : // Copyright (c) 2009-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 <pubkey.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             : #include <test/util/script.h>
      11           2 : 
      12           2 : #include <cstdint>
      13           2 : #include <limits>
      14           2 : #include <string>
      15           2 : #include <vector>
      16             : 
      17             : namespace {
      18             : class FuzzedSignatureChecker : public BaseSignatureChecker
      19             : {
      20             :     FuzzedDataProvider& m_fuzzed_data_provider;
      21             : 
      22             : public:
      23           0 :     explicit FuzzedSignatureChecker(FuzzedDataProvider& fuzzed_data_provider) : m_fuzzed_data_provider(fuzzed_data_provider)
      24           0 :     {
      25           2 :     }
      26             : 
      27           0 :     bool CheckECDSASignature(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const override
      28             :     {
      29           0 :         return m_fuzzed_data_provider.ConsumeBool();
      30             :     }
      31             : 
      32           0 :     bool CheckSchnorrSignature(Span<const unsigned char> sig, Span<const unsigned char> pubkey, SigVersion sigversion, ScriptExecutionData& execdata, ScriptError* serror = nullptr) const override
      33             :     {
      34           0 :         return m_fuzzed_data_provider.ConsumeBool();
      35             :     }
      36             : 
      37           0 :     bool CheckLockTime(const CScriptNum& nLockTime) const override
      38             :     {
      39           0 :         return m_fuzzed_data_provider.ConsumeBool();
      40             :     }
      41             : 
      42           0 :     bool CheckSequence(const CScriptNum& nSequence) const override
      43             :     {
      44           0 :         return m_fuzzed_data_provider.ConsumeBool();
      45             :     }
      46             : 
      47           0 :     virtual ~FuzzedSignatureChecker() = default;
      48             : };
      49             : } // namespace
      50             : 
      51           4 : FUZZ_TARGET(signature_checker)
      52             : {
      53           0 :     FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
      54           0 :     const unsigned int flags = fuzzed_data_provider.ConsumeIntegral<unsigned int>();
      55           0 :     const SigVersion sig_version = fuzzed_data_provider.PickValueInArray({SigVersion::BASE, SigVersion::WITNESS_V0});
      56           0 :     const auto script_1{ConsumeScript(fuzzed_data_provider)};
      57           0 :     const auto script_2{ConsumeScript(fuzzed_data_provider)};
      58           0 :     std::vector<std::vector<unsigned char>> stack;
      59           0 :     (void)EvalScript(stack, script_1, flags, FuzzedSignatureChecker(fuzzed_data_provider), sig_version, nullptr);
      60           0 :     if (!IsValidFlagCombination(flags)) {
      61           0 :         return;
      62             :     }
      63           0 :     (void)VerifyScript(script_1, script_2, nullptr, flags, FuzzedSignatureChecker(fuzzed_data_provider), nullptr);
      64           0 : }

Generated by: LCOV version 1.14