Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Threading Refactor #165

Merged
merged 34 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a23a095
feat: mpz-common (#107)
sinui0 Mar 7, 2024
7883f37
refactor: cointoss (#108)
sinui0 Mar 7, 2024
272b83d
refactor: mpz-ot (#109)
sinui0 Mar 7, 2024
a4f80dc
refactor: re-organize crates (#110)
sinui0 Mar 7, 2024
61275e8
Adds an ideal ROT functionality to mpz-ot-core (#102)
th4s Mar 7, 2024
13b0cae
refactor(mpz-ot): Normalize OT and ideal functionalities (#122)
sinui0 May 8, 2024
9891192
feat(mpz-common): add try_/join convenience macros (#126)
sinui0 May 13, 2024
9300c94
fix(mpz-ot): Ideal RCOT (#131)
sinui0 May 13, 2024
67564a4
docs: fix typos (#130)
themighty1 May 15, 2024
b35d392
feat(mpz-common): dummy executor (#132)
sinui0 May 15, 2024
3d523ec
feat(mpz-common): simple counter (#133)
sinui0 May 15, 2024
a10810a
refactor(mpz-garble-core): batched garbling (#140)
sinui0 May 28, 2024
b9e5f59
Add crate `mpz-ole-core` (#135)
th4s May 29, 2024
7292063
feat(mpz-common): multi-threaded executor (#136)
sinui0 May 29, 2024
6617c54
Add IO wrapper for OLE (#138)
th4s May 31, 2024
699acff
feat(mpz-common): Context::blocking (#141)
sinui0 May 31, 2024
c50a145
feat(mpz-common): scoped! macro (#143)
sinui0 May 31, 2024
ab82dbf
test(mpz-common): test mt executor concurrency (#145)
sinui0 Jun 4, 2024
81802ea
Add `mpz-share-conversion-core` (#147)
th4s Jun 5, 2024
b858189
refactor(mpz-garble): fix threading breaking changes (#144)
sinui0 Jun 5, 2024
b0f5a90
refactor(mpz-share-conversion): new impl (#146)
sinui0 Jun 5, 2024
6f1ef18
feat(mpz-common): add type alias for test st executor (#154)
sinui0 Jun 7, 2024
5fc90ff
feat(mpz-common): async sync primitives (#152)
sinui0 Jun 11, 2024
801381c
feat(mpz-ot): impl more OT traits on shared KOS (#153)
sinui0 Jun 11, 2024
6c7dec2
feat(mpz-garble): pre-commit inputs (#149)
sinui0 Jun 12, 2024
9c17b38
refactor: KOS and preprocessing traits (#155)
sinui0 Jun 12, 2024
640bda0
refactor(mpz-ot): add accept_reveal for verifiable ot (#158)
sinui0 Jun 14, 2024
1ec8979
fix(mpz-common): flush io in syncer (#157)
sinui0 Jun 14, 2024
34a0663
fix(mpz-ot): fix shared KOS verifiable ot receiver (#161)
sinui0 Jun 20, 2024
3272954
fix(mpz-garble): add thread id to otp ids (#162)
sinui0 Jun 20, 2024
461d3b4
refactor(mpz-common): new thread future (#163)
sinui0 Jun 24, 2024
836ad67
chore: bump serio and uid-mux (#164)
sinui0 Jun 25, 2024
5ad1bea
chore: move workspace manifest
sinui0 Jun 25, 2024
e25d123
fix: clippy --fix
sinui0 Jun 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(mpz-ot): Ideal RCOT (#131)
* delete obsolete module

* export test-utils and add ideal COT tests
  • Loading branch information
sinui0 committed Jun 25, 2024
commit 9300c9440321bc70006c3a457f5c018f8fbfde5f
3 changes: 2 additions & 1 deletion crates/mpz-ot-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ workspace = true
name = "mpz_ot_core"

[features]
default = ["rayon"]
default = ["rayon", "test-utils"]
rayon = ["dep:rayon", "itybity/rayon", "blake3/rayon"]
test-utils = []

[dependencies]
mpz-core.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions crates/mpz-ot-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ pub mod ferret;
pub mod ideal;
pub mod kos;
pub mod msgs;
#[cfg(test)]
pub(crate) mod test;
#[cfg(any(test, feature = "test-utils"))]
pub mod test;

/// An oblivious transfer identifier.
///
Expand Down
6 changes: 4 additions & 2 deletions crates/mpz-ot-core/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! OT test utilities.

use mpz_core::Block;

/// Asserts the correctness of correlated oblivious transfer.
pub(crate) fn assert_cot(delta: Block, choices: &[bool], msgs: &[Block], received: &[Block]) {
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))| {
if choice {
Expand All @@ -14,7 +16,7 @@ pub(crate) fn assert_cot(delta: Block, choices: &[bool], msgs: &[Block], receive
}

/// Asserts the correctness of random oblivious transfer.
pub(crate) fn assert_rot<T: Copy + PartialEq>(choices: &[bool], msgs: &[[T; 2]], received: &[T]) {
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))| {
if choice {
Expand Down
1 change: 1 addition & 0 deletions crates/mpz-ot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ cfg-if.workspace = true

[dev-dependencies]
mpz-common = { workspace = true, features = ["test-utils", "ideal"] }
mpz-ot-core = { workspace = true, features = ["test-utils"] }
rstest = { workspace = true }
criterion = { workspace = true, features = ["async_tokio"] }
tokio = { workspace = true, features = [
Expand Down
86 changes: 85 additions & 1 deletion crates/mpz-ot/src/ideal/cot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use mpz_ot_core::{
ideal::cot::IdealCOT, COTReceiverOutput, COTSenderOutput, RCOTReceiverOutput, RCOTSenderOutput,
};

use crate::{COTReceiver, COTSender, OTError, OTSetup, RandomCOTReceiver};
use crate::{COTReceiver, COTSender, OTError, OTSetup, RandomCOTReceiver, RandomCOTSender};

fn cot(
f: &mut IdealCOT,
Expand Down Expand Up @@ -70,6 +70,17 @@ impl<Ctx: Context> COTSender<Ctx, Block> for IdealCOTSender {
}
}

#[async_trait]
impl<Ctx: Context> RandomCOTSender<Ctx, Block> for IdealCOTSender {
async fn send_random_correlated(
&mut self,
ctx: &mut Ctx,
count: usize,
) -> Result<RCOTSenderOutput<Block>, OTError> {
Ok(self.0.call(ctx, count, rcot).await)
}
}

/// Ideal OT receiver.
#[derive(Debug, Clone)]
pub struct IdealCOTReceiver(Bob<IdealCOT>);
Expand Down Expand Up @@ -105,3 +116,76 @@ impl<Ctx: Context> RandomCOTReceiver<Ctx, bool, Block> for IdealCOTReceiver {
Ok(self.0.call(ctx, count, rcot).await)
}
}

#[cfg(test)]
mod tests {
use super::*;
use mpz_common::executor::test_st_executor;
use mpz_ot_core::test::assert_cot;
use rand::{Rng, SeedableRng};
use rand_chacha::ChaCha12Rng;

#[tokio::test]
async fn test_ideal_cot() {
let mut rng = ChaCha12Rng::seed_from_u64(0);
let (mut ctx_a, mut ctx_b) = test_st_executor(8);
let (mut alice, mut bob) = ideal_cot();

let delta = alice.0.get_mut().delta();

let count = 10;
let choices = (0..count).map(|_| rng.gen()).collect::<Vec<bool>>();

let (
COTSenderOutput {
id: id_a,
msgs: sender_msgs,
},
COTReceiverOutput {
id: id_b,
msgs: receiver_msgs,
},
) = tokio::try_join!(
alice.send_correlated(&mut ctx_a, count),
bob.receive_correlated(&mut ctx_b, &choices)
)
.unwrap();

assert_eq!(id_a, id_b);
assert_eq!(count, sender_msgs.len());
assert_eq!(count, receiver_msgs.len());
assert_cot(delta, &choices, &sender_msgs, &receiver_msgs);
}

#[tokio::test]
async fn test_ideal_rcot() {
let (mut ctx_a, mut ctx_b) = test_st_executor(8);
let (mut alice, mut bob) = ideal_rcot();

let delta = alice.0.get_mut().delta();

let count = 10;

let (
RCOTSenderOutput {
id: id_a,
msgs: sender_msgs,
},
RCOTReceiverOutput {
id: id_b,
choices,
msgs: receiver_msgs,
},
) = tokio::try_join!(
alice.send_random_correlated(&mut ctx_a, count),
bob.receive_random_correlated(&mut ctx_b, count)
)
.unwrap();

assert_eq!(id_a, id_b);
assert_eq!(count, sender_msgs.len());
assert_eq!(count, receiver_msgs.len());
assert_eq!(count, choices.len());
assert_cot(delta, &choices, &sender_msgs, &receiver_msgs);
}
}
158 changes: 0 additions & 158 deletions crates/mpz-ot/src/ideal/rcot.rs

This file was deleted.

20 changes: 19 additions & 1 deletion crates/mpz-ot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use mpz_common::Context;

pub use mpz_ot_core::{
COTReceiverOutput, COTSenderOutput, OTReceiverOutput, OTSenderOutput, RCOTReceiverOutput,
ROTReceiverOutput, ROTSenderOutput, TransferId,
RCOTSenderOutput, ROTReceiverOutput, ROTSenderOutput, TransferId,
};

/// An oblivious transfer error.
Expand Down Expand Up @@ -96,6 +96,24 @@ pub trait RandomOTSender<Ctx, T> {
) -> Result<ROTSenderOutput<T>, OTError>;
}

/// A random correlated oblivious transfer sender.
#[async_trait]
pub trait RandomCOTSender<Ctx, T> {
/// Obliviously transfers the correlated messages to the receiver.
///
/// Returns the `0`-bit messages that were obliviously transferred.
///
/// # Arguments
///
/// * `ctx` - The thread context.
/// * `count` - The number of correlated messages to obliviously transfer.
async fn send_random_correlated(
&mut self,
ctx: &mut Ctx,
count: usize,
) -> Result<RCOTSenderOutput<T>, OTError>;
}

/// An oblivious transfer receiver.
#[async_trait]
pub trait OTReceiver<Ctx, T, U> {
Expand Down