diff --git a/src/carrot_impl/account.cpp b/src/carrot_impl/account.cpp index 57593b07f..082eb39e7 100644 --- a/src/carrot_impl/account.cpp +++ b/src/carrot_impl/account.cpp @@ -110,7 +110,7 @@ CarrotDestinationV1 carrot_and_legacy_account::subaddress(const subaddress_index return addr; } //---------------------------------------------------------------------------------------------------------------------- -std::unordered_map carrot_and_legacy_account::get_subaddress_map() const +std::unordered_map carrot_and_legacy_account::get_subaddress_map_cn() const { std::unordered_map res; for (const auto &p : subaddress_map) diff --git a/src/carrot_impl/account.h b/src/carrot_impl/account.h index b864b0140..424d89cc9 100644 --- a/src/carrot_impl/account.h +++ b/src/carrot_impl/account.h @@ -69,7 +69,7 @@ namespace carrot CarrotDestinationV1 subaddress(const subaddress_index_extended &subaddress_index) const; - std::unordered_map get_subaddress_map() const; + std::unordered_map get_subaddress_map_cn() const; // brief: opening_for_subaddress - return (k^g_a, k^t_a) for j s.t. K^j_s = (k^g_a * G + k^t_a * T) void opening_for_subaddress(const subaddress_index_extended &subaddress_index, diff --git a/src/wallet/scanning_tools.cpp b/src/wallet/scanning_tools.cpp index 3f128f913..87f2aa436 100644 --- a/src/wallet/scanning_tools.cpp +++ b/src/wallet/scanning_tools.cpp @@ -142,9 +142,11 @@ static std::optional view_incoming_scan_pre_car const std::optional &encrypted_payment_id, const epee::span main_derivations, const epee::span additional_derivations, - const std::unordered_map &subaddress_map, + carrot::carrot_and_legacy_account &account, hw::device &hwdev) { + const std::unordered_map &subaddress_map = account.get_subaddress_map_cn(); + boost::optional receive_info; size_t main_deriv_idx; for (main_deriv_idx = 0; main_deriv_idx < std::max(1, main_derivations.size()); ++main_deriv_idx) @@ -236,6 +238,12 @@ static std::optional view_incoming_scan_pre_car .derive_type = carrot::AddressDeriveType::PreCarrot }; + // HERE BE DRAGONS!!! + // SRCG: whilst the following code will work, it'd be better being moved to the TX_BUILDER code + // add the entry to our subaddress map in case it's a change payment (false positives won't hurt us) + account.subaddress_map.insert({enote.onetime_address, subaddr_index}); + // LAND AHOY!!! + return enote_view_incoming_scan_info_t{ .sender_extension_g = sender_extension_g, .sender_extension_t = crypto::null_skey, @@ -331,7 +339,7 @@ static std::optional view_incoming_scan_carrot_ const mx25519_pubkey &s_sender_receiver_unctx, const crypto::public_key &main_address_spend_pubkey, const carrot::view_incoming_key_device &k_view_dev, - const std::unordered_map &subaddress_map) + carrot::carrot_and_legacy_account &account) { enote_view_incoming_scan_info_t res; @@ -352,13 +360,13 @@ static std::optional view_incoming_scan_carrot_ dummy_enote_type)) return std::nullopt; - const auto subaddr_it = subaddress_map.find(res.address_spend_pubkey); - CHECK_AND_ASSERT_MES(subaddr_it != subaddress_map.cend(), + const auto subaddr_it = account.subaddress_map.find(res.address_spend_pubkey); + CHECK_AND_ASSERT_MES(subaddr_it != account.subaddress_map.cend(), std::nullopt, "view_incoming_scan_carrot_enote: carrot enote scanned successfully, " "but the recovered address spend pubkey was not found in the subaddress map"); - const carrot::subaddress_index_extended subaddr_index = {{subaddr_it->second.major, subaddr_it->second.minor}}; + const carrot::subaddress_index_extended subaddr_index = subaddr_it->second; memset(&res.payment_id, 0, sizeof(res.payment_id)); memcpy(&res.payment_id, &payment_id, sizeof(carrot::payment_id_t)); @@ -461,7 +469,7 @@ std::optional view_incoming_scan_enote( const epee::span additional_derivations, const cryptonote::account_public_address &address, const carrot::view_incoming_key_device *k_view_dev, - const std::unordered_map &subaddress_map, + carrot::carrot_and_legacy_account &account, hw::device &hwdev) { CHECK_AND_ASSERT_MES(!main_derivations.empty() || !additional_derivations.empty(), @@ -487,7 +495,7 @@ std::optional view_incoming_scan_enote( encrypted_payment_id, main_derivations, additional_derivations, - subaddress_map, + account, hwdev); // copy long plaintext payment ID, if applicable @@ -532,7 +540,7 @@ std::optional view_incoming_scan_enote( s_sender_receiver_unctx, address.m_spend_public_key, *k_view_dev, - subaddress_map); + account); } } @@ -543,7 +551,7 @@ std::optional view_incoming_scan_enote( const epee::span additional_derivations; const cryptonote::account_public_address &address; const carrot::view_incoming_key_device *k_view_dev; - const std::unordered_map &subaddress_map; + carrot::carrot_and_legacy_account &account; hw::device &hwdev; }; @@ -555,7 +563,7 @@ std::optional view_incoming_scan_enote( additional_derivations, address, k_view_dev, - subaddress_map, + account, hwdev }, enote); @@ -571,7 +579,7 @@ std::optional view_incoming_scan_enote( const epee::span additional_derivations, const cryptonote::account_public_address &address, const carrot::view_incoming_key_device *k_view_dev, - const std::unordered_map &subaddress_map, + carrot::carrot_and_legacy_account &account, hw::device &hwdev) { MoneroEnoteVariant enote; @@ -628,7 +636,7 @@ std::optional view_incoming_scan_enote( additional_derivations, address, k_view_dev, - subaddress_map, + account, hwdev); } //------------------------------------------------------------------------------------------------------------------- @@ -639,7 +647,7 @@ std::optional view_incoming_scan_enote_from_pre const std::size_t local_output_index, const cryptonote::account_public_address &address, const crypto::secret_key &k_view_incoming, - const std::unordered_map &subaddress_map, + carrot::carrot_and_legacy_account &account, hw::device &hwdev) { const bool is_carrot = carrot::is_carrot_transaction_v1(tx_prefix); @@ -692,7 +700,7 @@ std::optional view_incoming_scan_enote_from_pre epee::to_span(additional_derivations), address, &k_view_dev, - subaddress_map, + account, hwdev); } //------------------------------------------------------------------------------------------------------------------- @@ -733,7 +741,7 @@ void view_incoming_scan_transaction( additional_derivations, address, &k_view_dev, - account.get_subaddress_map(), + account, account.get_keys().get_device()); } } @@ -817,6 +825,8 @@ std::vector> view_incoming_scan_t // 3. do view-incoming scan for each output enotes hw::device &hwdev = hw::get_device("default"); + carrot::carrot_and_legacy_account dummy_account; + dummy_account.subaddress_map[address.m_spend_public_key] = {{}}; for (size_t local_output_index = 0; local_output_index < n_outputs; ++local_output_index) { auto &enote_scan_info = res[local_output_index]; @@ -830,7 +840,7 @@ std::vector> view_incoming_scan_t custom_additional_derivations, address, /*k_view_dev=*/nullptr, - {{address.m_spend_public_key, {}}}, + dummy_account, hwdev); } diff --git a/src/wallet/scanning_tools.h b/src/wallet/scanning_tools.h index f971434f7..e1cc29e9b 100644 --- a/src/wallet/scanning_tools.h +++ b/src/wallet/scanning_tools.h @@ -122,7 +122,7 @@ std::optional view_incoming_scan_enote_from_pre const std::size_t local_output_index, const cryptonote::account_public_address &address, const crypto::secret_key &k_view_incoming, - const std::unordered_map &subaddress_map, + carrot::carrot_and_legacy_account &account, hw::device &hwdev); void view_incoming_scan_transaction( diff --git a/src/wallet/tx_builder.cpp b/src/wallet/tx_builder.cpp index 24f3df2d7..5db15f74b 100644 --- a/src/wallet/tx_builder.cpp +++ b/src/wallet/tx_builder.cpp @@ -630,7 +630,7 @@ std::vector make_carrot_transaction_proposa const bool is_selfsend_dest = build_payment_proposals(normal_payment_proposals, selfsend_payment_proposals, de, - w.get_account().get_subaddress_map()); + w.get_account().get_subaddress_map_cn()); CHECK_AND_ASSERT_THROW_MES((is_selfsend_dest && selfsend_payment_proposals.size() == i+1) || (!is_selfsend_dest && normal_payment_proposals.size() == i+1), __func__ << ": BUG in build_payment_proposals: incorrect count for payment proposal lists"); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index c3adc024a..643a0dfb2 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2664,7 +2664,7 @@ void wallet2::process_new_scanned_transaction( origin_tx_data.tx_type = td_origin.m_tx.type; rct::salvium_input_data_t sid; THROW_WALLET_EXCEPTION_IF(!cryptonote::generate_key_image_helper(m_account.get_keys(), - m_account.get_subaddress_map(), + m_account.get_subaddress_map_cn(), onetime_address, tx_public_key, additional_tx_public_keys, @@ -10414,7 +10414,7 @@ void wallet2::transfer_selected_rct(std::vector> circ_amounts; THROW_WALLET_EXCEPTION_IF(!get_circulating_supply(circ_amounts), error::wallet_internal_error, "Failed to get circulating supply"); // make a normal tx - bool r = cryptonote::construct_tx_and_get_tx_key(a_keys/*m_account.get_keys()*/, m_account.get_subaddress_map(), sources, splitted_dsts, hf_version, source_asset, dest_asset, tx_type, change_dts.addr, extra, tx, unlock_time, tx_key, additional_tx_keys, true, rct_config, use_view_tags); + bool r = cryptonote::construct_tx_and_get_tx_key(a_keys/*m_account.get_keys()*/, m_account.get_subaddress_map_cn(), sources, splitted_dsts, hf_version, source_asset, dest_asset, tx_type, change_dts.addr, extra, tx, unlock_time, tx_key, additional_tx_keys, true, rct_config, use_view_tags); LOG_PRINT_L2("constructed tx, r="<main_tx_pubkey_index : 0;