From abd1e5776481037b5d16d0de3f0737783d36527f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=BA=C3=B1ez?= Date: Wed, 20 Mar 2024 18:03:48 +0100 Subject: [PATCH] cargo-fix'n stuff --- ferveo/src/refresh.rs | 49 ++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/ferveo/src/refresh.rs b/ferveo/src/refresh.rs index 37838465..852df778 100644 --- a/ferveo/src/refresh.rs +++ b/ferveo/src/refresh.rs @@ -216,12 +216,11 @@ pub struct ShareUpdate { } impl ShareUpdate { - // TODO: Unit tests pub fn verify(&self, target_validator_public_key: E::G2) -> Result { let is_valid = E::pairing(E::G1::generator(), self.update) == E::pairing(self.commitment, target_validator_public_key); - if is_valid{ + if is_valid { Ok(true) } else { Err(Error::InvalidShareUpdate) @@ -278,19 +277,21 @@ impl UpdateTranscript { validator_public_keys: &HashMap, domain: &ark_poly::GeneralEvaluationDomain, ) -> Result { - // TODO: Make sure input validators and transcript validators match // TODO: Validate update polynomial commitments C_i are consistent with the type of update // Validate consistency between share updates, validator keys and polynomial commitments. // Let's first reconstruct the expected update commitments from the polynomial commitments: - let mut reconstructed_commitments = batch_to_projective_g1::(&self.coeffs); + let mut reconstructed_commitments = + batch_to_projective_g1::(&self.coeffs); domain.fft_in_place(&mut reconstructed_commitments); - for (index, update) in self.updates.iter(){ + for (index, update) in self.updates.iter() { // Next, validate share updates against their corresponding target validators - update.verify(*validator_public_keys.get(&index).unwrap()).unwrap(); + update + .verify(*validator_public_keys.get(index).unwrap()) + .unwrap(); // Finally, validate update commitments against update polynomial commitments let expected_commitment = reconstructed_commitments @@ -305,7 +306,6 @@ impl UpdateTranscript { } } - /// Prepare share updates with a given root (0 for refresh, some x coord for recovery) /// This is a helper function for `ShareUpdate::create_share_updates_for_recovery` and `ShareUpdate::create_share_updates_for_refresh` /// It generates a new random polynomial with a defined root and evaluates it at each of the participants' indices. @@ -650,7 +650,7 @@ mod tests_refresh { ( ctxt.index as u32, ctxt.public_decryption_contexts[ctxt.index] - .validator_public_key, + .validator_public_key, ) }) .collect::>(); @@ -680,20 +680,25 @@ mod tests_refresh { blinded_key_share.validator_public_key; // Current participant receives update transcripts from other participants - let updates_for_participant: Vec<_> = update_transcripts_by_producer - .values() - .map(|update_transcript_from_producer| { - // First, verify that the update transcript is valid - // TODO: Find a better way to ensure they're always validated - update_transcript_from_producer.verify(validator_keys_map, &fft_domain).unwrap(); - - let update_for_participant = update_transcript_from_producer.updates - .get(&(p.index as u32)) - .cloned() - .unwrap(); - update_for_participant - }) - .collect(); + let updates_for_participant: Vec<_> = + update_transcripts_by_producer + .values() + .map(|update_transcript_from_producer| { + // First, verify that the update transcript is valid + // TODO: Find a better way to ensure they're always validated + update_transcript_from_producer + .verify(validator_keys_map, &fft_domain) + .unwrap(); + + let update_for_participant = + update_transcript_from_producer + .updates + .get(&(p.index as u32)) + .cloned() + .unwrap(); + update_for_participant + }) + .collect(); // And creates a new, refreshed share