Bitcoin Core 28.99.0
P2P Digital Currency
kitchen_sink.cpp
Go to the documentation of this file.
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 <common/messages.h>
6#include <merkleblock.h>
7#include <node/types.h>
8#include <policy/fees.h>
9#include <rpc/util.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
22
23namespace {
24constexpr 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.
36FUZZ_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
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}
std::string ConsumeRandomLengthString(size_t max_length)
T PickValueInArray(const T(&array)[size])
FUZZ_TARGET(kitchen_sink)
std::vector< unsigned char > BitsToBytes(const std::vector< bool > &bits)
Definition: merkleblock.cpp:12
std::vector< bool > BytesToBits(const std::vector< unsigned char > &bytes)
Definition: merkleblock.cpp:21
is a home for simple string functions returning descriptive messages that are used in RPC and GUI int...
bilingual_str TransactionErrorString(const TransactionError err)
Definition: messages.cpp:124
TransactionError
Definition: types.h:20
is a home for public enum and struct type definitions that are used by internally by node code,...
std::optional< OutputType > ParseOutputType(const std::string &type)
Definition: outputtype.cpp:24
const std::string & FormatOutputType(OutputType type)
Definition: outputtype.cpp:38
OutputType
Definition: outputtype.h:17
static constexpr auto OUTPUT_TYPES
Definition: outputtype.h:25
std::string StringForFeeEstimateHorizon(FeeEstimateHorizon horizon)
Definition: fees.cpp:40
static constexpr auto ALL_FEE_ESTIMATE_HORIZONS
Definition: fees.h:51
UniValue JSONRPCTransactionError(TransactionError terr, const std::string &err_string)
Definition: util.cpp:430
RPCErrorCode RPCErrorFromTransactionError(TransactionError terr)
Definition: util.cpp:413
std::vector< B > ConsumeRandomLengthByteVector(FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt) noexcept
Definition: util.h:57
assert(!tx.IsCoinBase())