Bitcoin Core
31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
src
test
fuzz
message.cpp
Go to the documentation of this file.
1
// Copyright (c) 2020-present 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
{
22
static
ECC_Context
ecc_context
{};
23
SelectParams
(
ChainType::REGTEST
);
24
}
25
26
FUZZ_TARGET
(message, .
init
=
initialize_message
)
27
{
28
FuzzedDataProvider
fuzzed_data_provider
(buffer.data(), buffer.size());
29
const
std::string
random_message
=
fuzzed_data_provider
.
ConsumeRandomLengthString
(1024);
30
{
31
CKey
private_key =
ConsumePrivateKey
(
fuzzed_data_provider
);
32
std::string
signature
;
33
const
bool
message_signed
=
MessageSign
(private_key,
random_message
,
signature
);
34
if
(private_key.IsValid()) {
35
assert
(
message_signed
);
36
const
MessageVerificationResult
verification_result
=
MessageVerify
(
EncodeDestination
(
PKHash
(private_key.GetPubKey().GetID())),
signature
,
random_message
);
37
assert
(
verification_result
==
MessageVerificationResult::OK
);
38
}
39
}
40
{
41
(
void
)
MessageHash
(
random_message
);
42
auto
address =
fuzzed_data_provider
.
ConsumeRandomLengthString
(1024);
43
auto
signature
=
fuzzed_data_provider
.
ConsumeRandomLengthString
(1024);
44
(
void
)
MessageVerify
(address,
signature
,
random_message
);
45
(
void
)
SigningResultString
(
fuzzed_data_provider
.
PickValueInArray
({
SigningResult::OK
,
SigningResult::PRIVATE_KEY_NOT_AVAILABLE
,
SigningResult::SIGNING_FAILED
}));
46
}
47
}
FuzzedDataProvider.h
ecc_context
ECC_Context ecc_context
Definition
bitcoin-wallet.cpp:126
SelectParams
void SelectParams(const ChainType chain)
Sets the params returned by Params() to those for the given chain type.
Definition
chainparams.cpp:140
chaintype.h
ChainType::REGTEST
@ REGTEST
CKey
An encapsulated private key.
Definition
key.h:36
ECC_Context
RAII class initializing and deinitializing global state for elliptic curve support.
Definition
key.h:326
FuzzedDataProvider
Definition
FuzzedDataProvider.h:32
FuzzedDataProvider::ConsumeRandomLengthString
std::string ConsumeRandomLengthString(size_t max_length)
Definition
FuzzedDataProvider.h:153
FuzzedDataProvider::PickValueInArray
T PickValueInArray(const T(&array)[size])
Definition
FuzzedDataProvider.h:304
MessageHash
uint256 MessageHash(const std::string &message)
Hashes a message for signing and verification in a manner that prevents inadvertently signing a trans...
Definition
signmessage.cpp:73
MessageSign
bool MessageSign(const CKey &privkey, const std::string &message, std::string &signature)
Sign a message.
Definition
signmessage.cpp:57
SigningResultString
std::string SigningResultString(const SigningResult res)
Definition
signmessage.cpp:81
MessageVerify
MessageVerificationResult MessageVerify(const std::string &address, const std::string &signature, const std::string &message)
Verify a signed message.
Definition
signmessage.cpp:26
fuzz.h
FUZZ_TARGET
#define FUZZ_TARGET(...)
Definition
fuzz.h:35
EncodeDestination
std::string EncodeDestination(const CTxDestination &dest)
Definition
key_io.cpp:294
key_io.h
initialize_message
void initialize_message()
Definition
message.cpp:20
init
Definition
bitcoin-gui.cpp:17
signmessage.h
SigningResult::PRIVATE_KEY_NOT_AVAILABLE
@ PRIVATE_KEY_NOT_AVAILABLE
SigningResult::SIGNING_FAILED
@ SIGNING_FAILED
SigningResult::OK
@ OK
No error.
MessageVerificationResult
MessageVerificationResult
The result of a signed message verification.
Definition
signmessage.h:23
MessageVerificationResult::OK
@ OK
The message verification was successful.
strencodings.h
PKHash
Definition
addresstype.h:48
ConsumePrivateKey
CKey ConsumePrivateKey(FuzzedDataProvider &fuzzed_data_provider, std::optional< bool > compressed) noexcept
Definition
util.cpp:235
util.h
Ticks
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition
time.h:73
assert
assert(!tx.IsCoinBase())
fuzzed_data_provider
FuzzedDataProvider & fuzzed_data_provider
Definition
fees.cpp:38
Generated on Thu Apr 16 2026 09:42:38 for Bitcoin Core by
1.10.0