From 874179685aa24463e9e991204f15dbd6cb76fe56 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 11 May 2021 12:31:37 +1000 Subject: [PATCH] Move Signature::verify under sign --- monero-adaptor/src/clsag.rs | 63 +++++++++++++++++++------------------ monero-adaptor/src/lib.rs | 2 +- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/monero-adaptor/src/clsag.rs b/monero-adaptor/src/clsag.rs index 5707141d..54937787 100644 --- a/monero-adaptor/src/clsag.rs +++ b/monero-adaptor/src/clsag.rs @@ -89,6 +89,37 @@ pub struct Signature { pub D: EdwardsPoint, } +impl Signature { + #[cfg(test)] + #[must_use] + pub fn verify(&self, ring: [EdwardsPoint; RING_SIZE], msg: &[u8; 32]) -> bool { + let ring_concat = ring + .iter() + .flat_map(|pk| pk.compress().as_bytes().to_vec()) + .collect::>(); + + let mut h = self.h_0; + + let mus = todo!(); + let adjusted_commitment_i = todo!(); + + for (i, s_i) in self.responses.iter().enumerate() { + let pk_i = ring[(i + 1) % RING_SIZE]; + let prefix = clsag_round_hash_prefix(&ring_concat, todo!(), todo!(), msg); + let L_i = compute_L(h, mus, *s_i, pk_i, adjusted_commitment_i); + let R_i = compute_R(h, mus, pk_i, *s_i, self.I, self.D); + + h = hash_to_scalar(&[ + &prefix, + L_i.compress().as_bytes().as_ref(), + R_i.compress().as_bytes().as_ref(), + ]) + } + + h == self.h_0 + } +} + /// Compute the prefix for the hash common to every iteration of the ring /// signature algorithm. /// @@ -158,7 +189,7 @@ struct AggregationHashes { } impl AggregationHashes { - pub fn new( + fn new( ring: &Ring, commitment_ring: &Ring, I: CompressedEdwardsY, @@ -192,36 +223,6 @@ impl AggregationHashes { } } -impl Signature { - #[cfg(test)] - pub fn verify(&self, ring: [EdwardsPoint; RING_SIZE], msg: &[u8; 32]) -> anyhow::Result { - let ring_concat = ring - .iter() - .flat_map(|pk| pk.compress().as_bytes().to_vec()) - .collect::>(); - - let mut h = self.h_0; - - let mus = todo!(); - let adjusted_commitment_i = todo!(); - - for (i, s_i) in self.responses.iter().enumerate() { - let pk_i = ring[(i + 1) % RING_SIZE]; - let prefix = clsag_round_hash_prefix(&ring_concat, todo!(), todo!(), msg); - let L_i = compute_L(h, mus, *s_i, pk_i, adjusted_commitment_i); - let R_i = compute_R(h, mus, pk_i, *s_i, self.I, self.D); - - h = hash_to_scalar(&[ - &prefix, - L_i.compress().as_bytes().as_ref(), - R_i.compress().as_bytes().as_ref(), - ]) - } - - Ok(h == self.h_0) - } -} - impl From for monero::util::ringct::Clsag { fn from(from: Signature) -> Self { Self { diff --git a/monero-adaptor/src/lib.rs b/monero-adaptor/src/lib.rs index c460bbb2..54baa9c6 100644 --- a/monero-adaptor/src/lib.rs +++ b/monero-adaptor/src/lib.rs @@ -631,6 +631,6 @@ mod tests { let sig = alice.adaptor_sig.adapt(r_a); - assert!(sig.verify(ring, msg_to_sign).unwrap()); + assert!(sig.verify(ring, msg_to_sign)); } }