Coverage Report

Created: 2024-10-21 15:10

/root/bitcoin/src/test/fuzz/message.cpp
Line
Count
Source (jump to first uncovered line)
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 <chainparams.h>
6
#include <common/signmessage.h>
7
#include <key_io.h>
8
#include <test/fuzz/FuzzedDataProvider.h>
9
#include <test/fuzz/fuzz.h>
10
#include <test/fuzz/util.h>
11
#include <util/chaintype.h>
12
#include <util/strencodings.h>
13
14
#include <cassert>
15
#include <cstdint>
16
#include <iostream>
17
#include <string>
18
#include <vector>
19
20
void initialize_message()
21
0
{
22
0
    static ECC_Context ecc_context{};
23
0
    SelectParams(ChainType::REGTEST);
24
0
}
25
26
FUZZ_TARGET(message, .init = initialize_message)
27
0
{
28
0
    FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
29
0
    const std::string random_message = fuzzed_data_provider.ConsumeRandomLengthString(1024);
30
0
    {
31
0
        CKey private_key = ConsumePrivateKey(fuzzed_data_provider);
32
0
        std::string signature;
33
0
        const bool message_signed = MessageSign(private_key, random_message, signature);
34
0
        if (private_key.IsValid()) {
35
0
            assert(message_signed);
36
0
            const MessageVerificationResult verification_result = MessageVerify(EncodeDestination(PKHash(private_key.GetPubKey().GetID())), signature, random_message);
37
0
            assert(verification_result == MessageVerificationResult::OK);
38
0
        }
39
0
    }
40
0
    {
41
0
        (void)MessageHash(random_message);
42
0
        auto address = fuzzed_data_provider.ConsumeRandomLengthString(1024);
43
0
        auto signature = fuzzed_data_provider.ConsumeRandomLengthString(1024);
44
0
        (void)MessageVerify(address, signature, random_message);
45
0
        (void)SigningResultString(fuzzed_data_provider.PickValueInArray({SigningResult::OK, SigningResult::PRIVATE_KEY_NOT_AVAILABLE, SigningResult::SIGNING_FAILED}));
46
0
    }
47
0
}