diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 20fa37f3dbc6e6..b74b929703c510 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -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 \ diff --git a/src/test/fuzz/sv2_template_provider.cpp b/src/test/fuzz/sv2_template_provider.cpp new file mode 100644 index 00000000000000..13577db94c74be --- /dev/null +++ b/src/test/fuzz/sv2_template_provider.cpp @@ -0,0 +1,59 @@ +// 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 +#include +#include +#include +#include +#include + +FUZZ_TARGET(sv2_template_provider) +{ + const auto testing_setup = MakeNoLogFileContext(); + const TestingSetup* setup = testing_setup.get(); + + std::vector 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> block_cache; + uint64_t template_id; + + auto sock = std::make_shared(std::string(1, 'a')); + Sv2Client client{sock}; + + client.m_setup_connection_confirmed = false; + auto header = node::Sv2NetHeader{node::Sv2MsgType::SETUP_CONNECTION, static_cast(random_bytes.size())}; + auto setup_conn = node::Sv2NetMsg(std::move(header), std::move(random_bytes)); + + template_provider.ProcessSv2Message(setup_conn, + client, + best_new_template, + best_prev_hash, + block_cache, + template_id); + + client.m_setup_connection_confirmed = true; + header = node::Sv2NetHeader{node::Sv2MsgType::COINBASE_OUTPUT_DATA_SIZE, static_cast(random_bytes.size())}; + auto coinbase_output_size = node::Sv2NetMsg(std::move(header), std::move(random_bytes)); + template_provider.ProcessSv2Message(coinbase_output_size, + client, + best_new_template, + best_prev_hash, + block_cache, + template_id); + + client.m_coinbase_output_data_size_recv = true; + header = node::Sv2NetHeader{node::Sv2MsgType::SUBMIT_SOLUTION, static_cast(random_bytes.size())}; + auto submit_solution = node::Sv2NetMsg(std::move(header), std::move(random_bytes)); + template_provider.ProcessSv2Message(submit_solution, + client, + best_new_template, + best_prev_hash, + block_cache, + template_id); +};