What changed, and why it matters
This change fixes a small inconsistency in how Monero wallets are saved. When a wallet was created only in memory and then saved to disk on a test or staging network, it was missing the plain-text '.address.txt' file that normally gets created alongside mainnet wallets. The patch makes sure that address file is also written for non-mainnet wallets. It is a bug-fix for file output consistency, not a vulnerability that lets an attacker steal funds or keys.
No security action required. Treat as a normal bug-fix release. Users of testnet/stagenet wallets who rely on the .address.txt companion file will now see it created consistently.
Security signals we found
Behavioral consistency fix for wallet file persistence
No cryptographic material or private keys are written to the new file
Public address only is written to the .address.txt file
No input validation, parsing, or network changes
Evidence from the diff
wallet2::store_to() now writes a ‘
Changed components
src/wallet/wallet2.cpptests/unit_tests/wallet_storage.cppInspect captured patch +43 / −22
### src/wallet/wallet2.cpp
@@ -7293,7 +7293,13 @@ void wallet2::store_to(const std::string &path, const epee::wipeable_string &pas
LOG_ERROR("error removing file: " << old_file);
}
}
-
+
+ if (!had_old_wallet_files && m_nettype != MAINNET)
+ {
+ const bool r = save_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_nettype), true);
+ if (!r) MERROR("String with address text not saved");
+ }
+
if (m_message_store.get_active())
{
// While the "m_message_store" object of course always exist, a file for the message
### tests/unit_tests/wallet_storage.cpp
@@ -148,39 +148,54 @@ TEST(wallet_storage, store_to_file2file)
TEST(wallet_storage, store_to_mem2file)
{
- const path target_wallet_file = unit_test::data_dir / "wallet_mem2file";
+ for (const auto nettype : {cryptonote::MAINNET, cryptonote::TESTNET, cryptonote::STAGENET})
+ {
+ SCOPED_TRACE(static_cast<int>(nettype));
+ const path target_wallet_file = unit_test::data_dir / ("wallet_mem2file_" + std::to_string(nettype));
+ const std::string address_file = target_wallet_file.string() + ".address.txt";
+ if (is_file_exist(address_file))
+ remove(address_file);
- if (is_file_exist(target_wallet_file.string()))
- remove(target_wallet_file);
- if (is_file_exist(target_wallet_file.string() + ".keys"))
- remove(target_wallet_file.string() + ".keys");
- ASSERT_FALSE(is_file_exist(target_wallet_file.string()));
- ASSERT_FALSE(is_file_exist(target_wallet_file.string() + ".keys"));
+ if (is_file_exist(target_wallet_file.string()))
+ remove(target_wallet_file);
+ if (is_file_exist(target_wallet_file.string() + ".keys"))
+ remove(target_wallet_file.string() + ".keys");
+ ASSERT_FALSE(is_file_exist(target_wallet_file.string()));
+ ASSERT_FALSE(is_file_exist(target_wallet_file.string() + ".keys"));
- epee::wipeable_string password("beepbeep2");
+ epee::wipeable_string password("beepbeep2");
- {
- tools::wallet2 w;
- w.generate("", password);
- w.store_to(target_wallet_file.string(), password);
+ {
+ tools::wallet2 w(nettype);
+ w.generate("", password);
+ w.store_to(target_wallet_file.string(), password);
+
+ EXPECT_EQ(nettype != cryptonote::MAINNET, is_file_exist(address_file));
+ if (nettype != cryptonote::MAINNET)
+ {
+ std::string address;
+ ASSERT_TRUE(load_file_to_string(address_file, address));
+ EXPECT_EQ(w.get_address_as_str(), address);
+ }
+
+ EXPECT_TRUE(is_file_exist(target_wallet_file.string()));
+ EXPECT_TRUE(is_file_exist(target_wallet_file.string() + ".keys"));
+ }
EXPECT_TRUE(is_file_exist(target_wallet_file.string()));
EXPECT_TRUE(is_file_exist(target_wallet_file.string() + ".keys"));
- }
- EXPECT_TRUE(is_file_exist(target_wallet_file.string()));
- EXPECT_TRUE(is_file_exist(target_wallet_file.string() + ".keys"));
+ {
+ tools::wallet2 w(nettype);
+ w.load(target_wallet_file.string(), password);
- {
- tools::wallet2 w;
- w.load(target_wallet_file.string(), password);
+ EXPECT_TRUE(is_file_exist(target_wallet_file.string()));
+ EXPECT_TRUE(is_file_exist(target_wallet_file.string() + ".keys"));
+ }
EXPECT_TRUE(is_file_exist(target_wallet_file.string()));
EXPECT_TRUE(is_file_exist(target_wallet_file.string() + ".keys"));
}
-
- EXPECT_TRUE(is_file_exist(target_wallet_file.string()));
- EXPECT_TRUE(is_file_exist(target_wallet_file.string() + ".keys"));
}
TEST(wallet_storage, export_key_images_uses_generated_key_image)Why this scored 19/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.