What changed, and why it matters
This patch fixes a bug in Monero's multisig wallet setup. Previously, when exchanging multisig key data, the wallet would sometimes save its keys file while the keys were still temporarily decrypted. The fix ensures the keys are re-locked before writing the wallet file. A new test confirms a wallet can be safely saved and reloaded during an intermediate multisig exchange step.
Apply the patch. It is a targeted fix with a regression test. Users creating or exchanging multisig wallets should update to a version containing this fix to avoid potential plaintext key material in wallet files.
Security signals we found
Keys may be written to disk in a decrypted state during multisig wallet save
Fix moves key re-encryption before wallet file write
New regression test covers intermediate multisig exchange save/reload
Evidence from the diff
In wallet2::exchange_multisig_keys(), the unlocker (a local key unlocker object) was reset only inside the branch where multisig_account.multisig_is_ready() was true. If the wallet was saved while multisig was not yet ready, keys could remain decrypted during the store_keys() call. The patch moves unlocker.reset() before the conditional, so keys are always re-encrypted before any wallet file write. A unit test reload_after_intermediate_exchange reproduces the intermediate-round save/reload scenario.
Changed components
src/wallet/wallet2.cpptests/unit_tests/multisig.cppInspect captured patch +68 / −3
### src/wallet/wallet2.cpp
@@ -6367,12 +6367,12 @@ std::string wallet2::exchange_multisig_keys(const epee::wipeable_string &passwor
m_multisig_rounds_passed = multisig_account.get_kex_rounds_complete();
m_deterministic = false;
+ // release the local key unlocker before writing the wallet keys file
+ unlocker.reset();
+
// why is this necessary? who knows...
if (multisig_account.multisig_is_ready())
{
- // keys are encrypted again
- unlocker.reset();
-
if (!m_wallet_file.empty())
{
bool r = this->store_keys(m_keys_file, password, false);
### tests/unit_tests/multisig.cpp
@@ -38,6 +38,7 @@
#include "gtest/gtest.h"
+#include <boost/filesystem.hpp>
#include <cstdint>
#include <sstream>
@@ -407,6 +408,70 @@ TEST(multisig, make_2_3)
make_wallets(2, 3, true);
}
+TEST(multisig, reload_after_intermediate_exchange)
+{
+ const boost::filesystem::path test_dir = boost::filesystem::temp_directory_path() /
+ boost::filesystem::unique_path("monero-multisig-%%%%-%%%%");
+ ASSERT_TRUE(boost::filesystem::create_directory(test_dir));
+ struct test_dir_cleanup
+ {
+ const boost::filesystem::path path;
+ ~test_dir_cleanup()
+ {
+ boost::system::error_code ec;
+ boost::filesystem::remove_all(path, ec);
+ }
+ } cleanup{test_dir};
+ const boost::filesystem::path wallet_path = test_dir / "wallet";
+
+ const epee::wipeable_string password("test-password");
+ std::vector<tools::wallet2> wallets(3);
+ crypto::secret_key spendkey;
+ ASSERT_TRUE(epee::string_tools::hex_to_pod(test_addresses[0].spendkey, spendkey));
+
+ wallets[0].init("", boost::none, "", 0, true, epee::net_utils::ssl_support_t::e_ssl_support_disabled);
+ wallets[0].set_subaddress_lookahead(1, 1);
+ wallets[0].generate(wallet_path.string(), password, spendkey, true, false);
+ for (size_t i = 1; i < wallets.size(); ++i)
+ make_wallet(i, wallets[i]);
+
+ std::vector<std::string> infos(wallets.size());
+ for (size_t i = 0; i < wallets.size(); ++i)
+ {
+ const epee::wipeable_string wallet_password = i == 0 ? password : epee::wipeable_string("");
+ wallets[i].decrypt_keys(wallet_password);
+ infos[i] = wallets[i].get_multisig_first_kex_msg();
+ wallets[i].encrypt_keys(wallet_password);
+ }
+
+ std::vector<std::string> intermediate_infos;
+ for (size_t i = 0; i < wallets.size(); ++i)
+ intermediate_infos.push_back(wallets[i].make_multisig(i == 0 ? password : "", infos, 2));
+
+ std::vector<std::string> next_infos;
+ for (size_t i = 0; i < wallets.size(); ++i)
+ next_infos.push_back(wallets[i].exchange_multisig_keys(i == 0 ? password : "", intermediate_infos));
+
+ ASSERT_FALSE(wallets[0].get_multisig_status().is_ready);
+ wallets[0].store();
+ wallets[0].deinit();
+
+ tools::wallet2 reopened;
+ reopened.init("", boost::none, "", 0, true, epee::net_utils::ssl_support_t::e_ssl_support_disabled);
+ ASSERT_NO_THROW(reopened.load(wallet_path.string(), password));
+ EXPECT_TRUE(reopened.get_multisig_status().multisig_is_active);
+ EXPECT_FALSE(reopened.get_multisig_status().is_ready);
+ EXPECT_NO_THROW(reopened.exchange_multisig_keys(password, next_infos));
+ EXPECT_TRUE(reopened.get_multisig_status().is_ready);
+ for (size_t i = 1; i < wallets.size(); ++i)
+ {
+ EXPECT_NO_THROW(wallets[i].exchange_multisig_keys("", next_infos));
+ EXPECT_EQ(wallets[i].get_account().get_public_address_str(cryptonote::TESTNET),
+ reopened.get_account().get_public_address_str(cryptonote::TESTNET));
+ }
+ reopened.deinit();
+}
+
TEST(multisig, make_2_4)
{
make_wallets(2, 4, false);Why this scored 54/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.