diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 61f49481e..e2aa2b201 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -8155,14 +8155,6 @@ std::string wallet2::save_multisig_tx(multisig_tx_set txs) { LOG_PRINT_L0("saving " << txs.m_ptx.size() << " multisig transactions"); - // txes generated, get rid of used k values - for (size_t n = 0; n < txs.m_ptx.size(); ++n) - 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])); - m_transfers[idx].m_multisig_k.clear(); - } - // zero out some data we don't want to share for (auto &ptx: txs.m_ptx) { @@ -8190,6 +8182,11 @@ std::string wallet2::save_multisig_tx(multisig_tx_set txs) } LOG_PRINT_L2("Saving multisig unsigned tx data: " << oss.str()); std::string ciphertext = encrypt_with_view_secret_key(oss.str()); + + // The transaction creator has already signed, so do not expose the txset + // until the corresponding one-time nonce erasure is stored. + clear_multisig_k_and_store(txs); + return std::string(MULTISIG_UNSIGNED_TX_PREFIX) + ciphertext; } //---------------------------------------------------------------------------------------------------- @@ -8348,8 +8345,12 @@ bool wallet2::load_multisig_tx_from_file(const std::string &filename, multisig_t return true; } //---------------------------------------------------------------------------------------------------- -bool wallet2::sign_multisig_tx(multisig_tx_set &exported_txs, std::vector &txids) +bool wallet2::sign_multisig_tx(multisig_tx_set &exported_txs_inout, std::vector &txids) { + multisig_tx_set exported_txs = exported_txs_inout; + std::vector signed_txids; + std::vector> signed_tx_key_indices; + THROW_WALLET_EXCEPTION_IF(exported_txs.m_ptx.empty(), error::wallet_internal_error, "No tx found"); const crypto::public_key local_signer = get_multisig_signer_public_key(); @@ -8363,8 +8364,6 @@ bool wallet2::sign_multisig_tx(multisig_tx_set &exported_txs, std::vector &use THROW_WALLET_EXCEPTION(tools::error::multisig_export_needed); } //---------------------------------------------------------------------------------------------------- +void wallet2::clear_multisig_k_and_store(const multisig_tx_set &txs) +{ + // Must succeed before any txset produced with these nonces is exposed. + bool changed = false; + for (const auto &ptx: txs.m_ptx) + { + for (size_t idx: ptx.construction_data.selected_transfers) + { + std::vector &multisig_k = m_transfers[idx].m_multisig_k; + if (multisig_k.empty()) + continue; + memwipe(multisig_k.data(), multisig_k.size() * sizeof(multisig_k[0])); + multisig_k.clear(); + changed = true; + } + } + + if (changed) + store(); +} +//---------------------------------------------------------------------------------------------------- rct::multisig_kLRki wallet2::get_multisig_kLRki(size_t n, const rct::key &k) const { CHECK_AND_ASSERT_THROW_MES(n < m_transfers.size(), "Bad m_transfers index"); diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index cedfecbeb..074755002 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -1211,7 +1211,7 @@ private: bool load_multisig_tx(cryptonote::blobdata blob, multisig_tx_set &exported_txs, std::function accept_func = NULL); bool load_multisig_tx_from_file(const std::string &filename, multisig_tx_set &exported_txs, std::function accept_func = NULL); bool sign_multisig_tx_from_file(const std::string &filename, std::vector &txids, std::function accept_func); - bool sign_multisig_tx(multisig_tx_set &exported_txs, std::vector &txids); + bool sign_multisig_tx(multisig_tx_set &exported_txs_inout, std::vector &txids); bool sign_multisig_tx_to_file(multisig_tx_set &exported_txs, const std::string &filename, std::vector &txids); std::vector create_unmixable_sweep_transactions(); void discard_unmixable_outputs(); @@ -1908,6 +1908,7 @@ private: rct::multisig_kLRki get_multisig_composite_kLRki(size_t n, const std::unordered_set &ignore_set, std::unordered_set &used_L, std::unordered_set &new_used_L) const; rct::multisig_kLRki get_multisig_kLRki(size_t n, const rct::key &k) const; void get_multisig_k(size_t idx, const std::unordered_set &used_L, rct::key &nonce); + void clear_multisig_k_and_store(const multisig_tx_set &txs); void update_multisig_rescan_info(const std::vector> &multisig_k, const std::vector> &info, size_t n); bool add_rings(const crypto::chacha_key &key, const cryptonote::transaction_prefix &tx); bool add_rings(const cryptonote::transaction_prefix &tx);