What changed, and why it matters
This update adds a safety check in the Monero wallet's fast refresh process. Previously, if a malicious or buggy remote server told the wallet to start syncing from a block height beyond the wallet's known blockchain data, the wallet could proceed with inconsistent state. Now the wallet detects this condition, logs an error, and stops. The change prevents potential wallet corruption or confusion caused by untrusted server responses.
Apply the patch. It is a low-risk defensive fix that improves robustness against malicious or misbehaving full nodes. No immediate incident response is indicated unless wallet refresh anomalies have already been observed.
Security signals we found
Added bounds check on untrusted server-supplied start_height against local hash chain size
Defensive hardening at wallet/daemon trust boundary
Unit test demonstrates rejection of out-of-bounds refresh request
Evidence from the diff
In wallet2::fast_refresh(), a new guard checks whether blocks_start_height exceeds m_blockchain.size(). If so, it logs an error and returns true (aborting the fast refresh). A unit test simulates a server returning start_height=11 when the wallet’s hash chain has only the genesis block (size=1), and verifies the wallet rejects the refresh and keeps a size-1 hash chain. The patch is defensive: it does not fix an obvious memory corruption or cryptographic flaw, but closes a trust-boundary gap where a malicious daemon could push the wallet into an inconsistent refresh.
Changed components
src/wallet/wallet2.cpptests/unit_tests/wallet_pool.cppInspect captured patch +34 / −0
### src/wallet/wallet2.cpp
@@ -4176,6 +4176,11 @@ bool wallet2::fast_refresh(uint64_t stop_height, uint64_t &blocks_start_height,
MERROR("Blocks start before blockchain offset: " << blocks_start_height << " " << m_blockchain.offset());
return true;
}
+ if (blocks_start_height > m_blockchain.size())
+ {
+ MERROR("Blocks start after the end of the hash chain: " << blocks_start_height << " " << m_blockchain.size());
+ return true;
+ }
current_index = blocks_start_height;
if (hashes.size() + current_index < stop_height) {
drop_from_short_history(short_chain_history, 3);
### tests/unit_tests/wallet_pool.cpp
@@ -666,6 +666,35 @@ TEST(wallet_pool, does_not_duplicate_genesis_after_zero_offset_rebuild)
EXPECT_EQ(original[i], chain[i]) << i;
}
+TEST(wallet_pool, fast_refresh_rejects_start_height_past_hashchain_end)
+{
+ tools::wallet2 *wallet = nullptr;
+ const auto reply = [&](const cryptonote::COMMAND_RPC_GET_BLOCKS_FAST::request &,
+ cryptonote::COMMAND_RPC_GET_BLOCKS_FAST::response &response)
+ {
+ response.start_height = response.current_height = 1;
+ };
+ const auto hash_reply = [&](const cryptonote::COMMAND_RPC_GET_HASHES_FAST::request &,
+ cryptonote::COMMAND_RPC_GET_HASHES_FAST::response &response)
+ {
+ response.start_height = 11;
+ response.current_height = 50;
+ response.m_block_ids.resize(20, crypto::rand<crypto::hash>());
+ wallet->stop();
+ };
+ tools::wallet2 w(cryptonote::MAINNET, 1, true,
+ std::unique_ptr<epee::net_utils::http::http_client_factory>(
+ new pool_http_client_factory(reply, {}, hash_reply)));
+ wallet = &w;
+ wallet_pool_test::prepare_refresh(w);
+
+ uint64_t fetched = 0;
+ bool received = false;
+ w.refresh(true, 50, fetched, received, false);
+
+ EXPECT_EQ(1, wallet_pool_test::hashchain(w).size());
+}
+
TEST(wallet_pool, retries_pool_after_password_failure)
{
size_t queries = 0;Why this scored 59/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.