From 439cda5f177d5b970cea7e77c55fbaac2d4c03ab Mon Sep 17 00:00:00 2001 From: j-berman Date: Thu, 17 Sep 2026 16:36:16 -0700 Subject: [PATCH 1/3] txpool: don't drop cxns realying key images spent in chain --- src/cryptonote_core/blockchain.cpp | 9 +++++++-- src/cryptonote_core/tx_pool.cpp | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 53e991bb7..5cab6b2eb 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -3499,9 +3499,14 @@ bool Blockchain::have_tx_keyimges_as_spent(const transaction &tx) const LOG_PRINT_L3("Blockchain::" << __func__); for (const txin_v& in: tx.vin) { - CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, in_to_key, true); - if(have_tx_keyimg_as_spent(in_to_key.k_image)) + if (in.type() != typeid(txin_to_key)) + continue; + const auto &tokey_in = boost::get(in); + if(have_tx_keyimg_as_spent(tokey_in.k_image)) + { + LOG_PRINT_L1("Key image already spent in blockchain: " << epee::string_tools::pod_to_hex(tokey_in.k_image)); return true; + } } return false; } diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index 2781f3550..a01ca5409 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -239,7 +239,7 @@ namespace cryptonote // TODO: Investigate why not? if(!kept_by_block) { - if(have_tx_keyimges_as_spent(tx, id)) + if(have_tx_keyimges_as_spent(tx, id) || m_blockchain.have_tx_keyimges_as_spent(tx)) { mark_double_spend(tx); LOG_PRINT_L1("Transaction with id= "<< id << " used already spent key images"); From 2ea0bc9c82a5f0a2c89ab4cc0cfee360eae07107 Mon Sep 17 00:00:00 2001 From: j-berman Date: Tue, 22 Sep 2026 13:57:11 -0700 Subject: [PATCH 2/3] Review comments --- src/cryptonote_core/blockchain.cpp | 8 +++----- src/cryptonote_core/tx_pool.cpp | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 5cab6b2eb..dc64b25e2 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -3499,12 +3499,10 @@ bool Blockchain::have_tx_keyimges_as_spent(const transaction &tx) const LOG_PRINT_L3("Blockchain::" << __func__); for (const txin_v& in: tx.vin) { - if (in.type() != typeid(txin_to_key)) - continue; - const auto &tokey_in = boost::get(in); - if(have_tx_keyimg_as_spent(tokey_in.k_image)) + CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, in_to_key, true); + if(have_tx_keyimg_as_spent(in_to_key.k_image)) { - LOG_PRINT_L1("Key image already spent in blockchain: " << epee::string_tools::pod_to_hex(tokey_in.k_image)); + LOG_PRINT_L1("Key image already spent in blockchain: " << epee::string_tools::pod_to_hex(in_to_key)); return true; } } diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index a01ca5409..e233a1b64 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -234,6 +234,26 @@ namespace cryptonote return false; } + if (!check_inputs_types_supported(tx)) + { + // TODO: do more cheap semantics checks earlier. This is here so the have_tx_keyimges_as_spent below can only fail when expected. + MERROR("Unsupported input types for tx id= " << id); + tvc.m_verifivation_failed = true; + tvc.m_invalid_input = true; + return false; + } + + if (version && version > HF_VERSION_FCMP_PLUS_PLUS) + { + // TODO: do more cheap semantics checks earlier. This is here to protect overloading have_tx_keyimges_as_spent with many DB reads. + if (tx.vin.empty() || tx.vin.size() > FCMP_PLUS_PLUS_MAX_INPUTS) + { + tvc.m_verifivation_failed = true; + tvc.m_invalid_input = true; + return false; + } + } + // if the transaction came from a block popped from the chain, // don't check if we have its key images as spent. // TODO: Investigate why not? From a3648a830dcae1c84f965fdefc32483a27d3a292 Mon Sep 17 00:00:00 2001 From: j-berman Date: Tue, 22 Sep 2026 14:04:01 -0700 Subject: [PATCH 3/3] Print key image fix --- src/cryptonote_core/blockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index dc64b25e2..be6e5dd64 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -3502,7 +3502,7 @@ bool Blockchain::have_tx_keyimges_as_spent(const transaction &tx) const CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, in_to_key, true); if(have_tx_keyimg_as_spent(in_to_key.k_image)) { - LOG_PRINT_L1("Key image already spent in blockchain: " << epee::string_tools::pod_to_hex(in_to_key)); + LOG_PRINT_L1("Key image already spent in blockchain: " << epee::string_tools::pod_to_hex(in_to_key.k_image)); return true; } }