From 0c56bad680af07160be4d31e473f4d4f90881806 Mon Sep 17 00:00:00 2001 From: Mikkel Wienberg Madsen Date: Fri, 14 Jun 2024 16:19:58 +0200 Subject: [PATCH] cargo fmt --- src/marker/mod.rs | 6 +--- src/schemes/mod.rs | 1 - src/schemes/spdz.rs | 51 +++++++++++++++---------------- src/schemes/spdz/preprocessing.rs | 2 -- 4 files changed, 26 insertions(+), 34 deletions(-) diff --git a/src/marker/mod.rs b/src/marker/mod.rs index 6e8a46e..f3899de 100644 --- a/src/marker/mod.rs +++ b/src/marker/mod.rs @@ -42,11 +42,7 @@ impl Unverified { } impl<'ctx, S: InteractiveShared<'ctx>> Verified { - pub async fn open( - self, - ctx: S::Context, - coms: impl Communicate, - ) -> Result { + pub async fn open(self, ctx: S::Context, coms: impl Communicate) -> Result { S::recombine(ctx, self.0, coms).await } diff --git a/src/schemes/mod.rs b/src/schemes/mod.rs index 749106e..37b3a84 100644 --- a/src/schemes/mod.rs +++ b/src/schemes/mod.rs @@ -35,7 +35,6 @@ use rand::RngCore; use crate::net::Communicate; - /// Currently unused trait, but might be a better way to represent that a share /// can be multiplied by a const, however, it could also just be baked into 'Shared' directly. pub trait MulByConst: diff --git a/src/schemes/spdz.rs b/src/schemes/spdz.rs index 3718f66..1cf7a78 100644 --- a/src/schemes/spdz.rs +++ b/src/schemes/spdz.rs @@ -6,16 +6,15 @@ //! But for now that is handled by a dealer. //! - // TODO: make costum errors. -use crate::{net::Communicate, schemes::interactive::InteractiveShared}; -use ff::PrimeField; -use rand::RngCore; use crate::{ net::agency::Broadcast, protocols::commitments::{commit, verify_commit}, }; +use crate::{net::Communicate, schemes::interactive::InteractiveShared}; use derive_more::{Add, AddAssign, Sub, SubAssign}; +use ff::PrimeField; +use rand::RngCore; use self::preprocessing::ForSharing; @@ -99,22 +98,22 @@ where } impl<'ctx, F> InteractiveShared<'ctx> for Share -where F: PrimeField + serde::Serialize + serde::de::DeserializeOwned + std::convert::Into, +where + F: PrimeField + serde::Serialize + serde::de::DeserializeOwned + std::convert::Into, { type Context = &'ctx mut SpdzContext; type Value = F; type Error = (); async fn share( - _ctx: Self::Context, - _secret: Self::Value, - _rng: impl RngCore + Send, - _coms: impl Communicate, - ) -> Result { + _ctx: Self::Context, + _secret: Self::Value, + _rng: impl RngCore + Send, + _coms: impl Communicate, + ) -> Result { todo!() } - async fn symmetric_share( _ctx: Self::Context, _secret: Self::Value, @@ -123,23 +122,27 @@ where F: PrimeField + serde::Serialize + serde::de::DeserializeOwned + std::conv ) -> Result, Self::Error> { todo!() } - + async fn receive_share( - _ctx: Self::Context, - _coms: impl Communicate, - _from: usize, - ) -> Result { + _ctx: Self::Context, + _coms: impl Communicate, + _from: usize, + ) -> Result { todo!() } // This might not be the propper way to do recombine - it depends on what exanctly recombine is suppose to mean :) - async fn recombine(ctx: Self::Context, share: Self, mut network: impl Communicate) -> Result { - Ok(open_res(share, &mut network, &ctx.params, todo!("opened values")).await) + async fn recombine( + ctx: Self::Context, + share: Self, + mut network: impl Communicate, + ) -> Result { + Ok(open_res(share, &mut network, &ctx.params, &ctx.opened_values).await) } } -// This impl of share_many only works if the party is either sending or resiving all the elements. -// This is by design, as only the sender needs to broadcast, and that is where there are something to be won by doing it in bulk. +// This impl of share_many only works if the party is either sending or resiving all the elements. +// This is by design, as only the sender needs to broadcast, and that is where there are something to be won by doing it in bulk. pub async fn share( op_vals: Option>, for_sharing: &mut ForSharing, @@ -295,7 +298,6 @@ where .pop() .expect("Atleast one element must be opened"); while let Some(ov) = opened_vals.pop() { - for i in 0..n { opened_vals_sum[i] += ov[i]; } @@ -421,10 +423,10 @@ fn power>(base: F, ex #[cfg(test)] mod test { - use std::io::Seek; use ff::Field; use rand::thread_rng; use rand::SeedableRng; + use std::io::Seek; use crate::{algebra::element::Element32, net::network::InMemoryNetwork}; @@ -1454,10 +1456,7 @@ mod test { fn test_dealer_writing_to_file() { // preprosessing by dealer type F = Element32; - let mut files = [ - tempfile::tempfile().unwrap(), - tempfile::tempfile().unwrap(), - ]; + let mut files = [tempfile::tempfile().unwrap(), tempfile::tempfile().unwrap()]; let known_to_each = vec![1, 2]; let number_of_triplets = 2; preprocessing::write_preproc_to_file( diff --git a/src/schemes/spdz/preprocessing.rs b/src/schemes/spdz/preprocessing.rs index 79f4cca..3349e53 100644 --- a/src/schemes/spdz/preprocessing.rs +++ b/src/schemes/spdz/preprocessing.rs @@ -107,7 +107,6 @@ pub fn write_preproc_to_file( file: &mut File, ) -> SpdzContext { @@ -115,7 +114,6 @@ pub fn read_preproc_from_file( mut rng: impl rand::Rng, known_to_each: Vec,