2022-12-24 23:49:50 +00:00
|
|
|
// Copyright (c) 2020-2022 The Bitcoin Core developers
|
2020-01-22 20:23:48 +00:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include <consensus/consensus.h>
|
|
|
|
#include <net.h>
|
|
|
|
#include <net_processing.h>
|
2023-05-26 10:45:31 +02:00
|
|
|
#include <primitives/transaction.h>
|
2020-01-22 20:23:48 +00:00
|
|
|
#include <protocol.h>
|
|
|
|
#include <script/script.h>
|
2023-05-26 10:45:31 +02:00
|
|
|
#include <serialize.h>
|
|
|
|
#include <span.h>
|
2020-01-22 20:23:48 +00:00
|
|
|
#include <streams.h>
|
2023-05-26 10:45:31 +02:00
|
|
|
#include <sync.h>
|
2020-01-22 20:23:48 +00:00
|
|
|
#include <test/fuzz/FuzzedDataProvider.h>
|
|
|
|
#include <test/fuzz/fuzz.h>
|
2020-12-28 21:52:40 +01:00
|
|
|
#include <test/fuzz/util.h>
|
2022-11-23 16:36:58 +01:00
|
|
|
#include <test/fuzz/util/net.h>
|
2020-01-22 20:23:48 +00:00
|
|
|
#include <test/util/mining.h>
|
2020-05-10 20:12:25 -04:00
|
|
|
#include <test/util/net.h>
|
2020-01-22 20:23:48 +00:00
|
|
|
#include <test/util/setup_common.h>
|
2020-11-06 15:03:51 +01:00
|
|
|
#include <test/util/validation.h>
|
2023-04-17 22:20:59 +02:00
|
|
|
#include <util/chaintype.h>
|
2023-05-26 10:45:31 +02:00
|
|
|
#include <util/check.h>
|
|
|
|
#include <util/time.h>
|
|
|
|
#include <validation.h>
|
2020-01-22 20:23:48 +00:00
|
|
|
#include <validationinterface.h>
|
2023-05-26 10:45:31 +02:00
|
|
|
|
2020-01-22 20:23:48 +00:00
|
|
|
#include <atomic>
|
2023-05-26 10:45:31 +02:00
|
|
|
#include <cstdlib>
|
2020-01-22 20:23:48 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
2023-05-26 10:45:31 +02:00
|
|
|
#include <string_view>
|
|
|
|
#include <vector>
|
2020-01-22 20:23:48 +00:00
|
|
|
|
|
|
|
namespace {
|
2020-04-08 19:48:38 -04:00
|
|
|
const TestingSetup* g_setup;
|
2023-05-26 10:45:31 +02:00
|
|
|
std::string_view LIMIT_TO_MESSAGE_TYPE{};
|
2020-01-22 20:23:48 +00:00
|
|
|
} // namespace
|
|
|
|
|
2020-12-03 16:42:49 +01:00
|
|
|
void initialize_process_message()
|
2020-01-22 20:23:48 +00:00
|
|
|
{
|
2023-05-26 10:45:31 +02:00
|
|
|
if (const auto val{std::getenv("LIMIT_TO_MESSAGE_TYPE")}) {
|
|
|
|
LIMIT_TO_MESSAGE_TYPE = val;
|
|
|
|
Assert(std::count(getAllNetMessageTypes().begin(), getAllNetMessageTypes().end(), LIMIT_TO_MESSAGE_TYPE)); // Unknown message type passed
|
|
|
|
}
|
2021-01-12 18:23:59 +01:00
|
|
|
|
2022-12-12 11:19:02 +00:00
|
|
|
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(
|
2023-04-17 22:20:59 +02:00
|
|
|
/*chain_type=*/ChainType::REGTEST,
|
2022-12-12 11:19:02 +00:00
|
|
|
/*extra_args=*/{"-txreconciliation"});
|
2021-01-15 15:31:50 -05:00
|
|
|
g_setup = testing_setup.get();
|
2020-01-22 20:23:48 +00:00
|
|
|
for (int i = 0; i < 2 * COINBASE_MATURITY; i++) {
|
|
|
|
MineBlock(g_setup->m_node, CScript() << OP_TRUE);
|
|
|
|
}
|
|
|
|
SyncWithValidationInterfaceQueue();
|
|
|
|
}
|
|
|
|
|
2023-07-11 14:33:31 +02:00
|
|
|
FUZZ_TARGET(process_message, .init = initialize_process_message)
|
2020-01-22 20:23:48 +00:00
|
|
|
{
|
|
|
|
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
2021-01-10 16:41:52 +01:00
|
|
|
|
2021-03-23 11:04:18 +01:00
|
|
|
ConnmanTestMsg& connman = *static_cast<ConnmanTestMsg*>(g_setup->m_node.connman.get());
|
2023-08-04 16:43:39 -04:00
|
|
|
auto& chainman = static_cast<TestChainstateManager&>(*g_setup->m_node.chainman);
|
2021-01-10 16:41:52 +01:00
|
|
|
SetMockTime(1610000000); // any time to successfully reset ibd
|
2023-08-04 16:43:39 -04:00
|
|
|
chainman.ResetIbd();
|
2021-01-10 16:41:52 +01:00
|
|
|
|
2022-09-07 13:57:18 +10:00
|
|
|
LOCK(NetEventsInterface::g_msgproc_mutex);
|
|
|
|
|
2020-01-22 20:23:48 +00:00
|
|
|
const std::string random_message_type{fuzzed_data_provider.ConsumeBytesAsString(CMessageHeader::COMMAND_SIZE).c_str()};
|
|
|
|
if (!LIMIT_TO_MESSAGE_TYPE.empty() && random_message_type != LIMIT_TO_MESSAGE_TYPE) {
|
|
|
|
return;
|
|
|
|
}
|
2020-12-28 21:52:40 +01:00
|
|
|
CNode& p2p_node = *ConsumeNodeAsUniquePtr(fuzzed_data_provider).release();
|
2021-01-23 19:39:30 +01:00
|
|
|
|
2020-05-10 20:12:25 -04:00
|
|
|
connman.AddTestNode(p2p_node);
|
2022-07-11 18:07:53 +02:00
|
|
|
FillNode(fuzzed_data_provider, connman, p2p_node);
|
2020-12-28 21:52:40 +01:00
|
|
|
|
2021-01-10 16:41:52 +01:00
|
|
|
const auto mock_time = ConsumeTime(fuzzed_data_provider);
|
|
|
|
SetMockTime(mock_time);
|
|
|
|
|
2020-12-28 21:52:40 +01:00
|
|
|
// fuzzed_data_provider is fully consumed after this call, don't use it
|
2023-09-11 18:06:51 +02:00
|
|
|
DataStream random_bytes_data_stream{fuzzed_data_provider.ConsumeRemainingBytes<unsigned char>()};
|
2020-01-22 20:23:48 +00:00
|
|
|
try {
|
2020-08-29 10:31:11 +01:00
|
|
|
g_setup->m_node.peerman->ProcessMessage(p2p_node, random_message_type, random_bytes_data_stream,
|
2020-11-06 15:03:51 +01:00
|
|
|
GetTime<std::chrono::microseconds>(), std::atomic<bool>{false});
|
2020-04-24 12:29:47 +00:00
|
|
|
} catch (const std::ios_base::failure&) {
|
2020-01-22 20:23:48 +00:00
|
|
|
}
|
2022-09-13 12:22:18 +10:00
|
|
|
g_setup->m_node.peerman->SendMessages(&p2p_node);
|
2020-01-22 20:23:48 +00:00
|
|
|
SyncWithValidationInterfaceQueue();
|
2020-05-04 20:16:22 -04:00
|
|
|
g_setup->m_node.connman->StopNodes();
|
2020-01-22 20:23:48 +00:00
|
|
|
}
|