What changed, and why it matters
This Monero code change refactors how the blockchain import tool verifies blocks. Previously, the tool fed each transaction individually into the core for verification before processing the block. Now it builds a 'pool supplement' from the block's transactions and passes that directly to the block verifier, matching how the network protocol already handles blocks. The change also moves shared helper code into a common header and adds a duplicate-transaction check that was missing before.
Treat as a hardening/refactoring change rather than an active vulnerability fix. Reviewers should verify that `blockchain_import` now enforces the same transaction validity, pruning, and duplicate checks as the P2P protocol path, and that the new duplicate-transaction check does not introduce any consensus or import regressions.
Security signals we found
Refactored block verification path in blockchain_import to use pool supplements instead of per-transaction ingestion
Moved duplicated transaction-pool-supplement construction helpers into a shared header
Added duplicate transaction detection in pool_supplement construction (return value of add_tx now checked)
Removed per-tx handle_incoming_tx loop from blockchain_import, reducing divergence between import and network block-handling paths
No explicit security framing, CVE, or advisory language in commit or supplied references
Evidence from the diff
The commit merges PR #11354. It extracts make_pool_supplement_from_block_entry and make_full_pool_supplement_from_block_entry from cryptonote_protocol_handler.inl into a new shared header block_entry_utils.h, then makes blockchain_import.cpp use make_full_pool_supplement_from_block_entry instead of calling core.handle_incoming_tx() for each transaction. The new shared helper adds an explicit duplicate-transaction check (pool_supplement.add_tx(...) now returns false on duplicates, whereas the old protocol code called add_tx without checking its return value). The import tool now passes the constructed pool_supplement to core.handle_incoming_block().
Changed components
src/blockchain_utilities/blockchain_import.cppsrc/cryptonote_protocol/block_entry_utils.hsrc/cryptonote_protocol/cryptonote_protocol_handler.inlInspect captured patch +155 / −108
### src/blockchain_utilities/blockchain_import.cpp
@@ -42,6 +42,7 @@
#include "serialization/binary_utils.h" // dump_binary(), parse_binary()
#include "include_base_utils.h"
#include "cryptonote_core/cryptonote_core.h"
+#include "cryptonote_protocol/block_entry_utils.h"
#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "bcutil"
@@ -168,29 +169,30 @@ int check_flush(cryptonote::core &core, std::vector<block_complete_entry> &block
size_t blockidx = 0;
for(const block_complete_entry& block_entry: blocks)
{
- // process transactions
- for(auto& tx_blob: block_entry.txs)
+ pool_supplement ps{};
+ bool success = false;
+ try
{
- tx_verification_context tvc = AUTO_VAL_INIT(tvc);
- CHECK_AND_ASSERT_THROW_MES(tx_blob.prunable_hash == crypto::null_hash,
- "block entry must not contain pruned txs");
- core.handle_incoming_tx(tx_blob.blob, tvc, relay_method::block, true);
- if(tvc.m_verifivation_failed)
- {
- cryptonote::transaction transaction;
- if (cryptonote::parse_and_validate_tx_from_blob(tx_blob.blob, transaction))
- MERROR("Transaction verification failed, tx_id = " << cryptonote::get_transaction_hash(transaction));
- else
- MERROR("Transaction verification failed, transaction is unparsable");
- core.cleanup_handle_incoming_blocks();
- return 1;
- }
+ success = make_full_pool_supplement_from_block_entry(block_entry, ps);
+ }
+ catch (const std::exception& e)
+ {
+ MERROR("Exception while making transaction pool supplement: " << e.what());
+ }
+ catch (...)
+ {
+ MERROR("Exception while making transaction pool supplement");
+ }
+ if (!success)
+ {
+ MERROR("Failed to make transaction pool supplement for block at height " << core.get_current_blockchain_height());
+ core.cleanup_handle_incoming_blocks();
+ return 1;
}
// process block
block_verification_context bvc = {};
- pool_supplement ps{};
core.handle_incoming_block(block_entry.block, pblocks.empty() ? NULL : &pblocks[blockidx++], bvc, ps, false); // <--- process block
### src/cryptonote_protocol/block_entry_utils.h
@@ -0,0 +1,135 @@
+// Copyright (c) 2014-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 <unordered_set>
+#include <utility>
+#include <vector>
+
+#include "cryptonote_basic/cryptonote_format_utils.h"
+#include "cryptonote_core/tx_verification_utils.h"
+#include "cryptonote_protocol_defs.h"
+#include "misc_log_ex.h"
+#include "string_tools.h"
+
+namespace cryptonote
+{
+ template <class CryptoHashContainer>
+ inline bool make_pool_supplement_from_block_entry(
+ const std::vector<cryptonote::tx_blob_entry>& tx_entries,
+ const CryptoHashContainer& blk_tx_hashes,
+ const bool allow_pruned,
+ cryptonote::pool_supplement& pool_supplement)
+ {
+ if (tx_entries.size() > blk_tx_hashes.size())
+ {
+ MCERROR("verify", "Failed to make pool supplement: Too many transaction blobs!");
+ return false;
+ }
+
+ for (const cryptonote::tx_blob_entry& tx_entry: tx_entries)
+ {
+ const bool is_pruned = tx_entry.prunable_hash != crypto::null_hash;
+ if (is_pruned && !allow_pruned)
+ {
+ MCERROR("verify", "Pruned transaction not allowed here");
+ return false;
+ }
+
+ cryptonote::transaction tx;
+ crypto::hash tx_hash;
+ bool parse_success = false;
+ const bool max_size_check = true;
+ if (is_pruned)
+ {
+ if ((parse_success = cryptonote::parse_and_validate_tx_base_from_blob(tx_entry.blob, tx, max_size_check, /*require_eof=*/true)))
+ parse_success = cryptonote::get_pruned_transaction_hash(tx, tx_entry.prunable_hash, tx_hash);
+ }
+ else
+ {
+ parse_success = cryptonote::parse_and_validate_tx_from_blob(tx_entry.blob, tx, tx_hash, max_size_check);
+ }
+
+ if (!parse_success)
+ {
+ MCERROR("verify", "failed to parse and/or validate transaction: "
+ << epee::string_tools::buff_to_hex_nodelimer(tx_entry.blob)
+ );
+ return false;
+ }
+ else if (!blk_tx_hashes.count(tx_hash))
+ {
+ MCERROR("verify", "transaction " << tx_hash << " not in block");
+ return false;
+ }
+
+ if (!pool_supplement.add_tx(tx_hash, std::move(tx), tx_entry.blob))
+ {
+ MCERROR("verify", "Duplicate transaction " << tx_hash << " in block entry");
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ inline bool make_full_pool_supplement_from_block_entry(
+ const cryptonote::block_complete_entry& blk_entry,
+ cryptonote::pool_supplement& pool_supplement)
+ {
+ cryptonote::block blk;
+ if (!cryptonote::parse_and_validate_block_from_blob(blk_entry.block, blk))
+ {
+ MCERROR("verify", "sent bad block: failed to parse and/or validate block: "
+ << epee::string_tools::buff_to_hex_nodelimer(blk_entry.block)
+ );
+ return false;
+ }
+
+ const std::unordered_set<crypto::hash> blk_tx_hashes(blk.tx_hashes.cbegin(), blk.tx_hashes.cend());
+
+ if (blk_tx_hashes.size() != blk_entry.txs.size())
+ {
+ MCERROR("verify", "sent bad block entry: number of hashes is not equal number of tx blobs: "
+ << epee::string_tools::buff_to_hex_nodelimer(blk_entry.block)
+ );
+ return false;
+ }
+ else if (blk_tx_hashes.size() != blk.tx_hashes.size())
+ {
+ MCERROR("verify", "sent bad block entry: there are duplicate tx hashes in parsed block: "
+ << epee::string_tools::buff_to_hex_nodelimer(blk_entry.block));
+ return false;
+ }
+
+ // We set `allow_pruned` equal to whether this block entry is pruned since the pruned flag
+ // should be checked anyways by the time we deserialize transactions
+ return make_pool_supplement_from_block_entry(blk_entry.txs, blk_tx_hashes, blk_entry.pruned, pool_supplement);
+ }
+} // namespace cryptonote
### src/cryptonote_protocol/cryptonote_protocol_handler.inl
@@ -45,6 +45,7 @@
#include <cryptonote_core/cryptonote_core.h>
#include "cryptonote_protocol/cryptonote_protocol_handler.h"
+#include "cryptonote_protocol/block_entry_utils.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "profile_tools.h"
#include "net/network_throttle-detail.hpp"
@@ -85,96 +86,6 @@
namespace cryptonote
{
- template <class CryptoHashContainer>
- inline bool make_pool_supplement_from_block_entry(
- const std::vector<cryptonote::tx_blob_entry>& tx_entries,
- const CryptoHashContainer& blk_tx_hashes,
- const bool allow_pruned,
- cryptonote::pool_supplement& pool_supplement)
- {
- if (tx_entries.size() > blk_tx_hashes.size())
- {
- MERROR("Failed to make pool supplement: Too many transaction blobs!");
- return false;
- }
-
- for (const cryptonote::tx_blob_entry& tx_entry: tx_entries)
- {
- const bool is_pruned = tx_entry.prunable_hash != crypto::null_hash;
- if (is_pruned && !allow_pruned)
- {
- MERROR("Pruned transaction not allowed here");
- return false;
- }
-
- cryptonote::transaction tx;
- crypto::hash tx_hash;
- bool parse_success = false;
- const bool max_size_check = true;
- if (is_pruned)
- {
- if ((parse_success = cryptonote::parse_and_validate_tx_base_from_blob(tx_entry.blob, tx, max_size_check, /*require_eof=*/true)))
- parse_success = cryptonote::get_pruned_transaction_hash(tx, tx_entry.prunable_hash, tx_hash);
- }
- else
- {
- parse_success = cryptonote::parse_and_validate_tx_from_blob(tx_entry.blob, tx, tx_hash, max_size_check);
- }
-
- if (!parse_success)
- {
- MERROR("failed to parse and/or validate transaction: "
- << epee::string_tools::buff_to_hex_nodelimer(tx_entry.blob)
- );
- return false;
- }
- else if (!blk_tx_hashes.count(tx_hash))
- {
- MERROR("transaction " << tx_hash << " not in block");
- return false;
- }
-
- pool_supplement.add_tx(tx_hash, std::move(tx), tx_entry.blob);
- }
-
- return true;
- }
-
- inline bool make_full_pool_supplement_from_block_entry(
- const cryptonote::block_complete_entry& blk_entry,
- cryptonote::pool_supplement& pool_supplement)
- {
- cryptonote::block blk;
- if (!cryptonote::parse_and_validate_block_from_blob(blk_entry.block, blk))
- {
- MERROR("sent bad block: failed to parse and/or validate block: "
- << epee::string_tools::buff_to_hex_nodelimer(blk_entry.block)
- );
- return false;
- }
-
- const std::unordered_set<crypto::hash> blk_tx_hashes(blk.tx_hashes.cbegin(), blk.tx_hashes.cend());
-
- if (blk_tx_hashes.size() != blk_entry.txs.size())
- {
- MERROR("sent bad block entry: number of hashes is not equal number of tx blobs: "
- << epee::string_tools::buff_to_hex_nodelimer(blk_entry.block)
- );
- return false;
- }
- else if (blk_tx_hashes.size() != blk.tx_hashes.size())
- {
- MERROR("sent bad block entry: there are duplicate tx hashes in parsed block: "
- << epee::string_tools::buff_to_hex_nodelimer(blk_entry.block));
- return false;
- }
-
- // We set `allow_pruned` equal to whether this block entry is pruned since the pruned flag
- // should be checked anyways by the time we deserialize transactions
- return make_pool_supplement_from_block_entry(blk_entry.txs, blk_tx_hashes, blk_entry.pruned, pool_supplement);
- }
-
-
//-----------------------------------------------------------------------------------------------------------------------
template<class t_core>
t_cryptonote_protocol_handler<t_core>::t_cryptonote_protocol_handler(t_core& rcore, nodetool::i_p2p_endpoint<connection_context>* p_net_layout, bool offline):m_core(rcore),
@@ -2933,4 +2844,3 @@ skip:
m_core.stop();
}
} // namespace
-Why this scored 32/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.