Skip to content

Commit

Permalink
Pregenerate OTs
Browse files Browse the repository at this point in the history
  • Loading branch information
kisakishy committed Jul 29, 2024
1 parent c24277a commit 0f4eb2c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 16 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ serde = { version = "1.0.195", features = ["derive"] }
tokio = { version = "1.35.1", features = ["full"] }
trait-variant = "0.1.1"
async-trait = "0.1.77"

# mpz-ot
futures = "0.3"
rstest = "0.12"
serio = "0.1"

mpz-common = { git = "https://github.com/privacy-scaling-explorations/mpz.git", branch = "ferret-sinu", features = ["test-utils"] }
mpz-ot = { git = "https://github.com/privacy-scaling-explorations/mpz.git", branch = "ferret-sinu", features = ["ideal"] }
Expand Down
4 changes: 2 additions & 2 deletions src/faand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
use crate::{
channel::{self, Channel, MsgChannel},
fpre::{Auth, Delta, Key, Mac, Share},
ot::generate_ot,
ot::generate_ots,
};

pub(crate) const RHO: usize = 40;
Expand Down Expand Up @@ -676,7 +676,7 @@ pub(crate) async fn faand(
for b in finalbucket {
shares.push(b.2);
}
generate_ot().await;
generate_ots(100).await;
Ok(shares)
}

Expand Down
59 changes: 45 additions & 14 deletions src/ot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use mpz_core::{lpn::LpnParameters, Block};
use mpz_ot::{
ferret::{FerretConfig, Receiver, Sender},
ideal::cot::{ideal_rcot, IdealCOTReceiver, IdealCOTSender},
OTError, RCOTReceiverOutput, RCOTSenderOutput, RandomCOTReceiver, RandomCOTSender, TransferId,
Correlation, OTError, RCOTReceiverOutput, RCOTSenderOutput, RandomCOTReceiver, RandomCOTSender,
TransferId,
};
use mpz_ot_core::ferret::LpnType;

Expand All @@ -33,7 +34,7 @@ pub(crate) async fn mpz_ot_sender(
count: usize,
ctx_sender: &mut STExecutor<MemoryDuplex>,
rcot_sender: IdealCOTSender,
) -> Result<(TransferId, Vec<Block>), OTError> {
) -> Result<(TransferId, Vec<Block>, u128), OTError> {
let lpn_type: LpnType = LpnType::Regular;

let config = FerretConfig::new(LPN_PARAMETERS_TEST, lpn_type);
Expand Down Expand Up @@ -69,7 +70,7 @@ pub(crate) async fn mpz_ot_sender(
.await
.unwrap();

Ok((sender_id, u))
Ok((sender_id, u, block_to_u128(sender.delta())))
}

pub(crate) async fn mpz_ot_receiver(
Expand Down Expand Up @@ -171,23 +172,53 @@ pub(crate) async fn _mpz_ot(count: usize) -> Result<bool, OTError> {
Ok(true)
}

pub(crate) async fn generate_ot() -> bool {
pub(crate) async fn generate_ots(count: usize) -> bool {
let (io0, io1) = duplex(8);
let mut ctx_receiver = STExecutor::new(io0);
let mut ctx_sender = STExecutor::new(io1);

//let (mut ctx_sender, mut ctx_receiver) = test_st_executor(8);
let (rcot_sender, rcot_receiver) = ideal_rcot();

let count = 100;
let ((sender_id, u), (receiver_id, b, w)) = tokio::try_join!(
mpz_ot_sender(count, &mut ctx_sender, rcot_sender),
mpz_ot_receiver(count, &mut ctx_receiver, rcot_receiver)
)
.unwrap();
let sender_task = tokio::spawn(async move {
mpz_ot_sender(count, &mut ctx_sender, rcot_sender).await
});

let receiver_task = tokio::spawn(async move {
mpz_ot_receiver(count, &mut ctx_receiver, rcot_receiver).await
});

// Await the results of both tasks
let sender_result = sender_task.await;
let receiver_result = receiver_task.await;

// Handle errors from task execution
let (sender_id, u, delta) = match sender_result {
Ok(Ok(result)) => result,
Ok(Err(e)) => {
eprintln!("Sender task error: {:?}", e);
return false;
}
Err(e) => {
eprintln!("Sender task join error: {:?}", e);
return false;
}
};

let (receiver_id, b, w) = match receiver_result {
Ok(Ok(result)) => result,
Ok(Err(e)) => {
eprintln!("Receiver task error: {:?}", e);
return false;
}
Err(e) => {
eprintln!("Receiver task join error: {:?}", e);
return false;
}
};

for i in 0..count {
println!("ids {:?} {:?}", sender_id, receiver_id);
println!("delta {:?}", delta);
println!("b {:?}", b[i]);
println!("u {:?}", block_to_u128(u[i]));
println!("w {:?}", block_to_u128(w[i]));
Expand All @@ -198,16 +229,16 @@ pub(crate) async fn generate_ot() -> bool {
#[cfg(test)]
mod tests {
use futures::TryFutureExt as _;
use std::time::Instant;
use rstest::*;
use std::time::Instant;

use mpz_common::executor::test_st_executor;
use mpz_core::lpn::LpnParameters;
use mpz_ot::{
ferret::{FerretConfig, Receiver, Sender},
ideal::cot::ideal_rcot,
OTError, RCOTReceiverOutput, RCOTSenderOutput, RandomCOTReceiver, RandomCOTSender,
Correlation,
Correlation, OTError, RCOTReceiverOutput, RCOTSenderOutput, RandomCOTReceiver,
RandomCOTSender,
};
use mpz_ot_core::{ferret::LpnType, test::assert_cot};

Expand Down

0 comments on commit 0f4eb2c

Please sign in to comment.