Skip to content

Commit

Permalink
feat: start to add cpu code for iris matching
Browse files Browse the repository at this point in the history
  • Loading branch information
rw0x0 committed Aug 22, 2024
1 parent 6eed68d commit 4b91715
Show file tree
Hide file tree
Showing 20 changed files with 3,123 additions and 0 deletions.
59 changes: 59 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = [
"iris-mpc",
"iris-mpc-cpu",
"iris-mpc-gpu",
"iris-mpc-common",
"iris-mpc-upgrade",
Expand Down
20 changes: 20 additions & 0 deletions iris-mpc-cpu/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "iris-mpc-cpu"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html


[dependencies]
aes-prng = "0.2"
bytes = "1.7"
bytemuck.workspace = true
eyre.workspace = true
iris-mpc-common = { path = "../iris-mpc-common" }
num-traits = "0.2"
rand.workspace = true
rayon.workspace = true
serde.workspace = true
tokio.workspace = true
thiserror = "1.0"
tracing.workspace = true
60 changes: 60 additions & 0 deletions iris-mpc-cpu/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use rayon::ThreadPoolBuildError;
use thiserror::Error;

/// An Error enum capturing the errors produced by this crate.
#[derive(Error, Debug)]
pub enum Error {
/// Config Error
#[error("Invalid Configuration")]
Config,
/// Type conversion error
#[error("Conversion error")]
Conversion,
/// Error from the color_eyre crate
#[error(transparent)]
Eyre(#[from] eyre::Report),
/// Invalid party id provided
#[error("Invalid Party id {0}")]
Id(usize),
/// Message size is invalid
#[error("Message size is invalid")]
InvalidMessageSize,
/// Size is invalid
#[error("Size is invalid")]
InvalidSize,
/// A IO error has orccured
#[error(transparent)]
IO(#[from] std::io::Error),
/// JMP verify failed
#[error("JMP verify failed")]
JmpVerify,
/// Mask HW is to small
#[error("Mask HW is to small")]
MaskHW,
/// Not enough triples
#[error("Not enough triples")]
NotEnoughTriples,
/// Invalid number of parties
#[error("Invalid number of parties {0}")]
NumParty(usize),
/// Verify failed
#[error("Verify failed")]
Verify,
#[error(transparent)]
ThreadPoolBuildError(#[from] ThreadPoolBuildError),
/// Some other error has occurred.
#[error("Err: {0}")]
Other(String),
}

impl From<String> for Error {
fn from(mes: String) -> Self {
Self::Other(mes)
}
}

impl From<&str> for Error {
fn from(mes: &str) -> Self {
Self::Other(mes.to_owned())
}
}
5 changes: 5 additions & 0 deletions iris-mpc-cpu/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub(crate) mod error;
pub(crate) mod networks;
pub(crate) mod protocol;
pub(crate) mod shares;
pub(crate) mod utils;
2 changes: 2 additions & 0 deletions iris-mpc-cpu/src/networks/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub(crate) mod network_trait;
pub(crate) mod test_network;
43 changes: 43 additions & 0 deletions iris-mpc-cpu/src/networks/network_trait.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use crate::error::Error;
use bytes::{Bytes, BytesMut};
use iris_mpc_common::id::PartyID;

pub type IoError = std::io::Error;

#[allow(async_fn_in_trait)]
pub trait NetworkTrait: Send + Sync {
fn get_id(&self) -> PartyID;

async fn shutdown(self) -> Result<(), IoError>;

async fn send(&mut self, id: PartyID, data: Bytes) -> Result<(), IoError>;
async fn send_next_id(&mut self, data: Bytes) -> Result<(), IoError>;
async fn send_prev_id(&mut self, data: Bytes) -> Result<(), IoError>;

async fn receive(&mut self, id: PartyID) -> Result<BytesMut, IoError>;
async fn receive_prev_id(&mut self) -> Result<BytesMut, IoError>;
async fn receive_next_id(&mut self) -> Result<BytesMut, IoError>;

async fn broadcast(&mut self, data: Bytes) -> Result<Vec<BytesMut>, IoError>;
//======= sync world =========
fn blocking_send(&mut self, id: PartyID, data: Bytes) -> Result<(), IoError>;
fn blocking_send_next_id(&mut self, data: Bytes) -> Result<(), IoError>;
fn blocking_send_prev_id(&mut self, data: Bytes) -> Result<(), IoError>;

fn blocking_receive(&mut self, id: PartyID) -> Result<BytesMut, IoError>;
fn blocking_receive_prev_id(&mut self) -> Result<BytesMut, IoError>;
fn blocking_receive_next_id(&mut self) -> Result<BytesMut, IoError>;

fn blocking_broadcast(&mut self, data: Bytes) -> Result<Vec<BytesMut>, IoError>;
}

#[allow(async_fn_in_trait)]
pub trait NetworkEstablisher<N: NetworkTrait> {
fn get_id(&self) -> PartyID;
fn get_num_parties(&self) -> usize;
async fn open_channel(&mut self) -> Result<N, Error>;
async fn shutdown(self) -> Result<(), Error>;
//======= sync world =========
fn print_connection_stats(&self, out: &mut impl std::io::Write) -> std::io::Result<()>;
fn get_send_receive(&self, i: usize) -> std::io::Result<(u64, u64)>;
}
Loading

0 comments on commit 4b91715

Please sign in to comment.