mirror of
https://github.com/monero-project/monero.git
synced 2024-12-23 03:59:33 +00:00
wallet: fix multisig key memory leak
Multisig keys per-transfer were being wiped, but not erased, which lead to a ginormous quadratic bloat the more transfers and exports you performed with the wallet.
This commit is contained in:
parent
053ba2cf07
commit
23179a0ba4
1 changed files with 26 additions and 0 deletions
|
@ -6163,6 +6163,20 @@ void wallet2::load(const std::string& wallet_, const epee::wipeable_string& pass
|
||||||
error::wallet_files_doesnt_correspond, m_keys_file, m_wallet_file);
|
error::wallet_files_doesnt_correspond, m_keys_file, m_wallet_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wallets used to wipe, but not erase, old unused multisig key info, which lead to huge memory leaks.
|
||||||
|
// Here we erase these multisig keys if they're zero'd out to free up space.
|
||||||
|
for (auto &td : m_transfers)
|
||||||
|
{
|
||||||
|
auto mk_it = td.m_multisig_k.begin();
|
||||||
|
while (mk_it != td.m_multisig_k.end())
|
||||||
|
{
|
||||||
|
if (*mk_it == rct::zero())
|
||||||
|
mk_it = td.m_multisig_k.erase(mk_it);
|
||||||
|
else
|
||||||
|
++mk_it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cryptonote::block genesis;
|
cryptonote::block genesis;
|
||||||
generate_genesis(genesis);
|
generate_genesis(genesis);
|
||||||
crypto::hash genesis_hash = get_block_hash(genesis);
|
crypto::hash genesis_hash = get_block_hash(genesis);
|
||||||
|
@ -7036,7 +7050,10 @@ void wallet2::commit_tx(pending_tx& ptx)
|
||||||
|
|
||||||
// tx generated, get rid of used k values
|
// tx generated, get rid of used k values
|
||||||
for (size_t idx: ptx.selected_transfers)
|
for (size_t idx: ptx.selected_transfers)
|
||||||
|
{
|
||||||
memwipe(m_transfers[idx].m_multisig_k.data(), m_transfers[idx].m_multisig_k.size() * sizeof(m_transfers[idx].m_multisig_k[0]));
|
memwipe(m_transfers[idx].m_multisig_k.data(), m_transfers[idx].m_multisig_k.size() * sizeof(m_transfers[idx].m_multisig_k[0]));
|
||||||
|
m_transfers[idx].m_multisig_k.clear();
|
||||||
|
}
|
||||||
|
|
||||||
//fee includes dust if dust policy specified it.
|
//fee includes dust if dust policy specified it.
|
||||||
LOG_PRINT_L1("Transaction successfully sent. <" << txid << ">" << ENDL
|
LOG_PRINT_L1("Transaction successfully sent. <" << txid << ">" << ENDL
|
||||||
|
@ -7540,7 +7557,10 @@ std::string wallet2::save_multisig_tx(multisig_tx_set txs)
|
||||||
// txes generated, get rid of used k values
|
// txes generated, get rid of used k values
|
||||||
for (size_t n = 0; n < txs.m_ptx.size(); ++n)
|
for (size_t n = 0; n < txs.m_ptx.size(); ++n)
|
||||||
for (size_t idx: txs.m_ptx[n].construction_data.selected_transfers)
|
for (size_t idx: txs.m_ptx[n].construction_data.selected_transfers)
|
||||||
|
{
|
||||||
memwipe(m_transfers[idx].m_multisig_k.data(), m_transfers[idx].m_multisig_k.size() * sizeof(m_transfers[idx].m_multisig_k[0]));
|
memwipe(m_transfers[idx].m_multisig_k.data(), m_transfers[idx].m_multisig_k.size() * sizeof(m_transfers[idx].m_multisig_k[0]));
|
||||||
|
m_transfers[idx].m_multisig_k.clear();
|
||||||
|
}
|
||||||
|
|
||||||
// zero out some data we don't want to share
|
// zero out some data we don't want to share
|
||||||
for (auto &ptx: txs.m_ptx)
|
for (auto &ptx: txs.m_ptx)
|
||||||
|
@ -7864,7 +7884,10 @@ bool wallet2::sign_multisig_tx(multisig_tx_set &exported_txs, std::vector<crypto
|
||||||
// inputs in the transactions worked on here)
|
// inputs in the transactions worked on here)
|
||||||
for (size_t n = 0; n < exported_txs.m_ptx.size(); ++n)
|
for (size_t n = 0; n < exported_txs.m_ptx.size(); ++n)
|
||||||
for (size_t idx: exported_txs.m_ptx[n].construction_data.selected_transfers)
|
for (size_t idx: exported_txs.m_ptx[n].construction_data.selected_transfers)
|
||||||
|
{
|
||||||
memwipe(m_transfers[idx].m_multisig_k.data(), m_transfers[idx].m_multisig_k.size() * sizeof(m_transfers[idx].m_multisig_k[0]));
|
memwipe(m_transfers[idx].m_multisig_k.data(), m_transfers[idx].m_multisig_k.size() * sizeof(m_transfers[idx].m_multisig_k[0]));
|
||||||
|
m_transfers[idx].m_multisig_k.clear();
|
||||||
|
}
|
||||||
|
|
||||||
exported_txs.m_signers.insert(get_multisig_signer_public_key());
|
exported_txs.m_signers.insert(get_multisig_signer_public_key());
|
||||||
|
|
||||||
|
@ -13511,7 +13534,10 @@ cryptonote::blobdata wallet2::export_multisig()
|
||||||
transfer_details &td = m_transfers[n];
|
transfer_details &td = m_transfers[n];
|
||||||
crypto::key_image ki;
|
crypto::key_image ki;
|
||||||
if (td.m_multisig_k.size())
|
if (td.m_multisig_k.size())
|
||||||
|
{
|
||||||
memwipe(td.m_multisig_k.data(), td.m_multisig_k.size() * sizeof(td.m_multisig_k[0]));
|
memwipe(td.m_multisig_k.data(), td.m_multisig_k.size() * sizeof(td.m_multisig_k[0]));
|
||||||
|
td.m_multisig_k.clear();
|
||||||
|
}
|
||||||
info[n].m_LR.clear();
|
info[n].m_LR.clear();
|
||||||
info[n].m_partial_key_images.clear();
|
info[n].m_partial_key_images.clear();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue