From 0a79a4d9fd92f1dce447f90870779949e5cf166c Mon Sep 17 00:00:00 2001 From: auruya Date: Tue, 21 Oct 2025 10:26:20 +0300 Subject: [PATCH] fix check_tx_key for carrot tx using x25519 derivation --- src/wallet/wallet2.cpp | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index a86b3057c..18f7381c2 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -12999,15 +12999,44 @@ bool wallet2::check_spend_proof(const crypto::hash &txid, const std::string &mes void wallet2::check_tx_key(const crypto::hash &txid, const crypto::secret_key &tx_key, const std::vector &additional_tx_keys, const cryptonote::account_public_address &address, uint64_t &received, bool &in_pool, uint64_t &confirmations) { crypto::key_derivation derivation; - THROW_WALLET_EXCEPTION_IF(!crypto::generate_key_derivation(address.m_view_public_key, tx_key, derivation), error::wallet_internal_error, - "Failed to generate key derivation from supplied parameters"); - std::vector additional_derivations; - additional_derivations.resize(additional_tx_keys.size()); - for (size_t i = 0; i < additional_tx_keys.size(); ++i) - THROW_WALLET_EXCEPTION_IF(!crypto::generate_key_derivation(address.m_view_public_key, additional_tx_keys[i], additional_derivations[i]), error::wallet_internal_error, + if (address.m_is_carrot) + { + // For Carrot enotes, use X25519 scalar multiplication + mx25519_pubkey s_sender_receiver_unctx; + bool success = carrot::make_carrot_uncontextualized_shared_key_sender( + tx_key, + address.m_view_public_key, + s_sender_receiver_unctx); + THROW_WALLET_EXCEPTION_IF(!success, error::wallet_internal_error, + "Failed to generate X25519 key derivation from supplied parameters (main)"); + derivation = carrot::raw_byte_convert(s_sender_receiver_unctx); + + additional_derivations.resize(additional_tx_keys.size()); + for (size_t i = 0; i < additional_tx_keys.size(); ++i) + { + mx25519_pubkey additional_s_sender_receiver_unctx; + success = carrot::make_carrot_uncontextualized_shared_key_sender( + additional_tx_keys[i], + address.m_view_public_key, + additional_s_sender_receiver_unctx); + THROW_WALLET_EXCEPTION_IF(!success, error::wallet_internal_error, + "Failed to generate X25519 key derivation from supplied parameters (additional)"); + additional_derivations[i] = carrot::raw_byte_convert(additional_s_sender_receiver_unctx); + } + } + else + { + // For legacy enotes, use Edwards curve multiplication + THROW_WALLET_EXCEPTION_IF(!crypto::generate_key_derivation(address.m_view_public_key, tx_key, derivation), error::wallet_internal_error, "Failed to generate key derivation from supplied parameters"); + additional_derivations.resize(additional_tx_keys.size()); + for (size_t i = 0; i < additional_tx_keys.size(); ++i) + THROW_WALLET_EXCEPTION_IF(!crypto::generate_key_derivation(address.m_view_public_key, additional_tx_keys[i], additional_derivations[i]), error::wallet_internal_error, + "Failed to generate key derivation from supplied parameters"); + } + check_tx_key_helper(txid, derivation, additional_derivations, address, received, in_pool, confirmations); }