Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
fkettelhoit committed Sep 9, 2024
1 parent 1ac9228 commit 1112230
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 39 deletions.
2 changes: 1 addition & 1 deletion benches/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn join_benchmark(c: &mut Criterion) {
)]),
),
]);
let prg = compile_with_constants(&code, consts).unwrap();
let prg = compile_with_constants(code, consts).unwrap();
println!("{}", prg.circuit.report_gates());
let elapsed = now.elapsed();
println!(
Expand Down
18 changes: 10 additions & 8 deletions src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub enum ErrorKind {
InvalidLength,
}

type ChunkAndRemaining = (Vec<u8>, usize);

/// A communication channel used to send/receive messages to/from another party.
pub trait Channel {
/// The error that can occur sending messages over the channel.
Expand All @@ -53,7 +55,7 @@ pub trait Channel {
party: usize,
phase: &str,
i: usize,
) -> impl Future<Output = Result<(Vec<u8>, usize), Self::RecvError>> + Send;
) -> impl Future<Output = Result<ChunkAndRemaining, Self::RecvError>> + Send;
}

/// A wrapper around [`Channel`] that takes care of (de-)serializing messages.
Expand Down Expand Up @@ -142,8 +144,8 @@ impl<C: Channel> MsgChannel<C> {
/// A simple synchronous channel using [`Sender`] and [`Receiver`].
#[derive(Debug)]
pub struct SimpleChannel {
s: Vec<Option<Sender<(Vec<u8>, usize)>>>,
r: Vec<Option<Receiver<(Vec<u8>, usize)>>>,
s: Vec<Option<Sender<ChunkAndRemaining>>>,
r: Vec<Option<Receiver<ChunkAndRemaining>>>,
}

impl SimpleChannel {
Expand Down Expand Up @@ -187,7 +189,7 @@ pub enum AsyncRecvError {
}

impl Channel for SimpleChannel {
type SendError = SendError<(Vec<u8>, usize)>;
type SendError = SendError<ChunkAndRemaining>;
type RecvError = AsyncRecvError;

async fn send_bytes_to(
Expand All @@ -197,7 +199,7 @@ impl Channel for SimpleChannel {
i: usize,
remaining: usize,
msg: Vec<u8>,
) -> Result<(), SendError<(Vec<u8>, usize)>> {
) -> Result<(), SendError<ChunkAndRemaining>> {
let mb = msg.len() as f64 / 1024.0 / 1024.0;
let i = i + 1;
let total = i + remaining;
Expand All @@ -218,15 +220,15 @@ impl Channel for SimpleChannel {
p: usize,
_phase: &str,
_i: usize,
) -> Result<(Vec<u8>, usize), AsyncRecvError> {
) -> Result<ChunkAndRemaining, AsyncRecvError> {
let chunk = self.r[p]
.as_mut()
.unwrap_or_else(|| panic!("No receiver for party {p}"))
.recv();
match timeout(Duration::from_secs(10 * 60), chunk).await {
Ok(Some((bytes, remaining))) => Ok((bytes, remaining)),
Ok(None) => return Err(AsyncRecvError::Closed),
Err(_) => return Err(AsyncRecvError::TimeoutElapsed),
Ok(None) => Err(AsyncRecvError::Closed),
Err(_) => Err(AsyncRecvError::TimeoutElapsed),
}
}
}
42 changes: 24 additions & 18 deletions src/faand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub(crate) async fn shared_rng(
.recv_from(p, "RNG")
.await?
.pop()
.ok_or_else(|| Error::EmptyMsg)?;
.ok_or(Error::EmptyMsg)?;
commitments[p] = commitment;
bufs[p] = buffer;
}
Expand Down Expand Up @@ -249,7 +249,7 @@ pub(crate) async fn fabitn(
for p in (0..p_max).filter(|p| *p != p_own) {
fabitn_msg.iter_mut().enumerate().for_each(|(i, msg)| {
msg.1 = macint[p][i];
});
});
channel.send_to(p, "fabitn", &fabitn_msg).await?;
}

Expand Down Expand Up @@ -355,10 +355,11 @@ pub(crate) async fn fashare(
.send_to(p, "fashare commitverify", &own_commitments)
.await?;
}
let mut commitments: Vec<Vec<(Commitment, Commitment, Commitment, Vec<u8>)>> =
vec![vec![]; p_max];
let mut commitments = vec![vec![]; p_max];
for p in (0..p_max).filter(|p| *p != p_own) {
commitments[p] = channel.recv_from(p, "fashare commitverify").await?;
commitments[p] = channel
.recv_from::<(Commitment, Commitment, Commitment, Vec<u8>)>(p, "fashare commitverify")
.await?;
}
commitments[p_own] = own_commitments;

Expand Down Expand Up @@ -770,18 +771,22 @@ pub(crate) async fn faand(
}
channel.send_to(p, "faand", &ef_with_macs).await?;
}
let mut faand_vec: Vec<Vec<(bool, bool, Option<Mac>, Option<Mac>)>> =
vec![vec![(false, false, None, None); vectriples.len()]; p_max];
let mut faand_vec = vec![vec![(false, false, None, None); vectriples.len()]; p_max];
for p in (0..p_max).filter(|p| *p != p_own) {
faand_vec[p] = channel.recv_from(p, "faand").await?;
faand_vec[p] = channel
.recv_from::<(bool, bool, Option<Mac>, Option<Mac>)>(p, "faand")
.await?;
}
ef_with_macs.iter_mut().enumerate().for_each(|(i, (e, f, _, _))| {
for p in (0..p_max).filter(|&p| p != p_own) {
let (fa_e, fa_f, _, _) = faand_vec[p][i];
*e ^= fa_e;
*f ^= fa_f;
}
});
ef_with_macs
.iter_mut()
.enumerate()
.for_each(|(i, (e, f, _, _))| {
for p in (0..p_max).filter(|&p| p != p_own) {
let (fa_e, fa_f, _, _) = faand_vec[p][i];
*e ^= fa_e;
*f ^= fa_f;
}
});
let mut result = vec![Share(false, Auth(vec![])); vectriples.len()];

for i in 0..vectriples.len() {
Expand Down Expand Up @@ -857,10 +862,11 @@ pub(crate) async fn check_dvalue(
channel.send_to(p, "dvalue", &dvalue_msg).await?;
}

let mut dvalue_msg_p: Vec<Vec<(Vec<bool>, Vec<Option<Mac>>)>> =
vec![vec![(vec![], vec![]); buckets.len()]; p_max];
let mut dvalue_msg_p = vec![vec![(vec![], vec![]); buckets.len()]; p_max];
for p in (0..p_max).filter(|p| *p != p_own) {
dvalue_msg_p[p] = channel.recv_from(p, "dvalue").await?;
dvalue_msg_p[p] = channel
.recv_from::<(Vec<bool>, Vec<Option<Mac>>)>(p, "dvalue")
.await?;
}

for p in (0..p_max).filter(|p| *p != p_own) {
Expand Down
22 changes: 11 additions & 11 deletions src/fpre.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ where
.recv_from(p, "random shares (fpre)")
.await?
.pop()
.ok_or_else(|| Error::EmptyMsg)?;
.ok_or(Error::EmptyMsg)?;
if num_shares > 0 && num_shares != r {
let e = Error::RandomSharesMismatch(num_shares, r);
for p in 0..parties {
Expand Down Expand Up @@ -352,12 +352,12 @@ mod tests {
.recv_from(fpre_party, "delta")
.await?
.pop()
.ok_or_else(|| Error::EmptyMsg)?;
.ok_or(Error::EmptyMsg)?;
let delta_b: Delta = b
.recv_from(fpre_party, "delta")
.await?
.pop()
.ok_or_else(|| Error::EmptyMsg)?;
.ok_or(Error::EmptyMsg)?;

// random r1, r2, s1, s2:
a.send_to(fpre_party, "random shares", &[2_u32]).await?;
Expand Down Expand Up @@ -416,12 +416,12 @@ mod tests {
.recv_from(fpre_party, "delta")
.await?
.pop()
.ok_or_else(|| Error::EmptyMsg)?;
.ok_or(Error::EmptyMsg)?;
let delta_b: Delta = b
.recv_from(fpre_party, "delta")
.await?
.pop()
.ok_or_else(|| Error::EmptyMsg)?;
.ok_or(Error::EmptyMsg)?;

// random r1, r2, s1, s2:
a.send_to(fpre_party, "random shares", &[2_u32]).await?;
Expand All @@ -445,9 +445,9 @@ mod tests {

if i == 0 {
// uncorrupted authenticated (r1 XOR s1) AND (r2 XOR s2):
a.send_to(fpre_party, "AND shares", &vec![(auth_r1, auth_r2)])
a.send_to(fpre_party, "AND shares", &[(auth_r1, auth_r2)])
.await?;
b.send_to(fpre_party, "AND shares", &vec![(auth_s1, auth_s2)])
b.send_to(fpre_party, "AND shares", &[(auth_s1, auth_s2)])
.await?;
let Share(r3, Auth(mac_r3_key_s3)) = a
.recv_from::<Share>(fpre_party, "AND shares")
Expand All @@ -470,10 +470,10 @@ mod tests {
a.send_to(
fpre_party,
"AND shares",
&vec![(auth_r1_corrupted, auth_r2)],
&[(auth_r1_corrupted, auth_r2)],
)
.await?;
b.send_to(fpre_party, "AND shares", &vec![(auth_s1, auth_s2)])
b.send_to(fpre_party, "AND shares", &[(auth_s1, auth_s2)])
.await?;
assert_eq!(
a.recv_from::<String>(fpre_party, "AND shares").await?,
Expand All @@ -491,10 +491,10 @@ mod tests {
a.send_to(
fpre_party,
"AND shares",
&vec![(auth_r1_corrupted, auth_r2)],
&[(auth_r1_corrupted, auth_r2)],
)
.await?;
b.send_to(fpre_party, "AND shares", &vec![(auth_s1, auth_s2)])
b.send_to(fpre_party, "AND shares", &[(auth_s1, auth_s2)])
.await?;
assert_eq!(
a.recv_from::<Share>(fpre_party, "AND shares").await?.len(),
Expand Down
2 changes: 1 addition & 1 deletion src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ pub async fn mpc(
.recv_from(p_fpre, "delta")
.await?
.pop()
.ok_or_else(|| Error::EmptyMsg)?;
.ok_or(Error::EmptyMsg)?;
} else {
for p in (0..p_max).filter(|p| *p != p_own) {
let (d, u, b, w) = generate_ots(secret_bits_ot + 3 * faand_len).await.unwrap();
Expand Down

0 comments on commit 1112230

Please sign in to comment.