Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
test
fuzz
kitchen_sink.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 <
common/messages.h
>
6
#include <
merkleblock.h
>
7
#include <
node/types.h
>
8
#include <
outputtype.h
>
9
#include <
policy/fees/block_policy_estimator.h
>
10
#include <rpc/util.h>
11
#include <
test/fuzz/FuzzedDataProvider.h
>
12
#include <
test/fuzz/fuzz.h
>
13
#include <
test/fuzz/util.h
>
14
#include <
util/check.h
>
15
#include <
util/translation.h
>
16
17
#include <cstdint>
18
#include <optional>
19
#include <string>
20
#include <vector>
21
22
using
common::TransactionErrorString
;
23
using
node::TransactionError
;
24
25
namespace
{
26
constexpr
TransactionError
ALL_TRANSACTION_ERROR[] = {
27
TransactionError::MISSING_INPUTS,
28
TransactionError::ALREADY_IN_UTXO_SET,
29
TransactionError::MEMPOOL_REJECTED,
30
TransactionError::MEMPOOL_ERROR,
31
TransactionError::MAX_FEE_EXCEEDED,
32
};
33
};
// namespace
34
35
// The fuzzing kitchen sink: Fuzzing harness for functions that need to be
36
// fuzzed but a.) don't belong in any existing fuzzing harness file, and
37
// b.) are not important enough to warrant their own fuzzing harness file.
38
FUZZ_TARGET
(kitchen_sink)
39
{
40
FuzzedDataProvider
fuzzed_data_provider(buffer.data(), buffer.size());
41
42
const
TransactionError
transaction_error = fuzzed_data_provider.
PickValueInArray
(ALL_TRANSACTION_ERROR);
43
(void)
JSONRPCTransactionError
(transaction_error);
44
(void)
RPCErrorFromTransactionError
(transaction_error);
45
(void)
TransactionErrorString
(transaction_error);
46
47
(void)
StringForFeeEstimateHorizon
(fuzzed_data_provider.
PickValueInArray
(
ALL_FEE_ESTIMATE_HORIZONS
));
48
49
const
OutputType
output_type = fuzzed_data_provider.
PickValueInArray
(
OUTPUT_TYPES
);
50
const
std::string& output_type_string =
FormatOutputType
(output_type);
51
const
std::optional<OutputType> parsed =
ParseOutputType
(output_type_string);
52
assert
(parsed);
53
assert
(output_type == parsed.value());
54
(void)
ParseOutputType
(fuzzed_data_provider.
ConsumeRandomLengthString
(64));
55
56
const
std::vector<uint8_t> bytes =
ConsumeRandomLengthByteVector
(fuzzed_data_provider);
57
const
std::vector<bool> bits =
BytesToBits
(bytes);
58
const
std::vector<uint8_t> bytes_decoded =
BitsToBytes
(bits);
59
assert
(bytes == bytes_decoded);
60
}
FuzzedDataProvider.h
block_policy_estimator.h
ALL_FEE_ESTIMATE_HORIZONS
constexpr auto ALL_FEE_ESTIMATE_HORIZONS
Definition
block_policy_estimator.h:49
check.h
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
fuzz.h
FUZZ_TARGET
#define FUZZ_TARGET(...)
Definition
fuzz.h:35
BitsToBytes
std::vector< unsigned char > BitsToBytes(const std::vector< bool > &bits)
Definition
merkleblock.cpp:13
BytesToBits
std::vector< bool > BytesToBits(const std::vector< unsigned char > &bytes)
Definition
merkleblock.cpp:22
merkleblock.h
messages.h
common::TransactionErrorString
bilingual_str TransactionErrorString(const TransactionError err)
Definition
messages.cpp:118
node::TransactionError
TransactionError
Definition
types.h:19
types.h
ParseOutputType
std::optional< OutputType > ParseOutputType(std::string_view type)
Definition
outputtype.cpp:23
FormatOutputType
const std::string & FormatOutputType(OutputType type)
Definition
outputtype.cpp:37
outputtype.h
OutputType
OutputType
Definition
outputtype.h:18
OUTPUT_TYPES
constexpr auto OUTPUT_TYPES
Definition
outputtype.h:26
StringForFeeEstimateHorizon
std::string StringForFeeEstimateHorizon(FeeEstimateHorizon horizon)
Definition
block_policy_estimator.cpp:42
TransactionErrorString
bilingual_str TransactionErrorString(const TransactionError err)
Definition
messages.cpp:118
JSONRPCTransactionError
UniValue JSONRPCTransactionError(TransactionError terr, const std::string &err_string)
Definition
util.cpp:415
RPCErrorFromTransactionError
RPCErrorCode RPCErrorFromTransactionError(TransactionError terr)
Definition
util.cpp:396
util.h
ConsumeRandomLengthByteVector
std::vector< B > ConsumeRandomLengthByteVector(FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt) noexcept
Definition
util.h:63
translation.h
assert
assert(!tx.IsCoinBase())
Generated on
for Bitcoin Core by
1.18.0