Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ test_fuzz_fuzz_SOURCES = \
test/fuzz/prevector.cpp \
test/fuzz/primitives_transaction.cpp \
test/fuzz/process_message.cpp \
test/fuzz/process_message_dash.cpp \
test/fuzz/process_messages.cpp \
test/fuzz/protocol.cpp \
test/fuzz/psbt.cpp \
Expand Down
121 changes: 121 additions & 0 deletions src/test/fuzz/process_message_dash.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Copyright (c) 2026-present The Dash Core developers
// 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 <protocol.h>
#include <script/script.h>
#include <sync.h>
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
#include <test/util/mining.h>
#include <test/util/net.h>
#include <test/util/setup_common.h>
#include <test/util/validation.h>
#include <validationinterface.h>

#include <array>
#include <memory>

namespace {
const TestingSetup* g_setup;

const std::array<const char*, 41> DASH_MESSAGE_TYPES{
NetMsgType::SPORK,
NetMsgType::GETSPORKS,
NetMsgType::DSACCEPT,
NetMsgType::DSVIN,
NetMsgType::DSFINALTX,
NetMsgType::DSSIGNFINALTX,
NetMsgType::DSCOMPLETE,
NetMsgType::DSSTATUSUPDATE,
NetMsgType::DSTX,
NetMsgType::DSQUEUE,
NetMsgType::SENDDSQUEUE,
NetMsgType::SYNCSTATUSCOUNT,
NetMsgType::MNGOVERNANCESYNC,
NetMsgType::MNGOVERNANCEOBJECT,
NetMsgType::MNGOVERNANCEOBJECTVOTE,
NetMsgType::GETMNLISTDIFF,
NetMsgType::MNLISTDIFF,
NetMsgType::QSENDRECSIGS,
NetMsgType::QFCOMMITMENT,
NetMsgType::QCONTRIB,
NetMsgType::QCOMPLAINT,
NetMsgType::QJUSTIFICATION,
NetMsgType::QPCOMMITMENT,
NetMsgType::QWATCH,
NetMsgType::QSIGSESANN,
NetMsgType::QSIGSHARESINV,
NetMsgType::QGETSIGSHARES,
NetMsgType::QBSIGSHARES,
NetMsgType::QSIGREC,
NetMsgType::QSIGSHARE,
NetMsgType::QGETDATA,
NetMsgType::QDATA,
NetMsgType::CLSIG,
NetMsgType::ISDLOCK,
NetMsgType::MNAUTH,
NetMsgType::GETHEADERS2,
NetMsgType::SENDHEADERS2,
NetMsgType::HEADERS2,
NetMsgType::GETQUORUMROTATIONINFO,
NetMsgType::QUORUMROTATIONINFO,
NetMsgType::PLATFORMBAN,
};
} // namespace

void initialize_process_message_dash()
{
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(
/*chain_name=*/CBaseChainParams::REGTEST,
/*extra_args=*/{"-txreconciliation"});
g_setup = testing_setup.get();
for (int i = 0; i < 2 * COINBASE_MATURITY; i++) {
MineBlock(g_setup->m_node, CScript() << OP_TRUE);
}
SyncWithValidationInterfaceQueue();
}

FUZZ_TARGET(process_message_dash, .init = initialize_process_message_dash)
{
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());

ConnmanTestMsg& connman = *static_cast<ConnmanTestMsg*>(g_setup->m_node.connman.get());
TestChainState& chainstate = *static_cast<TestChainState*>(&g_setup->m_node.chainman->ActiveChainstate());
SetMockTime(1610000000); // any time to successfully reset ibd
chainstate.ResetIbd();

LOCK(NetEventsInterface::g_msgproc_mutex);

CNode& p2p_node = *ConsumeNodeAsUniquePtr(fuzzed_data_provider).release();

connman.AddTestNode(p2p_node);
FillNode(fuzzed_data_provider, connman, p2p_node);

const auto mock_time = ConsumeTime(fuzzed_data_provider);
SetMockTime(mock_time);

CSerializedNetMsg net_msg;
net_msg.m_type = fuzzed_data_provider.PickValueInArray(DASH_MESSAGE_TYPES);
net_msg.data = ConsumeRandomLengthByteVector(fuzzed_data_provider, MAX_PROTOCOL_MESSAGE_LENGTH);

connman.FlushSendBuffer(p2p_node);
(void)connman.ReceiveMsgFrom(p2p_node, std::move(net_msg));

bool more_work{true};
LIMITED_WHILE(more_work, 10000)
{
p2p_node.fPauseSend = false;
try {
more_work = connman.ProcessMessagesOnce(p2p_node);
} catch (const std::ios_base::failure&) {
more_work = false;
}
g_setup->m_node.peerman->SendMessages(&p2p_node);
}
SyncWithValidationInterfaceQueue();
g_setup->m_node.connman->StopNodes();
}
1 change: 1 addition & 0 deletions test/util/data/non-backported.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ src/stacktraces.*
src/stats/*.cpp
src/stats/*.h
src/test/block_reward_reallocation_tests.cpp
src/test/fuzz/process_message_dash.cpp
src/test/bls_tests.cpp
src/test/coinjoin_*.cpp
src/test/dip0020opcodes_tests.cpp
Expand Down
Loading