From 448c4536796cc57c4a1d60e23a278ceca3dc7523 Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 1 Jun 2018 00:41:16 +0100 Subject: [PATCH] fixing-invalid-txes-in-pool --- src/cryptonote_core/cryptonote_core.cpp | 3 ++- src/cryptonote_core/tx_pool.cpp | 32 ++++++++++++++++++++++++- src/cryptonote_core/tx_pool.h | 2 +- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index 13f5bdbae..e46bd0695 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -411,7 +411,8 @@ namespace cryptonote // now that we have a valid m_blockchain_storage, we can clean out any // transactions in the pool that do not conform to the current fork - m_mempool.validate(m_blockchain_storage.get_current_hard_fork_version()); + + m_mempool.validate(m_blockchain_storage.get_current_hard_fork_version(), m_mempool); bool show_time_stats = command_line::get_arg(vm, command_line::arg_show_time_stats) != 0; m_blockchain_storage.set_show_time_stats(show_time_stats); diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index 301806f00..b83a25078 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -130,6 +130,17 @@ namespace cryptonote return false; } + if(m_blockchain.get_current_hard_fork_version() >=6) + { + crypto::hash tx_prefix_hash = get_transaction_prefix_hash(tx); + for (const auto& txin : tx.vin) { + if (boost::get(txin).key_offsets.size() != DEFAULT_RINGSIZE) { + tvc.m_verifivation_failed = true; + return false; + } + } + } + if(!check_inputs_types_supported(tx)) { tvc.m_verifivation_failed = true; @@ -949,7 +960,7 @@ namespace cryptonote return true; } //--------------------------------------------------------------------------------- - size_t tx_memory_pool::validate(uint8_t version) + size_t tx_memory_pool::validate(uint8_t version, tx_memory_pool& pool) { CRITICAL_REGION_LOCAL(m_transactions_lock); CRITICAL_REGION_LOCAL1(m_blockchain); @@ -968,6 +979,25 @@ namespace cryptonote return true; }); + if (version >= 6) { + + std::list txs; + pool.get_transactions(txs); + + for (auto itr = txs.begin(); itr != txs.end(); itr++) { + + crypto::hash tx_prefix_hash = get_transaction_prefix_hash((*itr)); + + for (auto txin : itr->vin) { + + if (boost::get(txin).key_offsets.size() != DEFAULT_RINGSIZE) { + crypto::hash txid = get_transaction_hash((*itr)); + LOG_PRINT_L1("Transaction " << txid << " has an invalid ringsize, removing it from pool"); + remove.insert(txid); + } + } + } + } size_t n_removed = 0; if (!remove.empty()) { diff --git a/src/cryptonote_core/tx_pool.h b/src/cryptonote_core/tx_pool.h index 46daac7cb..b1118a254 100644 --- a/src/cryptonote_core/tx_pool.h +++ b/src/cryptonote_core/tx_pool.h @@ -327,7 +327,7 @@ namespace cryptonote * * @return the number of transactions removed */ - size_t validate(uint8_t version); + size_t validate(uint8_t version, tx_memory_pool& pool); #define CURRENT_MEMPOOL_ARCHIVE_VER 11