LCOV - code coverage report
Current view: top level - src/test/fuzz - muhash.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 37 37 100.0 %
Date: 2023-10-05 15:40:34 Functions: 7 7 100.0 %
Branches: 10 20 50.0 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (c) 2020-2021 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 <crypto/muhash.h>
       6                 :            : #include <test/fuzz/FuzzedDataProvider.h>
       7                 :            : #include <test/fuzz/fuzz.h>
       8                 :            : #include <test/fuzz/util.h>
       9                 :            : 
      10                 :            : #include <vector>
      11                 :            : 
      12         [ -  + ]:        385 : FUZZ_TARGET(muhash)
      13                 :            : {
      14                 :         39 :     FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
      15                 :         39 :     std::vector<uint8_t> data{ConsumeRandomLengthByteVector(fuzzed_data_provider)};
      16                 :         39 :     std::vector<uint8_t> data2{ConsumeRandomLengthByteVector(fuzzed_data_provider)};
      17                 :            : 
      18                 :         39 :     MuHash3072 muhash;
      19                 :            : 
      20         [ +  - ]:         39 :     muhash.Insert(data);
      21         [ +  - ]:         39 :     muhash.Insert(data2);
      22                 :            : 
      23         [ +  - ]:         39 :     const std::string initial_state_hash{"dd5ad2a105c2d29495f577245c357409002329b9f4d6182c0af3dc2f462555c8"};
      24         [ +  - ]:         39 :     uint256 out;
      25   [ +  -  +  - ]:        212 :     uint256 out2;
      26         [ +  - ]:         39 :     CallOneOf(
      27                 :            :         fuzzed_data_provider,
      28                 :         55 :         [&] {
      29                 :            :             // Test that MuHash result is consistent independent of order of operations
      30                 :         16 :             muhash.Finalize(out);
      31                 :            : 
      32                 :         16 :             muhash = MuHash3072();
      33                 :         16 :             muhash.Insert(data2);
      34                 :         16 :             muhash.Insert(data);
      35                 :         16 :             muhash.Finalize(out2);
      36                 :         16 :         },
      37                 :         40 :         [&] {
      38                 :            :             // Test that multiplication with the initial state never changes the finalized result
      39                 :          1 :             muhash.Finalize(out);
      40                 :          1 :             MuHash3072 muhash3;
      41                 :          1 :             muhash3 *= muhash;
      42                 :          1 :             muhash3.Finalize(out2);
      43                 :          1 :         },
      44                 :         48 :         [&] {
      45                 :            :             // Test that dividing a MuHash by itself brings it back to it's initial state
      46                 :          9 :             muhash /= muhash;
      47                 :          9 :             muhash.Finalize(out);
      48                 :          9 :             out2 = uint256S(initial_state_hash);
      49                 :          9 :         },
      50                 :         52 :         [&] {
      51                 :            :             // Test that removing all added elements brings the object back to it's initial state
      52                 :         13 :             muhash.Remove(data);
      53                 :         13 :             muhash.Remove(data2);
      54                 :         13 :             muhash.Finalize(out);
      55                 :         13 :             out2 = uint256S(initial_state_hash);
      56                 :         13 :         });
      57   [ +  -  +  - ]:         39 :     assert(out == out2);
      58                 :         39 : }

Generated by: LCOV version 1.14