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