tests: tests_common library and gen_corpus executable
What changed, and why it matters
This commit adds new testing tools to Monero: a shared helper library for building test transactions and a build-time generator for fuzzing seed data. It also updates one fuzz test to exercise more transaction-validation code paths. There is no change to the live Monero network code, consensus rules, or wallet behavior—only test infrastructure.
No security action required. Treat as normal test/development infrastructure. Reviewers may optionally verify that the new helpers do not accidentally link production targets and that generated corpus files are not shipped as authoritative consensus data.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch introduces tests/tests_common (shared tx-construction helpers) and tests/fuzz/gen_corpus (a build-time executable that creates seed corpora for fuzzers). It adds MAX_HF_VERSION in cryptonote_config.h, wires the new directories into CMake, and extends tests/fuzz/transaction.cpp so the fuzzer parses a leading hard-fork byte and calls prevalidate_miner_transaction() plus ver_non_input_consensus(). All new code is under tests/ and is not compiled into production binaries.
Changed components
tests/tests_commontests/fuzz/gen_corpustests/fuzz/transaction.cppsrc/cryptonote_config.h (single constant MAX_HF_VERSION)Inspect captured patch +1133 / −4
### src/cryptonote_config.h
@@ -194,6 +194,7 @@
#define HF_VERSION_BULLETPROOF_PLUS 15
#define HF_VERSION_VIEW_TAGS 15
#define HF_VERSION_2021_SCALING 15
+#define MAX_HF_VERSION 16 // max version supported by code, not necessarily activated/enabled
#define PER_KB_FEE_QUANTIZATION_DECIMALS 8
#define CRYPTONOTE_SCALING_2021_FEE_ROUNDING_PLACES 2
### tests/CMakeLists.txt
@@ -47,6 +47,8 @@ set(GTEST_LIBRARIES gtest gtest_main)
message(STATUS "Copying test data directory...")
file(COPY data DESTINATION .) # Copy data directory from source root to build root
+add_subdirectory(tests_common)
+
if (CMAKE_BUILD_TYPE STREQUAL "fuzz" OR OSSFUZZ)
add_subdirectory(fuzz)
else ()
### tests/data/fuzz/transaction/TX1
[binary or diff unavailable]
### tests/data/fuzz/transaction/TX2
[binary or diff unavailable]
### tests/fuzz/CMakeLists.txt
@@ -26,6 +26,8 @@
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+add_subdirectory(gen_corpus)
+
if(OSSFUZZ)
# Add the include path for <fuzzer/FuzzedDataProvider.h>
include_directories(${CMAKE_SOURCE_DIR}/tests/fuzz/include)
### tests/fuzz/gen_corpus/CMakeLists.txt
@@ -0,0 +1,48 @@
+# Copyright (c) 2026, The Monero Project
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without modification, are
+# permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice, this list of
+# conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice, this list
+# of conditions and the following disclaimer in the documentation and/or other
+# materials provided with the distribution.
+#
+# 3. Neither the name of the copyright holder nor the names of its contributors may be
+# used to endorse or promote products derived from this software without specific
+# prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+monero_add_minimal_executable(gen_corpus
+ gen_corpus.cpp
+ main.cpp
+ transaction.cpp)
+target_link_libraries(gen_corpus
+ PRIVATE
+ common
+ cryptonote_core
+ epee
+ tests_common
+ ${OPENSSL_LIBRARIES}
+ ${EXTRA_LIBRARIES})
+target_compile_definitions(gen_corpus
+ PRIVATE
+ GEN_CORPUS_DEFAULT_DATA_DIR="${TEST_DATA_DIR}/fuzz")
+
+add_custom_command(COMMAND gen_corpus --force
+ TARGET gen_corpus POST_BUILD
+ VERBATIM
+ COMMENT "Generating fuzz tests seed corpora")
### tests/fuzz/gen_corpus/README.md
@@ -0,0 +1,6 @@
+# Dynamic Seed Corpus Generator
+
+This directory contains source code to build a program which generates seed corpus data dynamically.
+It should be used during the fuzzer build stage, before running the fuzzers. In the OSS-Fuzz
+platform, the resultant data should be zipped into seed corpus files, one for each fuzzer. Outside
+of OSS-Fuzz, these seed corpus paths can be passed directly to the individual fuzzing programs.
### tests/fuzz/gen_corpus/gen_corpus.cpp
@@ -0,0 +1,106 @@
+// Copyright (c) 2026, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "gen_corpus.h"
+
+#include "misc_log_ex.h"
+#include "scope_guard.h"
+
+#include <list>
+#include <memory>
+#include <stdexcept>
+
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "fuzz"
+
+namespace fuzz
+{
+
+seed_corpus_source_single::seed_corpus_source_single()
+ : m_did_set_seed_corpus(false), m_sink(nullptr)
+{}
+
+void seed_corpus_source_single::gen_corpus(seed_corpus_sink &sink)
+{
+ if (this->m_did_set_seed_corpus || this->m_sink)
+ throw std::logic_error("seed_corpus_source_single::gen_corpus is not re-entrant");
+
+ const epee::scope_guard clear_on_exit([this](){
+ this->m_did_set_seed_corpus = false;
+ this->m_sink = nullptr;
+ });
+
+ MINFO("Generating corpus " << this->get_fuzzer_name() << "/" << this->get_seed_corpus_name() << "...");
+
+ this->m_sink = &sink;
+ this->gen_corpus_single();
+
+ if (!this->m_did_set_seed_corpus)
+ throw std::logic_error("Seed corpus was never set in body");
+}
+
+void seed_corpus_source_single::set_seed_corpus(const unsigned char * seed_corpus_buf, std::size_t seed_corpus_len)
+{
+ if (!this->m_sink)
+ throw std::logic_error("seed_corpus_source_single::set_seed_corpus called while not generating");
+ else if (this->m_did_set_seed_corpus)
+ throw std::logic_error("seed_corpus_source_single::set_seed_corpus called more than once per generation");
+
+ this->m_sink->send_seed_corpus(this->get_fuzzer_name(),
+ this->get_seed_corpus_name(),
+ seed_corpus_buf,
+ seed_corpus_len);
+ this->m_did_set_seed_corpus = true;
+}
+
+namespace registry
+{
+namespace
+{
+std::list<std::unique_ptr<seed_corpus_source>> &get_registry()
+{
+ static std::list<std::unique_ptr<seed_corpus_source>> instance;
+ return instance;
+}
+} //anonymous namespace
+
+registry_entry_t register_seed_corpus_source(seed_corpus_source * src)
+{
+ get_registry().emplace_back(src);
+ return {};
+}
+
+void dispatch_all_registered_seed_corpus_sources(seed_corpus_sink &sink)
+{
+ for (auto &src : get_registry())
+ src->gen_corpus(sink);
+}
+
+} //namespace registry
+
+} //namespace fuzz
### tests/fuzz/gen_corpus/gen_corpus.h
@@ -0,0 +1,119 @@
+// Copyright (c) 2026, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#pragma once
+
+#include <cstddef>
+
+#define SEED_CORPUS_N(fuzzer_name, seed_corpus_name, cls_name) \
+ class cls_name : public ::fuzz::seed_corpus_source_single \
+ { \
+ protected: \
+ const char * get_fuzzer_name() const override { return #fuzzer_name; }; \
+ const char * get_seed_corpus_name() const override { return #seed_corpus_name; }; \
+ void gen_corpus_single() override; \
+ private: \
+ [[maybe_unused]] static ::fuzz::registry::registry_entry_t registry_entry; \
+ }; \
+ ::fuzz::registry::registry_entry_t cls_name :: registry_entry = \
+ ::fuzz::registry::register_seed_corpus_source(new cls_name()); \
+ void cls_name :: gen_corpus_single() \
+
+#define SEED_CORPUS(fuzzer_name, seed_corpus_name) \
+ SEED_CORPUS_N(fuzzer_name, seed_corpus_name, gen_seed_corpus_ ## fuzzer_name ## _ ## seed_corpus_name)
+
+#define SET_SEED_CORPUS(seed_corpus_buf, seed_corpus_len) this->set_seed_corpus(seed_corpus_buf, seed_corpus_len)
+
+namespace fuzz
+{
+
+/**
+ * @brief Interface to consume seed corpora
+ */
+class seed_corpus_sink
+{
+public:
+ virtual void send_seed_corpus(const char * fuzzer_name,
+ const char * seed_corpus_name,
+ const unsigned char * seed_corpus_buf,
+ std::size_t seed_corpus_len) = 0;
+
+ virtual ~seed_corpus_sink() = default;
+};
+
+/**
+ * @brief Interface to generate seed corpora
+ */
+class seed_corpus_source
+{
+public:
+ virtual void gen_corpus(seed_corpus_sink &sink) = 0;
+
+ virtual ~seed_corpus_source() = default;
+};
+
+/**
+ * @brief Abstract class which generates a single seed corpus, used by macros SEED_CORPUS() and SET_SEED_CORPUS()
+ */
+class seed_corpus_source_single: public seed_corpus_source
+{
+public:
+ seed_corpus_source_single();
+
+ void gen_corpus(seed_corpus_sink &sink) override;
+
+protected:
+ virtual const char * get_fuzzer_name() const = 0;
+ virtual const char * get_seed_corpus_name() const = 0;
+ virtual void gen_corpus_single() = 0;
+
+ void set_seed_corpus(const unsigned char * seed_corpus_buf, std::size_t seed_corpus_len);
+
+private:
+ bool m_did_set_seed_corpus;
+ seed_corpus_sink * m_sink;
+};
+
+namespace registry
+{
+struct registry_entry_t {};
+/**
+ * @brief Add seed corpus source to static registry
+ * @param src Pointer to a seed corpus source (takes ownership)
+ * @note Entry is not thread-safe, only call from the main thread
+ */
+registry_entry_t register_seed_corpus_source(seed_corpus_source * src);
+
+/**
+ * @brief Run all sources passed to `register_seed_corpus_source()` against given `sink`
+ * @note Entry is not thread-safe, only call from the main thread
+ */
+void dispatch_all_registered_seed_corpus_sources(seed_corpus_sink &sink);
+} //namespace registry
+
+} //namespace fuzz
### tests/fuzz/gen_corpus/main.cpp
@@ -0,0 +1,178 @@
+// Copyright (c) 2026, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "gen_corpus.h"
+
+#include "common/command_line.h"
+#include "common/util.h"
+#include "hex.h"
+#include "misc_log_ex.h"
+#include "string_tools.h"
+
+#include <iostream>
+#include <filesystem>
+#include <fstream>
+#include <openssl/evp.h>
+#include <string>
+
+namespace po = boost::program_options;
+
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "fuzz"
+
+namespace
+{
+std::string sha1_hex(const void *data, size_t len)
+{
+ unsigned char md[20];
+ unsigned int md_len = sizeof(md);
+ EVP_Digest(data, len, md, &md_len, EVP_sha1(), nullptr);
+
+ return epee::to_hex::string(md);
+}
+
+class FileSeedCorpusSink: public fuzz::seed_corpus_sink
+{
+public:
+ FileSeedCorpusSink(std::filesystem::path fuzz_data_dir, bool overwrite_existing):
+ m_fuzz_data_dir(fuzz_data_dir),
+ m_overwrite_existing(overwrite_existing)
+ {
+ if (!std::filesystem::exists(m_fuzz_data_dir))
+ std::filesystem::create_directories(m_fuzz_data_dir);
+ }
+
+ void send_seed_corpus(const char * fuzzer_name,
+ const char * seed_corpus_name,
+ const unsigned char * seed_corpus_buf,
+ std::size_t seed_corpus_len) override
+ {
+ std::filesystem::create_directories(m_fuzz_data_dir / fuzzer_name);
+
+ const std::filesystem::path seed_corpus_path = m_fuzz_data_dir / fuzzer_name / seed_corpus_name;
+ if (!m_overwrite_existing && std::filesystem::exists(seed_corpus_path))
+ throw std::runtime_error(std::string("File ") + seed_corpus_path.string() + " already exists");
+
+ std::ofstream ofs(seed_corpus_path, std::ios_base::binary | std::ios_base::out);
+ ofs.write(reinterpret_cast<const char*>(seed_corpus_buf), seed_corpus_len);
+ ofs.close();
+ if (!ofs.good())
+ throw std::runtime_error("Could not write seed corpus to file: " + seed_corpus_path.string());
+
+ const std::string corpus_full_name = std::string(fuzzer_name) + "/" + seed_corpus_name;
+ m_generated_sha1s.emplace(corpus_full_name, sha1_hex(seed_corpus_buf, seed_corpus_len));
+ }
+
+ void dump_sha1s() const
+ {
+ size_t longest_name = 0;
+ for (const auto &p : m_generated_sha1s)
+ longest_name = std::max(longest_name, p.first.size());
+
+ MINFO("Seed corpus SHA1 hashes:");
+ for (const auto &p : m_generated_sha1s)
+ {
+ std::string padded_name = p.first;
+ padded_name.resize(longest_name, ' ');
+ MINFO(padded_name << " - " << p.second);
+ }
+ }
+
+ ~FileSeedCorpusSink()
+ {
+ try { dump_sha1s(); }
+ catch (...) {}
+ }
+
+private:
+ std::filesystem::path m_fuzz_data_dir;
+ bool m_overwrite_existing;
+ std::map<std::string, std::string> m_generated_sha1s;
+};
+
+} //anonymous namespace
+
+int main(int argc, const char * const argv[])
+{
+ try
+ {
+ tools::on_startup();
+ epee::string_tools::set_module_name_and_folder(argv[0]);
+ mlog_configure(mlog_get_default_log_path("gen_corpus.log"), true);
+
+ po::options_description desc_options("Command line options");
+ const command_line::arg_descriptor<std::string> arg_data_dir = {
+ "data-dir",
+ "Data files directory",
+ GEN_CORPUS_DEFAULT_DATA_DIR};
+ const command_line::arg_descriptor<std::string> arg_log_level = {
+ "log-level",
+ "0-4 or categories",
+ ""};
+ const command_line::arg_descriptor<bool> arg_force = {
+ "force",
+ "Overwrite existing corpus files",
+ false
+ };
+ command_line::add_arg(desc_options, arg_data_dir);
+ command_line::add_arg(desc_options, arg_log_level);
+ command_line::add_arg(desc_options, arg_force);
+
+ po::variables_map vm;
+ bool r = command_line::handle_error_helper(desc_options, [&]()
+ {
+ po::store(po::parse_command_line(argc, argv, desc_options), vm);
+ po::notify(vm);
+ return true;
+ });
+ if (!r)
+ return 1;
+
+ // set the log level
+ if (!command_line::is_arg_defaulted(vm, arg_log_level))
+ mlog_set_log(command_line::get_arg(vm, arg_log_level).c_str());
+ else
+ mlog_set_log(MONERO_DEFAULT_LOG_CATEGORY ":INFO");
+
+ // get the data dir
+ const std::string data_dir = command_line::get_arg(vm, arg_data_dir);
+ MINFO("Writing fuzzing seed corpus files to: " << data_dir);
+ const bool overwrite_existing = command_line::get_arg(vm, arg_force);
+
+ // run seed corpus generation
+ FileSeedCorpusSink seed_corpus_sink(data_dir, overwrite_existing);
+ ::fuzz::registry::dispatch_all_registered_seed_corpus_sources(seed_corpus_sink);
+
+ return 0;
+ }
+ catch (const std::exception &e)
+ {
+ std::cerr << "Exception caught in main(): " << e.what() << std::endl;
+ return 1;
+ }
+}
### tests/fuzz/gen_corpus/transaction.cpp
@@ -0,0 +1,119 @@
+// Copyright (c) 2026, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "cryptonote_basic/blobdatatype.h"
+#include "cryptonote_basic/cryptonote_basic_impl.h"
+#include "gen_corpus.h"
+#include "misc_log_ex.h"
+#include "tests_common/tx_construction_helpers.h"
+
+/**
+ * `transaction` seed corpus format:
+ *
+ * first byte: hard fork version to verify tx against
+ * rest of the bytes: serialized transaction blob
+ */
+
+/// Generates a seed corpus with above format. Transactions are either 1-out
+/// coinbase or 1-in,2-out non-coinbase
+#define TX_SEED_CORPUS(name, is_coinbase, hf_version, ...) \
+ SEED_CORPUS(transaction, name) \
+ { \
+ const cryptonote::transaction tx = gen_tx<is_coinbase>(hf_version \
+ ,##__VA_ARGS__); \
+ const cryptonote::blobdata tx_blob = cryptonote::tx_to_blob(tx); \
+ std::vector<unsigned char> corpus(tx_blob.size() + 1); \
+ corpus[0] = hf_version; \
+ memcpy(corpus.data() + 1, tx_blob.data(), tx_blob.size()); \
+ SET_SEED_CORPUS(corpus.data(), corpus.size()); \
+ } \
+
+namespace
+{
+cryptonote::account_public_address get_core_donation_address()
+{
+ const std::string address =
+ "888tNkZrPN6JsEgekjMnABU4TBzc2Dt29EPAvkRxbANsAnjyPbb3iQ1YBRk1UXcdRsiKc9dhwMVgN5S9cQUiyoogDavup3H";
+ cryptonote::address_parse_info parsed_address;
+ bool r = cryptonote::get_account_address_from_str(parsed_address, cryptonote::MAINNET, address);
+ CHECK_AND_ASSERT_THROW_MES(r, "Failed to parse GF address");
+ return parsed_address.address;
+}
+
+cryptonote::transaction gen_miner_tx(const std::uint8_t hf_version)
+{
+ const cryptonote::account_public_address miner_address = get_core_donation_address();
+
+ constexpr size_t height = 999999;
+ constexpr rct::xmr_amount reward = 2 * COIN;
+
+ return mock::construct_miner_tx_with_reward(height, reward, miner_address, hf_version);
+}
+
+cryptonote::transaction gen_non_miner_tx(const std::uint8_t hf_version, const bool sweep_unmixable_override = false)
+{
+ std::vector<cryptonote::tx_destination_entry> destinations{
+ {cryptonote::tx_destination_entry(COIN, get_core_donation_address(), false)},
+ {cryptonote::tx_destination_entry(COIN, get_core_donation_address(), false)}};
+ return mock::construct_pre_carrot_tx_with_fake_inputs(destinations,
+ COIN / 100, hf_version, sweep_unmixable_override);
+}
+
+template <bool is_coinbase, typename... Args>
+cryptonote::transaction gen_tx(const std::uint8_t hf_version, Args&&... args)
+{
+ if constexpr (is_coinbase)
+ return gen_miner_tx(hf_version, args...);
+ else
+ return gen_non_miner_tx(hf_version, args...);
+}
+} //anonymous namespace
+
+TX_SEED_CORPUS(coinbase_v1, true, 1)
+
+TX_SEED_CORPUS(v1, false, 1)
+
+TX_SEED_CORPUS(v1_viewtagged, false, HF_VERSION_VIEW_TAGS, true)
+
+TX_SEED_CORPUS(coinbase_v2, true, HF_VERSION_DYNAMIC_FEE)
+
+TX_SEED_CORPUS(coinbase_v2_vt, true, HF_VERSION_VIEW_TAGS)
+
+TX_SEED_CORPUS(v2_mlsag_full, false, HF_VERSION_DYNAMIC_FEE)
+
+/// @TODO: v2_mlsag_simple
+
+TX_SEED_CORPUS(v2_bp, false, HF_VERSION_PER_BYTE_FEE)
+
+TX_SEED_CORPUS(v2_bp_short, false, HF_VERSION_SMALLER_BP)
+
+TX_SEED_CORPUS(v2_clsag, false, HF_VERSION_CLSAG)
+
+TX_SEED_CORPUS(v2_bpp, false, HF_VERSION_BULLETPROOF_PLUS)
+
+static_assert(MAX_HF_VERSION == 16, "Add FCMP++ corpora here");
### tests/fuzz/transaction.cpp
@@ -26,17 +26,53 @@
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#include "include_base_utils.h"
-#include "file_io_utils.h"
+#define IN_UNIT_TESTS
#include "cryptonote_basic/blobdatatype.h"
#include "cryptonote_basic/cryptonote_basic.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
+#include "cryptonote_core/blockchain.h"
+#include "cryptonote_core/tx_verification_utils.h"
#include "fuzzer.h"
BEGIN_INIT_SIMPLE_FUZZER()
END_INIT_SIMPLE_FUZZER()
+/**
+ * `transaction` seed corpus format:
+ *
+ * first byte: hard fork version to verify tx against
+ * rest of the bytes: serialized transaction blob
+ */
+
BEGIN_SIMPLE_FUZZER()
- cryptonote::transaction tx{};
- parse_and_validate_tx_from_blob(std::string((const char*)buf, len), tx);
+ size_t len_ = len;
+
+ // pull hf_version as first byte
+ std::uint8_t hf_version{};
+ if (len_ > 0)
+ {
+ hf_version = *buf;
+ --len_;
+ ++buf;
+ }
+
+ // parse and validate tx from rest of buffer
+ cryptonote::transaction tx;
+ if (!parse_and_validate_tx_from_blob(std::string((const char*)buf, len_), tx))
+ return 0;
+
+ // get coinbase height
+ std::uint64_t coinbase_height{};
+ if (1 == tx.vin.size())
+ {
+ const cryptonote::txin_gen *in_gen = boost::strict_get<cryptonote::txin_gen>(tx.vin.data());
+ if (in_gen) coinbase_height = in_gen->height;
+ }
+
+ // run tx through verification functions
+ cryptonote::block b;
+ b.miner_tx = tx;
+ cryptonote::Blockchain::prevalidate_miner_transaction(b, coinbase_height, hf_version);
+ cryptonote::tx_verification_context tvc{};
+ cryptonote::ver_non_input_consensus(tx, tvc, hf_version);
END_SIMPLE_FUZZER()
### tests/tests_common/CMakeLists.txt
@@ -0,0 +1,35 @@
+# Copyright (c) 2026, The Monero Project
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without modification, are
+# permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice, this list of
+# conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice, this list
+# of conditions and the following disclaimer in the documentation and/or other
+# materials provided with the distribution.
+#
+# 3. Neither the name of the copyright holder nor the names of its contributors may be
+# used to endorse or promote products derived from this software without specific
+# prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+add_library(tests_common
+ src/tx_construction_helpers.cpp)
+target_link_libraries(tests_common
+ PUBLIC
+ cncrypto
+ cryptonote_core)
+target_include_directories(tests_common PUBLIC include)
### tests/tests_common/include/tests_common/tx_construction_helpers.h
@@ -0,0 +1,107 @@
+// Copyright (c) 2025, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#pragma once
+
+//local headers
+#include "cryptonote_core/cryptonote_tx_utils.h"
+
+//third party headers
+
+//standard headers
+
+//forward declarations
+
+namespace mock
+{
+//----------------------------------------------------------------------------------------------------------------------
+//----------------------------------------------------------------------------------------------------------------------
+cryptonote::transaction construct_miner_tx_with_reward(const size_t height,
+ const rct::xmr_amount reward,
+ const cryptonote::account_public_address &miner_address,
+ const uint8_t hf_version);
+//----------------------------------------------------------------------------------------------------------------------
+//----------------------------------------------------------------------------------------------------------------------
+struct stripped_down_tx_source_entry_t
+{
+ bool is_rct;
+ uint64_t global_output_index;
+ crypto::public_key onetime_address;
+ crypto::public_key real_out_tx_key;
+ std::vector<crypto::public_key> real_out_additional_tx_keys;
+ size_t local_output_index;
+ rct::xmr_amount amount;
+ rct::key mask;
+};
+//----------------------------------------------------------------------------------------------------------------------
+//----------------------------------------------------------------------------------------------------------------------
+cryptonote::tx_source_entry gen_tx_source_entry_fake_members(
+ const stripped_down_tx_source_entry_t &in,
+ const size_t mixin,
+ const uint64_t max_global_output_index);
+//----------------------------------------------------------------------------------------------------------------------
+//----------------------------------------------------------------------------------------------------------------------
+cryptonote::transaction construct_pre_carrot_tx_with_fake_inputs(
+ const cryptonote::account_keys &sender_account_keys,
+ const std::unordered_map<crypto::public_key, cryptonote::subaddress_index> &sender_subaddress_map,
+ std::vector<stripped_down_tx_source_entry_t> &&stripped_sources,
+ std::vector<cryptonote::tx_destination_entry> &destinations,
+ const boost::optional<cryptonote::account_public_address> &change_addr,
+ const crypto::hash &payment_id,
+ const rct::xmr_amount fee,
+ const uint8_t hf_version,
+ crypto::secret_key &main_tx_privkey_out,
+ std::vector<crypto::secret_key> &additional_tx_privkeys_out,
+ const bool sweep_unmixable_override = false);
+//----------------------------------------------------------------------------------------------------------------------
+//----------------------------------------------------------------------------------------------------------------------
+cryptonote::transaction construct_pre_carrot_tx_with_fake_inputs(
+ const cryptonote::account_keys &sender_account_keys,
+ const std::unordered_map<crypto::public_key, cryptonote::subaddress_index> &sender_subaddress_map,
+ std::vector<stripped_down_tx_source_entry_t> &&stripped_sources,
+ std::vector<cryptonote::tx_destination_entry> &destinations,
+ const boost::optional<cryptonote::account_public_address> &change_addr,
+ const rct::xmr_amount fee,
+ const uint8_t hf_version,
+ const bool sweep_unmixable_override = false);
+//----------------------------------------------------------------------------------------------------------------------
+//----------------------------------------------------------------------------------------------------------------------
+cryptonote::transaction construct_pre_carrot_tx_with_fake_inputs(
+ std::vector<cryptonote::tx_destination_entry> &destinations,
+ const rct::xmr_amount fee,
+ const uint8_t hf_version,
+ const bool sweep_unmixable_override = false);
+//----------------------------------------------------------------------------------------------------------------------
+//----------------------------------------------------------------------------------------------------------------------
+static constexpr rct::xmr_amount fake_fee_per_weight = 2023;
+//----------------------------------------------------------------------------------------------------------------------
+//----------------------------------------------------------------------------------------------------------------------
+extern const cryptonote::account_public_address null_addr;
+//----------------------------------------------------------------------------------------------------------------------
+//----------------------------------------------------------------------------------------------------------------------
+} //namespace mock
### tests/tests_common/src/tx_construction_helpers.cpp
@@ -0,0 +1,370 @@
+// Copyright (c) 2025-2026, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+//paired header
+#include "tests_common/tx_construction_helpers.h"
+
+//local headers
+#include "crypto/generators.h"
+
+//third party headers
+#include <boost/numeric/conversion/cast.hpp>
+
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "tests"
+
+namespace mock
+{
+//----------------------------------------------------------------------------------------------------------------------
+cryptonote::transaction construct_miner_tx_with_reward(const size_t height,
+ const rct::xmr_amount reward,
+ const cryptonote::account_public_address &miner_address,
+ const uint8_t hf_version)
+{
+ constexpr rct::xmr_amount already_generated_coins = 10000 * COIN;
+ constexpr size_t max_outs = 999;
+
+ const size_t median_weight = cryptonote::get_min_block_weight(hf_version);
+ const size_t weight_limit = 2 * median_weight;
+ const cryptonote::blobdata extra_nonce;
+
+ cryptonote::transaction tx;
+ size_t cumulative_tx_weight = median_weight * 9 / 10;
+ size_t current_block_weight = cumulative_tx_weight;
+ rct::xmr_amount fee = reward;
+ bool r = cryptonote::construct_miner_tx(height, median_weight, already_generated_coins,
+ current_block_weight, fee, miner_address, tx, extra_nonce, max_outs, hf_version);
+ size_t attempts = 0;
+ CHECK_AND_ASSERT_THROW_MES(r, "Coinbase transaction failed on first try");
+ while (
+ !r
+ || cumulative_tx_weight + cryptonote::get_transaction_weight(tx) != current_block_weight
+ || cryptonote::get_outs_money_amount(tx) != reward)
+ {
+ CHECK_AND_ASSERT_THROW_MES(attempts++ < 100, "too many attempts to construct miner tx");
+
+ // adjustments
+ const uint64_t coinbase_weight = cryptonote::get_transaction_weight(tx);
+ const rct::xmr_amount actual_reward = cryptonote::get_outs_money_amount(tx);
+ if (!r || cumulative_tx_weight + coinbase_weight > current_block_weight)
+ cumulative_tx_weight = cumulative_tx_weight * 19 / 20;
+ else
+ cumulative_tx_weight = current_block_weight - coinbase_weight;
+ if (r)
+ {
+ CHECK_AND_ASSERT_THROW_MES(actual_reward >= fee, "logic error in coinbase reward adjustment");
+ if (actual_reward > reward)
+ {
+ if (fee >= (actual_reward - reward))
+ fee -= (actual_reward - reward);
+ else
+ cumulative_tx_weight = (cumulative_tx_weight + weight_limit + 1) / 2;
+ }
+ else
+ fee += (reward - actual_reward);
+ }
+
+ // re-make with new params
+ current_block_weight = cumulative_tx_weight + coinbase_weight;
+ r = cryptonote::construct_miner_tx(height, median_weight, already_generated_coins,
+ current_block_weight, fee, miner_address, tx, extra_nonce, max_outs, hf_version);
+ }
+
+ CHECK_AND_ASSERT_THROW_MES((tx.version >= 2) == (hf_version >= HF_VERSION_DYNAMIC_FEE), "wrong tx version");
+ CHECK_AND_ASSERT_THROW_MES(!tx.vout.empty(), "tx empty");
+ CHECK_AND_ASSERT_THROW_MES(cryptonote::check_output_types(tx, hf_version), "wrong tx out type");
+ CHECK_AND_ASSERT_THROW_MES(tx.unlock_time == height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW, "wrong tx unlock time");
+ CHECK_AND_ASSERT_THROW_MES(boost::get<cryptonote::txin_gen>(tx.vin.at(0)).height == height, "tx wrong height");
+
+ return tx;
+}
+//----------------------------------------------------------------------------------------------------------------------
+cryptonote::tx_source_entry gen_tx_source_entry_fake_members(
+ const stripped_down_tx_source_entry_t &in,
+ const size_t mixin,
+ const uint64_t max_global_output_index)
+{
+ const size_t ring_size = mixin + 1;
+
+ CHECK_AND_ASSERT_THROW_MES(in.global_output_index <= max_global_output_index,
+ "real global output index too high");
+ CHECK_AND_ASSERT_THROW_MES(max_global_output_index + 1 >= ring_size,
+ "not enough global output indices for mixin");
+
+ cryptonote::tx_source_entry res;
+
+ // populate ring with fake data
+ std::unordered_set<uint64_t> used_indices;
+ res.outputs.reserve(mixin + 1);
+ res.outputs.push_back(
+ {in.global_output_index,
+ { rct::pk2rct(in.onetime_address), rct::commit(in.amount, in.mask) }});
+ used_indices.insert(in.global_output_index);
+ while (res.outputs.size() < ring_size)
+ {
+ const uint64_t global_output_index = crypto::rand_range<uint64_t>(0, max_global_output_index);
+ if (used_indices.count(global_output_index))
+ continue;
+ used_indices.insert(global_output_index);
+ const rct::ctkey output_pair{rct::pkGen(),
+ in.is_rct ? rct::pkGen() : rct::zeroCommitVartime(in.amount)};
+ res.outputs.push_back({global_output_index, output_pair});
+ }
+ // sort by index
+ std::sort(res.outputs.begin(), res.outputs.end(), [](const auto &a, const auto &b) -> bool {
+ return a.first < b.first;
+ });
+
+ // real_output
+ res.real_output = 0;
+ while (res.outputs.at(res.real_output).second.dest != in.onetime_address)
+ ++res.real_output;
+
+ // copy from in
+ res.rct = in.is_rct;
+ res.real_out_tx_key = in.real_out_tx_key;
+ res.real_out_additional_tx_keys = in.real_out_additional_tx_keys;
+ res.real_output_in_tx_index = in.local_output_index;
+ res.amount = in.amount;
+ res.mask = in.mask;
+
+ return res;
+}
+//----------------------------------------------------------------------------------------------------------------------
+cryptonote::transaction construct_pre_carrot_tx_with_fake_inputs(
+ const cryptonote::account_keys &sender_account_keys,
+ const std::unordered_map<crypto::public_key, cryptonote::subaddress_index> &sender_subaddress_map,
+ std::vector<stripped_down_tx_source_entry_t> &&stripped_sources,
+ std::vector<cryptonote::tx_destination_entry> &destinations,
+ const boost::optional<cryptonote::account_public_address> &change_addr,
+ const crypto::hash &payment_id,
+ const rct::xmr_amount fee,
+ const uint8_t hf_version,
+ crypto::secret_key &main_tx_privkey_out,
+ std::vector<crypto::secret_key> &additional_tx_privkeys_out,
+ const bool sweep_unmixable_override)
+{
+ // derive config from hf version
+ const bool rct = hf_version >= HF_VERSION_DYNAMIC_FEE && !sweep_unmixable_override;
+ rct::RCTConfig rct_config;
+ switch (hf_version)
+ {
+ case 1:
+ case 2:
+ case 3:
+ case HF_VERSION_DYNAMIC_FEE:
+ case 5:
+ case HF_VERSION_MIN_MIXIN_4:
+ case 7:
+ rct_config = { rct::RangeProofBorromean, 0 };
+ break;
+ case HF_VERSION_PER_BYTE_FEE:
+ case 9:
+ rct_config = { rct::RangeProofPaddedBulletproof, 1 };
+ break;
+ case HF_VERSION_SMALLER_BP:
+ case 11:
+ case HF_VERSION_MIN_2_OUTPUTS:
+ rct_config = { rct::RangeProofPaddedBulletproof, 2 };
+ break;
+ case HF_VERSION_CLSAG:
+ case 14:
+ rct_config = { rct::RangeProofPaddedBulletproof, 3 };
+ break;
+ case HF_VERSION_BULLETPROOF_PLUS:
+ case 16:
+ rct_config = { rct::RangeProofPaddedBulletproof, 4 };
+ break;
+ default:
+ ASSERT_MES_AND_THROW("unrecognized hf version");
+ }
+ const bool use_view_tags = hf_version >= HF_VERSION_VIEW_TAGS;
+ const size_t mixin = 15;
+ const uint64_t max_global_output_index = 1000000;
+
+ // count missing money and balance if necessary
+ boost::multiprecision::int128_t missing_money = fee;
+ for (const cryptonote::tx_destination_entry &destination : destinations)
+ missing_money += destination.amount;
+ for (const stripped_down_tx_source_entry_t &stripped_source : stripped_sources)
+ missing_money -= stripped_source.amount;
+ if (missing_money > 0)
+ {
+ CHECK_AND_ASSERT_THROW_MES(missing_money <= std::numeric_limits<rct::xmr_amount>::max(),
+ "missing money overflow");
+
+ const rct::xmr_amount missing_money64 = boost::numeric_cast<rct::xmr_amount>(missing_money);
+
+ hw::device &hwdev = hw::get_device("default");
+ cryptonote::keypair main_tx_keypair = cryptonote::keypair::generate(hwdev);
+
+ std::vector<crypto::public_key> dummy_additional_tx_public_keys;
+ std::vector<rct::key> amount_keys;
+ crypto::public_key input_onetime_address;
+ crypto::view_tag vt;
+ const bool r = hwdev.generate_output_ephemeral_keys(rct ? 2 : 1,
+ cryptonote::account_keys(),
+ main_tx_keypair.pub,
+ main_tx_keypair.sec,
+ cryptonote::tx_destination_entry(missing_money64, sender_account_keys.m_account_address, false),
+ boost::none,
+ /*output_index=*/0,
+ /*need_additional_txkeys=*/false,
+ /*additional_tx_keys=*/{},
+ dummy_additional_tx_public_keys,
+ amount_keys,
+ input_onetime_address,
+ use_view_tags,
+ vt);
+ CHECK_AND_ASSERT_THROW_MES(r, "failed to generate balancing input");
+
+ const stripped_down_tx_source_entry_t balancing_in{
+ .is_rct = rct,
+ .global_output_index = crypto::rand_range<uint64_t>(0, max_global_output_index),
+ .onetime_address = input_onetime_address,
+ .real_out_tx_key = main_tx_keypair.pub,
+ .real_out_additional_tx_keys = {},
+ .local_output_index = 0,
+ .amount = missing_money64,
+ .mask = rct ? rct::genCommitmentMask(amount_keys.at(0)) : rct::I
+ };
+
+ stripped_sources.push_back(balancing_in);
+ }
+
+ // populate random sources
+ std::vector<cryptonote::tx_source_entry> sources;
+ sources.reserve(stripped_sources.size());
+ for (const auto &stripped_source : stripped_sources)
+ sources.push_back(gen_tx_source_entry_fake_members(stripped_source,
+ mixin,
+ max_global_output_index));
+
+ // construct tx
+ cryptonote::transaction tx;
+
+ // count integrated addresses and check <= 1
+ size_t num_integrated = 0;
+ for (const cryptonote::tx_destination_entry &dst : destinations)
+ num_integrated += dst.is_integrated;
+ CHECK_AND_ASSERT_THROW_MES(num_integrated <= 1, "max 1 integrated address allowed");
+
+ // make put unencrypted payment_id in tx_extra
+ std::vector<uint8_t> extra;
+ if (payment_id != crypto::null_hash)
+ {
+ const bool is_long_payment_id = memcmp(payment_id.data + 8, crypto::null_hash.data, 32 - 8);
+ if (!is_long_payment_id && !num_integrated)
+ MWARNING("Short payment ID provided but no destination marked as integrated");
+
+ cryptonote::tx_extra_nonce extra_nonce;
+ if (is_long_payment_id)
+ {
+ cryptonote::set_payment_id_to_tx_extra_nonce(extra_nonce.nonce, payment_id);
+ }
+ else // !is_long_payment_id
+ {
+ crypto::hash8 pid_8;
+ memcpy(&pid_8, &payment_id, sizeof(pid_8));
+ cryptonote::set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce.nonce, pid_8);
+ }
+
+ CHECK_AND_ASSERT_THROW_MES(cryptonote::add_extra_nonce_to_tx_extra(extra, extra_nonce.nonce),
+ "failed to add nonce to tx_extra");
+ }
+
+ const bool r = cryptonote::construct_tx_and_get_tx_key(
+ sender_account_keys,
+ sender_subaddress_map,
+ sources,
+ destinations,
+ change_addr,
+ extra,
+ tx,
+ main_tx_privkey_out,
+ additional_tx_privkeys_out,
+ rct,
+ rct_config,
+ use_view_tags);
+ CHECK_AND_ASSERT_THROW_MES(r, "failed to construct tx");
+ return tx;
+}
+//----------------------------------------------------------------------------------------------------------------------
+cryptonote::transaction construct_pre_carrot_tx_with_fake_inputs(
+ const cryptonote::account_keys &sender_account_keys,
+ const std::unordered_map<crypto::public_key, cryptonote::subaddress_index> &sender_subaddress_map,
+ std::vector<stripped_down_tx_source_entry_t> &&stripped_sources,
+ std::vector<cryptonote::tx_destination_entry> &destinations,
+ const boost::optional<cryptonote::account_public_address> &change_addr,
+ const rct::xmr_amount fee,
+ const uint8_t hf_version,
+ const bool sweep_unmixable_override)
+{
+ crypto::secret_key dummy_main_tx_privkey;
+ std::vector<crypto::secret_key> dummy_additional_tx_privkeys;
+ return construct_pre_carrot_tx_with_fake_inputs(sender_account_keys,
+ sender_subaddress_map,
+ std::forward<std::vector<stripped_down_tx_source_entry_t>>(stripped_sources),
+ destinations,
+ change_addr,
+ crypto::null_hash,
+ fee,
+ hf_version,
+ dummy_main_tx_privkey,
+ dummy_additional_tx_privkeys,
+ sweep_unmixable_override);
+}
+//----------------------------------------------------------------------------------------------------------------------
+cryptonote::transaction construct_pre_carrot_tx_with_fake_inputs(
+ std::vector<cryptonote::tx_destination_entry> &destinations,
+ const rct::xmr_amount fee,
+ const uint8_t hf_version,
+ const bool sweep_unmixable_override)
+{
+ cryptonote::account_base aether_acb;
+ aether_acb.generate();
+ const std::unordered_map<crypto::public_key, cryptonote::subaddress_index> sender_subaddress_map = {
+ { aether_acb.get_keys().m_account_address.m_spend_public_key, {0, 0 } }
+ };
+
+ return construct_pre_carrot_tx_with_fake_inputs(aether_acb.get_keys(),
+ sender_subaddress_map,
+ /*stripped_sources=*/{},
+ destinations,
+ /*change_addr*/boost::none,
+ fee,
+ hf_version,
+ sweep_unmixable_override);
+}
+//----------------------------------------------------------------------------------------------------------------------
+const cryptonote::account_public_address null_addr{
+ .m_spend_public_key = crypto::get_G(),
+ .m_view_public_key = crypto::get_G()
+};
+//----------------------------------------------------------------------------------------------------------------------
+} //namespace mockWhy this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.