From 7f25459169e9cc67ad3db026474236a9075094cd Mon Sep 17 00:00:00 2001 From: auruya Date: Mon, 1 Sep 2025 16:18:11 +0300 Subject: [PATCH] add dest_asset_type check (#52) --- src/cryptonote_core/blockchain.cpp | 42 ++++++++++++++++--------- src/cryptonote_core/cryptonote_core.cpp | 2 +- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 7da27dc6e..47b97fa6b 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -3790,7 +3790,7 @@ bool Blockchain::check_tx_type_and_version(const transaction& tx, tx_verificatio } // Check for v1 TXs - genesis block protocol_tx exception required! - if (tx.version == 1 && epee::string_tools::pod_to_hex(cryptonote::get_transaction_hash(tx)) == "4f78ff511e860acd03138737a71505eb62eb78b620e180e58c8e13ed0e1e3e19") { + if (tx.version == 1) { MERROR("v1 TXs are not permitted"); tvc.m_version_mismatch = true; return false; @@ -3823,6 +3823,32 @@ bool Blockchain::check_tx_type_and_version(const transaction& tx, tx_verificatio } } + + if (tx.type == cryptonote::transaction_type::AUDIT) { + // Make sure we are supposed to accept AUDIT txs at this point + const std::map>> audit_hard_forks = get_config(m_nettype).AUDIT_HARD_FORKS; + CHECK_AND_ASSERT_MES(audit_hard_forks.find(hf_version) != audit_hard_forks.end(), false, "trying to audit outside an audit fork"); + std::string expected_asset_type = audit_hard_forks.at(hf_version).second.first; + CHECK_AND_ASSERT_MES(tx.source_asset_type == expected_asset_type, false, "trying to spend " << tx.source_asset_type << " coins in an AUDIT TX"); + } else { + if (hf_version >= HF_VERSION_SALVIUM_ONE_PROOFS) { + CHECK_AND_ASSERT_MES(tx.source_asset_type == "SAL1", false, "trying to spend " << tx.source_asset_type << " coins in a non-AUDIT TX"); + } else { + CHECK_AND_ASSERT_MES(tx.source_asset_type == "SAL", false, "trying to spend " << tx.source_asset_type << " coins in a non-AUDIT TX"); + } + } + + if (tx.type == cryptonote::transaction_type::BURN) { + CHECK_AND_ASSERT_MES(tx.destination_asset_type == "BURN", false, "incorrect burn tx destination type:" << tx.destination_asset_type); + } else { + if (tx.source_asset_type != tx.destination_asset_type) { + MERROR_VER("Tx " << get_transaction_hash(tx) << " has mismatched asset types: " << tx.source_asset_type << " != " << tx.destination_asset_type); + tvc.m_verifivation_failed = true; + return false; + } + } + + // Check for invalid TX types if (tx.type == cryptonote::transaction_type::UNSET || tx.type > cryptonote::transaction_type::MAX) { MERROR("TX type `" + std::to_string(tx.type) + "' is not supported"); @@ -4086,20 +4112,6 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc, } } - if (tx.type == cryptonote::transaction_type::AUDIT) { - // Make sure we are supposed to accept AUDIT txs at this point - const std::map>> audit_hard_forks = get_config(m_nettype).AUDIT_HARD_FORKS; - CHECK_AND_ASSERT_MES(audit_hard_forks.find(hf_version) != audit_hard_forks.end(), false, "trying to audit outside an audit fork"); - std::string expected_asset_type = audit_hard_forks.at(hf_version).second.first; - CHECK_AND_ASSERT_MES(tx.source_asset_type == expected_asset_type, false, "trying to spend " << tx.source_asset_type << " coins in an AUDIT TX"); - } else { - if (hf_version >= HF_VERSION_SALVIUM_ONE_PROOFS) { - CHECK_AND_ASSERT_MES(tx.source_asset_type == "SAL1", false, "trying to spend " << tx.source_asset_type << " coins in a non-AUDIT TX"); - } else { - CHECK_AND_ASSERT_MES(tx.source_asset_type == "SAL", false, "trying to spend " << tx.source_asset_type << " coins in a non-AUDIT TX"); - } - } - std::vector> pubkeys(tx.vin.size()); std::vector < uint64_t > results; results.resize(tx.vin.size(), 0); diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index 52ed81140..a5de618c5 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -1022,7 +1022,7 @@ namespace cryptonote } if (!rvv.empty()) { - LOG_PRINT_L1("One transaction among this group has bad semantics, verifying one at a time"); + LOG_PRINT_L1("Verifying transactions one at a time"); ret = false; for (size_t n = 0; n < tx_info.size(); ++n) {