What changed, and why it matters
This Monero update adds a cache that remembers which transactions in the memory pool have already failed expensive input verification, so the node does not waste CPU re-checking the same bad transaction repeatedly. It is a performance and denial-of-service hardening change, not a fix for a currently exploitable vulnerability. The commit message and code comments describe it as a caching improvement, not a security patch.
Treat as a routine hardening/performance improvement. No urgent security action is required. Nodes and services should upgrade through normal Monero release channels when this commit is included in a tagged release.
Security signals we found
Adds caching of invalid input verification IDs to avoid repeated expensive ring signature verification
Reduces CPU consumption for transactions that re-enter or remain in the mempool with unchanged invalid inputs
Could mitigate a minor denial-of-service vector where a node repeatedly re-verifies a bad transaction
No change to consensus rules, cryptographic validation, or transaction acceptance policy
Evidence from the diff
The patch introduces an invalid_input_verification_id parameter through Blockchain::check_tx_inputs and tx_memory_pool::check_tx_inputs. When ring-signature input verification fails, the node now stores a deterministic verification ID (make_input_verification_id) keyed by transaction hash. On later re-checks of the same transaction, if the cached invalid ID matches the freshly computed ID, the node short-circuits and returns false without re-running the costly proof verification. The cache is maintained only for transactions present in the tx pool and is erased when the transaction is removed. This complements the existing valid-input-verification-id cache.
Changed components
src/cryptonote_core/blockchain.cppsrc/cryptonote_core/blockchain.hsrc/cryptonote_core/tx_pool.cppsrc/cryptonote_core/tx_pool.hInspect captured patch +56 / −10
### src/cryptonote_core/blockchain.cpp
@@ -2963,6 +2963,7 @@ bool Blockchain::check_tx_inputs(transaction& tx,
crypto::hash& max_used_block_id,
tx_verification_context &tvc,
crypto::hash &valid_input_verification_id_inout,
+ crypto::hash &invalid_input_verification_id_inout,
bool kept_by_block) const
{
LOG_PRINT_L3("Blockchain::" << __func__);
@@ -2979,7 +2980,7 @@ bool Blockchain::check_tx_inputs(transaction& tx,
#endif
TIME_MEASURE_START(a);
- bool res = check_tx_inputs(tx, tvc, valid_input_verification_id_inout, &max_used_block_height);
+ bool res = check_tx_inputs(tx, tvc, valid_input_verification_id_inout, invalid_input_verification_id_inout, &max_used_block_height);
TIME_MEASURE_FINISH(a);
if(m_show_time_stats)
{
@@ -3263,6 +3264,7 @@ bool Blockchain::expand_transaction_2(transaction &tx, const crypto::hash &tx_pr
bool Blockchain::check_tx_inputs(transaction& tx,
tx_verification_context &tvc,
crypto::hash &valid_input_verification_id_inout,
+ crypto::hash &invalid_input_verification_id_inout,
uint64_t* pmax_used_block_height) const
{
PERF_TIMER(check_tx_inputs);
@@ -3458,10 +3460,9 @@ bool Blockchain::check_tx_inputs(transaction& tx,
const crypto::hash txid = get_transaction_hash(tx);
// Try skipping verification if input verification ID matches a previously valid ID
- crypto::hash calculated_input_verification_id = crypto::null_hash;
+ const crypto::hash calculated_input_verification_id = make_input_verification_id(get_transaction_hash(tx), pubkeys);
if (valid_input_verification_id_inout != crypto::null_hash)
{
- calculated_input_verification_id = make_input_verification_id(get_transaction_hash(tx), pubkeys);
if (calculated_input_verification_id == valid_input_verification_id_inout)
{
MDEBUG("Valid verID hit for tx " << txid << ", skipping input verification...");
@@ -3478,18 +3479,24 @@ bool Blockchain::check_tx_inputs(transaction& tx,
MDEBUG("No previously valid verID provided for tx " << txid << ", continuing to input verification as normal...");
}
- // Verify ring signature input proofs
valid_input_verification_id_inout = crypto::null_hash;
+ assert(calculated_input_verification_id != crypto::null_hash);
+ if (invalid_input_verification_id_inout == calculated_input_verification_id)
+ {
+ MDEBUG("Tx inputs already determined invalid for " << txid);
+ return false;
+ }
+
+ // Verify ring signature input proofs
if (!ver_input_proofs_rings(tx, pubkeys))
{
MERROR_VER("Failed to verify input ring signatures for tx " << txid);
+ invalid_input_verification_id_inout = calculated_input_verification_id;
return false;
}
// At this point, we've succeeded at input verification, so set `valid_input_verification_id_inout`
- valid_input_verification_id_inout = (calculated_input_verification_id == crypto::null_hash)
- ? make_input_verification_id(get_transaction_hash(tx), pubkeys)
- : calculated_input_verification_id;
+ valid_input_verification_id_inout = calculated_input_verification_id;
MDEBUG("Input verification for tx " << txid << " succeeded. Setting verID to " << valid_input_verification_id_inout);
@@ -4186,7 +4193,8 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash&
{
// validate that transaction inputs and the keys spending them are correct.
tx_verification_context tvc;
- if(!check_tx_inputs(tx, tvc, valid_input_verification_id))
+ crypto::hash invalid_input_verification_id{crypto::null_hash};
+ if(!check_tx_inputs(tx, tvc, valid_input_verification_id, invalid_input_verification_id))
{
MERROR_VER("Block with id: " << id << " has at least one transaction (id: " << tx_id << ") with wrong inputs.");
### src/cryptonote_core/blockchain.h
@@ -628,6 +628,7 @@ namespace cryptonote
* @param max_used_block_id return-by-reference block hash of most recent input
* @param tvc returned information about tx verification
* @param valid_input_verification_id_inout a previously valid verID if non-null, set on input verification
+ * @param invalid_input_verification_id_inout a previously invalid verID if non-null, set on input verification failure
* @param kept_by_block whether or not the transaction is from a previously-verified block
*
* @return false if any input is invalid, otherwise true
@@ -645,6 +646,7 @@ namespace cryptonote
crypto::hash& max_used_block_id,
tx_verification_context &tvc,
crypto::hash &valid_input_verification_id_inout,
+ crypto::hash &invalid_input_verification_id_inout,
bool kept_by_block = false) const;
/**
@@ -1339,6 +1341,7 @@ namespace cryptonote
* @param tx the transaction to validate
* @param tvc returned information about tx verification
* @param valid_input_verification_id_inout a previously valid verID if non-null, set on input verification
+ * @param invalid_input_verification_id_inout a previously invalid verID if non-null, set on input verification failure
* @param pmax_related_block_height return-by-pointer the height of the most recent block in the input set
*
* @return false if any validation step fails, otherwise true
@@ -1354,6 +1357,7 @@ namespace cryptonote
bool check_tx_inputs(transaction& tx,
tx_verification_context &tvc,
crypto::hash &valid_input_verification_id_inout,
+ crypto::hash &invalid_input_verification_id_inout,
uint64_t* pmax_used_block_height = NULL) const;
/**
### src/cryptonote_core/tx_pool.cpp
@@ -248,8 +248,14 @@ namespace cryptonote
uint64_t max_used_block_height = 0;
cryptonote::txpool_tx_meta_t meta{};
meta.valid_input_verification_id = valid_input_verification_id;
+
+ crypto::hash invalid_input_verification_id = crypto::null_hash;
+ const auto invalid_input_it = m_invalid_input_verification_ids.find(id);
+ if (invalid_input_it != m_invalid_input_verification_ids.end())
+ invalid_input_verification_id = invalid_input_it->second;
+
const bool ch_inp_res = check_tx_inputs([&tx]()->cryptonote::transaction&{ return tx; }, id,
- meta.valid_input_verification_id, max_used_block_height, max_used_block_id, tvc, kept_by_block);
+ meta.valid_input_verification_id, invalid_input_verification_id, max_used_block_height, max_used_block_id, tvc, kept_by_block);
if(!ch_inp_res)
{
// if the transaction was valid before (kept_by_block), then it
@@ -291,6 +297,10 @@ namespace cryptonote
}
tvc.m_verifivation_impossible = true;
tvc.m_added_to_pool = true;
+
+ // Added to pool with invalid input
+ if (invalid_input_verification_id != crypto::null_hash)
+ m_invalid_input_verification_ids[id] = invalid_input_verification_id;
}else
{
LOG_PRINT_L1("tx used wrong inputs, rejected");
@@ -1395,6 +1405,7 @@ namespace cryptonote
bool tx_memory_pool::check_tx_inputs(const std::function<cryptonote::transaction&(void)> &get_tx,
const crypto::hash &txid,
crypto::hash &valid_input_verification_id_inout,
+ crypto::hash &invalid_input_verification_id_inout,
uint64_t &max_used_block_height,
crypto::hash &max_used_block_id,
tx_verification_context &tvc,
@@ -1411,7 +1422,7 @@ namespace cryptonote
return std::get<0>(i->second);
}
}
- bool ret = m_blockchain.check_tx_inputs(get_tx(), max_used_block_height, max_used_block_id, tvc, valid_input_verification_id_inout, kept_by_block);
+ bool ret = m_blockchain.check_tx_inputs(get_tx(), max_used_block_height, max_used_block_id, tvc, valid_input_verification_id_inout, invalid_input_verification_id_inout, kept_by_block);
if (!kept_by_block)
m_input_cache.insert(std::make_pair(txid, std::make_tuple(ret, tvc, max_used_block_height, max_used_block_id)));
return ret;
@@ -1441,16 +1452,27 @@ namespace cryptonote
if (txd.last_failed_id == top_block_hash)
return false; // we are already sure that this tx isn't passing for this exact chain
+ crypto::hash invalid_input_verification_id = crypto::null_hash;
+ const auto invalid_input_it = m_invalid_input_verification_ids.find(txid);
+ if (invalid_input_it != m_invalid_input_verification_ids.end())
+ invalid_input_verification_id = invalid_input_it->second;
+
tx_verification_context tvc{};
if (!check_tx_inputs([&lazy_tx]()->cryptonote::transaction&{ return lazy_tx(); },
txid,
txd.valid_input_verification_id,
+ invalid_input_verification_id,
txd.max_used_block_height,
txd.max_used_block_id,
tvc))
{
txd.last_failed_height = top_block_height;
txd.last_failed_id = top_block_hash;
+
+ // The tx is in the pool with an invalid input verID, cache it
+ if (invalid_input_verification_id != crypto::null_hash)
+ m_invalid_input_verification_ids[txid] = invalid_input_verification_id;
+
return false;
}
@@ -1869,6 +1891,9 @@ namespace cryptonote
MDEBUG("Removing tx " << txid << " from tx pool, but it was not found in the map of added txs");
}
track_removed_tx(txid, sensitive);
+
+ // Remove from invalid input cache (may not be present)
+ m_invalid_input_verification_ids.erase(txid);
}
//---------------------------------------------------------------------------------
void tx_memory_pool::track_removed_tx(const crypto::hash& txid, bool sensitive)
### src/cryptonote_core/tx_pool.h
@@ -662,6 +662,7 @@ namespace cryptonote
bool check_tx_inputs(const std::function<cryptonote::transaction&(void)> &get_tx,
const crypto::hash &txid,
crypto::hash &valid_input_verification_id_inout,
+ crypto::hash &invalid_input_verification_id_inout,
uint64_t &max_used_block_height,
crypto::hash &max_used_block_id,
tx_verification_context &tvc,
@@ -681,6 +682,14 @@ namespace cryptonote
mutable std::unordered_map<crypto::hash, std::tuple<bool, tx_verification_context, uint64_t, crypto::hash>> m_input_cache;
+ /*
+ If a tx enters the pool but has an invalid input verification ID (e.g. a reorged transaction that may eventually
+ become correct), we save its invalid input verID so we don't re-attempt expensive verification we know will fail.
+ An invalid ID may only be saved for a tx that exists in the pool. This cache can eventually be removed if we
+ modify how the alt block handling protocol inserts invalid input txs into the pool.
+ */
+ mutable std::unordered_map<crypto::hash/*tx_hash*/, crypto::hash> m_invalid_input_verification_ids;
+
std::unordered_map<crypto::hash, transaction> m_parsed_tx_cache;
//! Next timestamp that a DB check for relayable txes is allowedWhy this scored 26/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.