From 5d2b4a672af39dc15f262e6431922b95ab846f7d Mon Sep 17 00:00:00 2001 From: Artem Gureev Date: Tue, 7 Jul 2026 18:06:46 +0000 Subject: [PATCH] fix(wallet): locate self-sent notes by nullifier --- lez/wallet/src/lib.rs | 9 ++++++++- lez/wallet/src/storage/key_chain.rs | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lez/wallet/src/lib.rs b/lez/wallet/src/lib.rs index 75c56fec..93db8bf0 100644 --- a/lez/wallet/src/lib.rs +++ b/lez/wallet/src/lib.rs @@ -494,9 +494,16 @@ impl WalletCore { tx: &lee::privacy_preserving_transaction::PrivacyPreservingTransaction, acc_decode_mask: &[AccDecodeData], ) -> Result<()> { - for (output_index, acc_decode_data) in acc_decode_mask.iter().enumerate() { + for acc_decode_data in acc_decode_mask { match acc_decode_data { AccDecodeData::Decode(secret, acc_account_id) => { + let Some(output_index) = self + .storage + .key_chain() + .locate_spend(*acc_account_id, &tx.message) + else { + continue; + }; let acc_ead = tx.message.encrypted_private_post_states[output_index].clone(); let (kind, res_acc) = lee_core::EncryptionScheme::decrypt( diff --git a/lez/wallet/src/storage/key_chain.rs b/lez/wallet/src/storage/key_chain.rs index f03b035d..dff8ef2c 100644 --- a/lez/wallet/src/storage/key_chain.rs +++ b/lez/wallet/src/storage/key_chain.rs @@ -445,6 +445,21 @@ impl UserKeyChain { Some(new_nullifier) } + #[must_use] + pub fn locate_spend(&self, account_id: AccountId, message: &Message) -> Option { + let init = Nullifier::for_account_initialization(&account_id); + let update = self.private_account(account_id).map(|acc| { + Nullifier::for_account_update( + &Commitment::new(&account_id, acc.account), + &acc.key_chain.private_key_holder.nullifier_secret_key, + ) + }); + message + .new_nullifiers + .iter() + .position(|(nullifier, _)| *nullifier == init || Some(nullifier) == update.as_ref()) + } + pub fn add_imported_public_account(&mut self, private_key: lee::PrivateKey) { let account_id = AccountId::from(&lee::PublicKey::new_from_private_key(&private_key));