2021-01-25 08:23:45 -03:00
|
|
|
// Copyright (c) 2020-2021 The Bitcoin Core developers
|
2020-04-22 09:53:50 -04:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2020-11-12 12:06:45 -03:00
|
|
|
#include <merkleblock.h>
|
|
|
|
#include <policy/fees.h>
|
2020-04-22 10:40:32 -04:00
|
|
|
#include <rpc/util.h>
|
2020-04-22 09:53:50 -04:00
|
|
|
#include <test/fuzz/FuzzedDataProvider.h>
|
|
|
|
#include <test/fuzz/fuzz.h>
|
|
|
|
#include <test/fuzz/util.h>
|
|
|
|
#include <util/error.h>
|
2020-06-05 08:26:16 -04:00
|
|
|
#include <util/translation.h>
|
2020-04-22 09:53:50 -04:00
|
|
|
|
2020-11-12 12:06:45 -03:00
|
|
|
#include <array>
|
2020-04-22 09:53:50 -04:00
|
|
|
#include <cstdint>
|
|
|
|
#include <vector>
|
|
|
|
|
2020-11-12 12:06:45 -03:00
|
|
|
namespace {
|
|
|
|
constexpr TransactionError ALL_TRANSACTION_ERROR[] = {
|
|
|
|
TransactionError::OK,
|
|
|
|
TransactionError::MISSING_INPUTS,
|
|
|
|
TransactionError::ALREADY_IN_CHAIN,
|
|
|
|
TransactionError::P2P_DISABLED,
|
|
|
|
TransactionError::MEMPOOL_REJECTED,
|
|
|
|
TransactionError::MEMPOOL_ERROR,
|
|
|
|
TransactionError::INVALID_PSBT,
|
|
|
|
TransactionError::PSBT_MISMATCH,
|
|
|
|
TransactionError::SIGHASH_MISMATCH,
|
|
|
|
TransactionError::MAX_FEE_EXCEEDED,
|
|
|
|
};
|
|
|
|
}; // namespace
|
|
|
|
|
2020-04-22 09:53:50 -04:00
|
|
|
// The fuzzing kitchen sink: Fuzzing harness for functions that need to be
|
|
|
|
// fuzzed but a.) don't belong in any existing fuzzing harness file, and
|
|
|
|
// b.) are not important enough to warrant their own fuzzing harness file.
|
2020-12-03 12:42:49 -03:00
|
|
|
FUZZ_TARGET(kitchen_sink)
|
2020-04-22 09:53:50 -04:00
|
|
|
{
|
|
|
|
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
|
|
|
|
2020-11-12 12:06:45 -03:00
|
|
|
const TransactionError transaction_error = fuzzed_data_provider.PickValueInArray(ALL_TRANSACTION_ERROR);
|
2020-04-22 10:40:32 -04:00
|
|
|
(void)JSONRPCTransactionError(transaction_error);
|
|
|
|
(void)RPCErrorFromTransactionError(transaction_error);
|
2020-04-22 09:53:50 -04:00
|
|
|
(void)TransactionErrorString(transaction_error);
|
2020-11-12 12:06:45 -03:00
|
|
|
|
2021-01-03 14:44:02 -03:00
|
|
|
(void)StringForFeeEstimateHorizon(fuzzed_data_provider.PickValueInArray(ALL_FEE_ESTIMATE_HORIZONS));
|
2020-11-12 12:06:45 -03:00
|
|
|
|
2020-12-31 04:51:57 -03:00
|
|
|
const OutputType output_type = fuzzed_data_provider.PickValueInArray(OUTPUT_TYPES);
|
2020-11-12 12:06:45 -03:00
|
|
|
const std::string& output_type_string = FormatOutputType(output_type);
|
|
|
|
OutputType output_type_parsed;
|
|
|
|
const bool parsed = ParseOutputType(output_type_string, output_type_parsed);
|
|
|
|
assert(parsed);
|
|
|
|
assert(output_type == output_type_parsed);
|
|
|
|
(void)ParseOutputType(fuzzed_data_provider.ConsumeRandomLengthString(64), output_type_parsed);
|
|
|
|
|
|
|
|
const std::vector<uint8_t> bytes = ConsumeRandomLengthByteVector(fuzzed_data_provider);
|
|
|
|
const std::vector<bool> bits = BytesToBits(bytes);
|
|
|
|
const std::vector<uint8_t> bytes_decoded = BitsToBytes(bits);
|
|
|
|
assert(bytes == bytes_decoded);
|
2020-04-22 09:53:50 -04:00
|
|
|
}
|