Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmasny committed Jan 12, 2024
2 parents 9d6866e + a3d4fda commit efb049b
Show file tree
Hide file tree
Showing 43 changed files with 807 additions and 994 deletions.
2 changes: 1 addition & 1 deletion ipa-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "ipa-core"
version = "0.1.0"
rust-version = "1.64.0"
rust-version = "1.75.0"
edition = "2021"

[features]
Expand Down
6 changes: 5 additions & 1 deletion ipa-core/src/cli/playbook/ipa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,11 @@ where
.unwrap();

let results: Vec<F> = results
.map(|bytes| AdditiveShare::<F>::from_byte_slice(&bytes).collect::<Vec<_>>())
.map(|bytes| {
AdditiveShare::<F>::from_byte_slice(&bytes)
.collect::<Result<Vec<_>, _>>()
.unwrap()
})
.reconstruct();

let lat = mpc_time.elapsed();
Expand Down
6 changes: 5 additions & 1 deletion ipa-core/src/cli/playbook/multiply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ where

// expect replicated shares to be sent back
results
.map(|bytes| Replicated::<F>::from_byte_slice(&bytes).collect::<Vec<_>>())
.map(|bytes| {
Replicated::<F>::from_byte_slice(&bytes)
.collect::<Result<Vec<_>, _>>()
.unwrap()
})
.reconstruct()
}
22 changes: 21 additions & 1 deletion ipa-core/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{backtrace::Backtrace, fmt::Debug};
use std::{backtrace::Backtrace, convert::Infallible, fmt::Debug};

use thiserror::Error;

Expand Down Expand Up @@ -108,3 +108,23 @@ pub fn set_global_panic_hook() {
(default_hook)(panic_info);
}));
}

/// Same purpose as [`unwrap-infallible`] but fewer dependencies.
/// As usual, there is a 8 year old [`RFC`] to make this to std that hasn't been merged yet.
///
/// [`unwrap-infallible`]: https://docs.rs/unwrap-infallible/latest/unwrap_infallible
/// [`RFC`]: https://github.com/rust-lang/rfcs/issues/1723
pub trait UnwrapInfallible {
/// R to avoid clashing with result's `Ok` type.
type R;

fn unwrap_infallible(self) -> Self::R;
}

impl<T> UnwrapInfallible for Result<T, Infallible> {
type R = T;

fn unwrap_infallible(self) -> Self::R {
self.unwrap()
}
}
17 changes: 11 additions & 6 deletions ipa-core/src/ff/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,23 @@ impl From<Boolean> for bool {
}
}

#[derive(thiserror::Error, Debug)]
#[error("{0} is not a valid boolean value, only 0 and 1 are accepted.")]
pub struct ParseBooleanError(u8);

impl Serializable for Boolean {
type Size = <<Boolean as SharedValue>::Storage as Block>::Size;
type DeserializationError = ParseBooleanError;

fn serialize(&self, buf: &mut GenericArray<u8, Self::Size>) {
buf[0] = u8::from(self.0);
}

///## Panics
/// panics when u8 is not 0 or 1
fn deserialize(buf: &GenericArray<u8, Self::Size>) -> Self {
assert!(buf[0] < 2u8);
Boolean(buf[0] != 0)
fn deserialize(buf: &GenericArray<u8, Self::Size>) -> Result<Self, Self::DeserializationError> {
if buf[0] > 1 {
return Err(ParseBooleanError(buf[0]));
}
Ok(Boolean(buf[0] != 0))
}
}

Expand Down Expand Up @@ -180,7 +185,7 @@ mod test {
let input = rng.gen::<Boolean>();
let mut a: GenericArray<u8, U1> = [0u8; 1].into();
input.serialize(&mut a);
let output = Boolean::deserialize(&a);
let output = Boolean::deserialize(&a).unwrap();
assert_eq!(input, output);
}

Expand Down
Loading

0 comments on commit efb049b

Please sign in to comment.