Skip to content

Commit

Permalink
fuzz: sv2 template provider
Browse files Browse the repository at this point in the history
Co-Authored-By: Christopher Coverdale <chris.coverdale24@gmail.com>
  • Loading branch information
Sjors and ccdle12 committed Dec 12, 2023
1 parent 1a32a00 commit 31f9ae2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Makefile.test.include
Expand Up @@ -348,6 +348,7 @@ test_fuzz_fuzz_SOURCES = \
test/fuzz/strprintf.cpp \
test/fuzz/system.cpp \
test/fuzz/sv2_messages.cpp \
test/fuzz/sv2_template_provider.cpp \
test/fuzz/timedata.cpp \
test/fuzz/torcontrol.cpp \
test/fuzz/transaction.cpp \
Expand Down
46 changes: 46 additions & 0 deletions src/test/fuzz/sv2_template_provider.cpp
@@ -0,0 +1,46 @@
// Copyright (c) 2019-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <common/sv2_messages.h>
#include <node/sv2_template_provider.h>
#include <test/fuzz/fuzz.h>
#include <streams.h>
#include <test/util/net.h>
#include <test/util/setup_common.h>

FUZZ_TARGET(sv2_template_provider)
{
const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
const TestingSetup* setup = testing_setup.get();

std::vector<uint8_t> random_bytes{buffer.begin(), buffer.end()};

Sv2TemplateProvider template_provider{*setup->m_node.chainman, *setup->m_node.mempool};

node::Sv2NewTemplateMsg best_new_template;
node::Sv2SetNewPrevHashMsg best_prev_hash;
std::map<uint64_t, std::unique_ptr<node::CBlockTemplate>> block_cache;

auto sock = std::make_shared<StaticContentsSock>(std::string(1, 'a'));
Sv2Client client{sock};

client.m_setup_connection_confirmed = false;
auto header = node::Sv2NetHeader{node::Sv2MsgType::SETUP_CONNECTION, static_cast<uint32_t>(random_bytes.size())};
auto setup_conn = node::Sv2NetMsg(std::move(header), std::vector<uint8_t>(random_bytes));

template_provider.ProcessSv2Message(setup_conn,
client);

client.m_setup_connection_confirmed = true;
header = node::Sv2NetHeader{node::Sv2MsgType::COINBASE_OUTPUT_DATA_SIZE, static_cast<uint32_t>(random_bytes.size())};
auto coinbase_output_size = node::Sv2NetMsg(std::move(header), std::vector<uint8_t>(random_bytes));
template_provider.ProcessSv2Message(coinbase_output_size,
client);

client.m_coinbase_output_data_size_recv = true;
header = node::Sv2NetHeader{node::Sv2MsgType::SUBMIT_SOLUTION, static_cast<uint32_t>(random_bytes.size())};
auto submit_solution = node::Sv2NetMsg(std::move(header), std::vector<uint8_t>(random_bytes));
template_provider.ProcessSv2Message(submit_solution,
client);
};

0 comments on commit 31f9ae2

Please sign in to comment.