Skip to content

Commit

Permalink
fix: clippy --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sinui0 committed Jun 25, 2024
1 parent 5ad1bea commit e25d123
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 45 deletions.
2 changes: 1 addition & 1 deletion crates/mpz-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ serde = { workspace = true, features = ["derive"] }
pollster.workspace = true
rayon = { workspace = true, optional = true }
cfg-if.workspace = true
tokio = { workspace = true, optional = true, default-features = false }
tokio = { workspace = true, optional = true }

[dev-dependencies]
tokio = { workspace = true, features = [
Expand Down
18 changes: 8 additions & 10 deletions crates/mpz-common/src/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ mod st {

/// Executes a closure on the CPU backend.
#[inline]
pub fn blocking<F, R>(f: F) -> impl Future<Output = R> + Send
pub async fn blocking<F, R>(f: F) -> R
where
F: FnOnce() -> R + Send + 'static,
R: Send + 'static,
{
async move { f() }
f()
}
}

Expand Down Expand Up @@ -88,18 +88,16 @@ mod rayon_backend {
}

/// Executes a closure on the CPU backend.
pub fn blocking<F, R>(f: F) -> impl Future<Output = R> + Send
pub async fn blocking<F, R>(f: F) -> R
where
F: FnOnce() -> R + Send + 'static,
R: Send + 'static,
{
async move {
let (sender, receiver) = oneshot::channel();
rayon::spawn(move || {
_ = sender.send(f());
});
receiver.await.expect("worker thread does not drop channel")
}
let (sender, receiver) = oneshot::channel();
rayon::spawn(move || {
_ = sender.send(f());
});
receiver.await.expect("worker thread does not drop channel")
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/mpz-common/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ pub struct Counter(u32);

impl Counter {
/// Increments the counter in place, returning the previous value.
#[allow(clippy::should_implement_trait)]
pub fn next(&mut self) -> Self {
let prev = self.0;
self.0 += 1;
Expand Down
2 changes: 1 addition & 1 deletion crates/mpz-fields/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,6 @@ mod tests {
assert!(GetBit::<Lsb0>::get_bit(&a, 0));

assert_eq!(b, T::two_pow(T::BIT_SIZE as u32 - 1));
assert!(GetBit::<Lsb0>::get_bit(&b, (T::BIT_SIZE - 1) as usize));
assert!(GetBit::<Lsb0>::get_bit(&b, T::BIT_SIZE - 1));
}
}
2 changes: 1 addition & 1 deletion crates/mpz-garble-core/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl EncryptedGate {
Self(inner)
}

pub(crate) fn to_bytes(&self) -> [u8; 32] {
pub(crate) fn to_bytes(self) -> [u8; 32] {
let mut bytes = [0u8; 32];
bytes[..16].copy_from_slice(&self.0[0].to_bytes());
bytes[16..].copy_from_slice(&self.0[1].to_bytes());
Expand Down
10 changes: 1 addition & 9 deletions crates/mpz-garble-core/src/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,12 @@ pub struct EvaluatorOutput {
}

/// Garbled circuit evaluator.
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct Evaluator {
/// Buffer for the active labels.
buffer: Vec<Label>,
}

impl Default for Evaluator {
fn default() -> Self {
Self {
buffer: Default::default(),
}
}
}

impl Evaluator {
/// Returns a consumer over the encrypted gates of a circuit.
///
Expand Down
14 changes: 3 additions & 11 deletions crates/mpz-garble-core/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,12 @@ pub struct GeneratorOutput {
}

/// Garbled circuit generator.
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct Generator {
/// Buffer for the 0-bit labels.
buffer: Vec<Label>,
}

impl Default for Generator {
fn default() -> Self {
Self {
buffer: Default::default(),
}
}
}

impl Generator {
/// Returns an iterator over the encrypted gates of a circuit.
///
Expand Down Expand Up @@ -295,7 +287,7 @@ where
// If we have generated all AND gates, we can compute
// the rest of the "free" gates.
if !self.has_gates() {
assert!(matches!(self.next(), None));
assert!(self.next().is_none());

self.complete = true;
}
Expand Down Expand Up @@ -356,7 +348,7 @@ where

let mut batch = [EncryptedGate::default(); N];
let mut i = 0;
while let Some(gate) = self.0.next() {
for gate in self.0.by_ref() {
batch[i] = gate;
i += 1;

Expand Down
4 changes: 2 additions & 2 deletions crates/mpz-garble-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ mod tests {
.iter()
.zip(full_outputs)
.map(|(active_output, full_output)| {
full_output.commit().verify(&active_output).unwrap();
full_output.commit().verify(active_output).unwrap();
active_output.decode(&full_output.decoding()).unwrap()
})
.collect();
Expand Down Expand Up @@ -234,7 +234,7 @@ mod tests {
.iter()
.zip(full_outputs)
.map(|(active_output, full_output)| {
full_output.commit().verify(&active_output).unwrap();
full_output.commit().verify(active_output).unwrap();
active_output.decode(&full_output.decoding()).unwrap()
})
.collect();
Expand Down
2 changes: 1 addition & 1 deletion crates/mpz-garble/src/protocol/deap/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ where
deap.finalize(&mut self.ctx, &mut self.ot_recv).await
}
State::Child(_) => Err(FinalizationError::NotMainThread.into()),
State::Finalized => return Err(FinalizationError::AlreadyFinalized.into()),
State::Finalized => Err(FinalizationError::AlreadyFinalized.into()),
}
}
}
Expand Down
18 changes: 10 additions & 8 deletions crates/mpz-ot-core/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@ use mpz_core::Block;

/// Asserts the correctness of correlated oblivious transfer.
pub fn assert_cot(delta: Block, choices: &[bool], msgs: &[Block], received: &[Block]) {
assert!(choices.into_iter().zip(msgs.into_iter().zip(received)).all(
|(&choice, (&msg, &received))| {
assert!(choices
.iter()
.zip(msgs.iter().zip(received))
.all(|(&choice, (&msg, &received))| {
if choice {
received == msg ^ delta
} else {
received == msg
}
}
));
}));
}

/// Asserts the correctness of random oblivious transfer.
pub fn assert_rot<T: Copy + PartialEq>(choices: &[bool], msgs: &[[T; 2]], received: &[T]) {
assert!(choices.into_iter().zip(msgs.into_iter().zip(received)).all(
|(&choice, (&msg, &received))| {
assert!(choices
.iter()
.zip(msgs.iter().zip(received))
.all(|(&choice, (&msg, &received))| {
if choice {
received == msg[1]
} else {
received == msg[0]
}
}
));
}));
}
3 changes: 2 additions & 1 deletion crates/mpz-ot/src/ideal/ot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ impl<Ctx: Context, T: Copy + Send + Sync + 'static> CommittedOTReceiver<Ctx, boo
for IdealOTReceiver<T>
{
async fn reveal_choices(&mut self, ctx: &mut Ctx) -> Result<(), OTError> {
Ok(self.0.call(ctx, (), verify).await)
self.0.call(ctx, (), verify).await;
Ok(())
}
}

Expand Down

0 comments on commit e25d123

Please sign in to comment.