From e1fd462a502329593a7aaf8bbc9533f57300671b Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Sat, 21 May 2022 21:44:57 -0400 Subject: [PATCH] Properly calculate uniqueness when creating change outputs It was missing sorting its inputs by their key images. --- coins/monero/src/wallet/send/mod.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/coins/monero/src/wallet/send/mod.rs b/coins/monero/src/wallet/send/mod.rs index 5254d3e3..e1462c4e 100644 --- a/coins/monero/src/wallet/send/mod.rs +++ b/coins/monero/src/wallet/send/mod.rs @@ -289,14 +289,20 @@ impl SignableTransaction { rpc: &Rpc, spend: &Scalar ) -> Result { + let mut images = Vec::with_capacity(self.inputs.len()); + for input in &self.inputs { + images.push(generate_key_image(&(spend + input.key_offset))); + } + images.sort_by(|x, y| x.compress().to_bytes().cmp(&y.compress().to_bytes()).reverse()); + let (commitments, mask_sum) = self.prepare_outputs( rng, Some( uniqueness( - &self.inputs.iter().map(|input| Input::ToKey { + &images.iter().map(|image| Input::ToKey { amount: 0, key_offsets: vec![], - key_image: generate_key_image(&(spend + input.key_offset)) + key_image: *image }).collect::>() ) )