Skip to content

Commit

Permalink
rename mock ot to ideal
Browse files Browse the repository at this point in the history
  • Loading branch information
sinui0 committed Jan 17, 2024
1 parent 1b5573b commit d95ea00
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 103 deletions.
4 changes: 2 additions & 2 deletions garble/mpz-garble/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ name = "mpz_garble"

[features]
default = ["mock"]
mock = ["mpz-ot/mock"]
mock = ["mpz-ot/ideal"]

[dependencies]
mpz-circuits.workspace = true
Expand All @@ -34,7 +34,7 @@ itybity.workspace = true
opaque-debug.workspace = true

[dev-dependencies]
mpz-ot = { workspace = true, features = ["mock"] }
mpz-ot = { workspace = true, features = ["ideal"] }
rstest = { workspace = true }
criterion = { workspace = true, features = ["async_tokio"] }
tlsn-utils-aio = { workspace = true, features = ["duplex"] }
Expand Down
4 changes: 2 additions & 2 deletions garble/mpz-garble/src/ot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ mod tests {

use mpz_circuits::circuits::AES128;
use mpz_garble_core::{ChaChaEncoder, Encoder};
use mpz_ot::mock::mock_ot_shared_pair;
use mpz_ot::ideal::ideal_ot_shared_pair;

#[tokio::test]
async fn test_encoding_transfer() {
let encoder = ChaChaEncoder::new([0u8; 32]);
let (sender, receiver) = mock_ot_shared_pair();
let (sender, receiver) = ideal_ot_shared_pair();

let inputs = AES128
.inputs()
Expand Down
18 changes: 9 additions & 9 deletions garble/mpz-garble/src/protocol/deap/mock.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
//! Mocked DEAP VMs for testing
use mpz_ot::mock::{mock_ot_shared_pair, MockSharedOTReceiver, MockSharedOTSender};
use mpz_ot::ideal::{ideal_ot_shared_pair, IdealSharedOTReceiver, IdealSharedOTSender};
use utils_aio::mux::{mock::MockMuxChannelFactory, MuxChannel};

use crate::config::Role;

use super::{vm::DEAPVm, DEAPThread};

/// Mock DEAP Leader VM.
pub type MockLeader = DEAPVm<MockSharedOTSender, MockSharedOTReceiver>;
pub type MockLeader = DEAPVm<IdealSharedOTSender, IdealSharedOTReceiver>;
/// Mock DEAP Leader thread.
pub type MockLeaderThread = DEAPThread<MockSharedOTSender, MockSharedOTReceiver>;
pub type MockLeaderThread = DEAPThread<IdealSharedOTSender, IdealSharedOTReceiver>;
/// Mock DEAP Follower VM.
pub type MockFollower = DEAPVm<MockSharedOTSender, MockSharedOTReceiver>;
pub type MockFollower = DEAPVm<IdealSharedOTSender, IdealSharedOTReceiver>;
/// Mock DEAP Follower thread.
pub type MockFollowerThread = DEAPThread<MockSharedOTSender, MockSharedOTReceiver>;
pub type MockFollowerThread = DEAPThread<IdealSharedOTSender, IdealSharedOTReceiver>;

/// Create a pair of mocked DEAP VMs
pub async fn create_mock_deap_vm(
id: &str,
) -> (
DEAPVm<MockSharedOTSender, MockSharedOTReceiver>,
DEAPVm<MockSharedOTSender, MockSharedOTReceiver>,
DEAPVm<IdealSharedOTSender, IdealSharedOTReceiver>,
DEAPVm<IdealSharedOTSender, IdealSharedOTReceiver>,
) {
let mut mux_factory = MockMuxChannelFactory::new();
let (leader_ot_send, follower_ot_recv) = mock_ot_shared_pair();
let (follower_ot_send, leader_ot_recv) = mock_ot_shared_pair();
let (leader_ot_send, follower_ot_recv) = ideal_ot_shared_pair();
let (follower_ot_send, leader_ot_recv) = ideal_ot_shared_pair();

let leader_channel = mux_factory.get_channel(id).await.unwrap();
let follower_channel = mux_factory.get_channel(id).await.unwrap();
Expand Down
22 changes: 11 additions & 11 deletions garble/mpz-garble/src/protocol/deap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ impl State {
#[cfg(test)]
mod tests {
use mpz_circuits::{circuits::AES128, ops::WrappingAdd, CircuitBuilder};
use mpz_ot::mock::mock_ot_shared_pair;
use mpz_ot::ideal::ideal_ot_shared_pair;
use utils_aio::duplex::MemoryDuplex;

use crate::Memory;
Expand All @@ -912,8 +912,8 @@ mod tests {
#[tokio::test]
async fn test_deap() {
let (leader_channel, follower_channel) = MemoryDuplex::<GarbleMessage>::new();
let (leader_ot_send, follower_ot_recv) = mock_ot_shared_pair();
let (follower_ot_send, leader_ot_recv) = mock_ot_shared_pair();
let (leader_ot_send, follower_ot_recv) = ideal_ot_shared_pair();
let (follower_ot_send, leader_ot_recv) = ideal_ot_shared_pair();

let mut leader = DEAP::new(Role::Leader, [42u8; 32]);
let mut follower = DEAP::new(Role::Follower, [69u8; 32]);
Expand Down Expand Up @@ -1005,8 +1005,8 @@ mod tests {
#[tokio::test]
async fn test_deap_load() {
let (leader_channel, follower_channel) = MemoryDuplex::<GarbleMessage>::new();
let (leader_ot_send, follower_ot_recv) = mock_ot_shared_pair();
let (follower_ot_send, leader_ot_recv) = mock_ot_shared_pair();
let (leader_ot_send, follower_ot_recv) = ideal_ot_shared_pair();
let (follower_ot_send, leader_ot_recv) = ideal_ot_shared_pair();

let mut leader = DEAP::new(Role::Leader, [42u8; 32]);
let mut follower = DEAP::new(Role::Follower, [69u8; 32]);
Expand Down Expand Up @@ -1120,8 +1120,8 @@ mod tests {
#[tokio::test]
async fn test_deap_decode_private() {
let (leader_channel, follower_channel) = MemoryDuplex::<GarbleMessage>::new();
let (leader_ot_send, follower_ot_recv) = mock_ot_shared_pair();
let (follower_ot_send, leader_ot_recv) = mock_ot_shared_pair();
let (leader_ot_send, follower_ot_recv) = ideal_ot_shared_pair();
let (follower_ot_send, leader_ot_recv) = ideal_ot_shared_pair();

let mut leader = DEAP::new(Role::Leader, [42u8; 32]);
let mut follower = DEAP::new(Role::Follower, [69u8; 32]);
Expand Down Expand Up @@ -1228,8 +1228,8 @@ mod tests {
#[tokio::test]
async fn test_deap_decode_shared() {
let (leader_channel, follower_channel) = MemoryDuplex::<GarbleMessage>::new();
let (leader_ot_send, follower_ot_recv) = mock_ot_shared_pair();
let (follower_ot_send, leader_ot_recv) = mock_ot_shared_pair();
let (leader_ot_send, follower_ot_recv) = ideal_ot_shared_pair();
let (follower_ot_send, leader_ot_recv) = ideal_ot_shared_pair();

let mut leader = DEAP::new(Role::Leader, [42u8; 32]);
let mut follower = DEAP::new(Role::Follower, [69u8; 32]);
Expand Down Expand Up @@ -1366,8 +1366,8 @@ mod tests {

async fn run_zk(key: [u8; 16], msg: [u8; 16], expected_ciphertext: [u8; 16]) {
let (leader_channel, follower_channel) = MemoryDuplex::<GarbleMessage>::new();
let (_, follower_ot_recv) = mock_ot_shared_pair();
let (follower_ot_send, leader_ot_recv) = mock_ot_shared_pair();
let (_, follower_ot_recv) = ideal_ot_shared_pair();
let (follower_ot_send, leader_ot_recv) = ideal_ot_shared_pair();

let mut leader = DEAP::new(Role::Leader, [42u8; 32]);
let mut follower = DEAP::new(Role::Follower, [69u8; 32]);
Expand Down
6 changes: 3 additions & 3 deletions garble/mpz-garble/src/protocol/deap/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,15 +482,15 @@ mod tests {
use crate::protocol::deap::mock::create_mock_deap_vm;

use core::{future::Future, pin::Pin};
use mpz_ot::mock::{MockSharedOTReceiver, MockSharedOTSender};
use mpz_ot::ideal::{IdealSharedOTReceiver, IdealSharedOTSender};
use rstest::{fixture, rstest};

// Leader and follower VMs in a set up state and the futures which need to be awaited
// to trigger circuit execution.
struct VmFixture {
leader_vm: DEAPVm<MockSharedOTSender, MockSharedOTReceiver>,
leader_vm: DEAPVm<IdealSharedOTSender, IdealSharedOTReceiver>,
leader_fut: Pin<Box<dyn Future<Output = Vec<Value>>>>,
follower_vm: DEAPVm<MockSharedOTSender, MockSharedOTReceiver>,
follower_vm: DEAPVm<IdealSharedOTSender, IdealSharedOTReceiver>,
follower_fut: Pin<Box<dyn Future<Output = Vec<Value>>>>,
}

Expand Down
4 changes: 2 additions & 2 deletions garble/mpz-garble/tests/offline-garble.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use mpz_circuits::{circuits::AES128, types::StaticValueType};
use mpz_garble_core::msg::GarbleMessage;
use mpz_ot::mock::mock_ot_shared_pair;
use mpz_ot::ideal::ideal_ot_shared_pair;
use utils_aio::duplex::MemoryDuplex;

use mpz_garble::{config::Visibility, Evaluator, Generator, GeneratorConfigBuilder, ValueMemory};

#[tokio::test]
async fn test_offline_garble() {
let (mut gen_channel, mut ev_channel) = MemoryDuplex::<GarbleMessage>::new();
let (ot_send, ot_recv) = mock_ot_shared_pair();
let (ot_send, ot_recv) = ideal_ot_shared_pair();

let gen = Generator::new(
GeneratorConfigBuilder::default().build().unwrap(),
Expand Down
4 changes: 2 additions & 2 deletions garble/mpz-garble/tests/semihonest.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use mpz_circuits::{circuits::AES128, types::StaticValueType};
use mpz_garble_core::msg::GarbleMessage;
use mpz_ot::mock::mock_ot_shared_pair;
use mpz_ot::ideal::ideal_ot_shared_pair;
use utils_aio::duplex::MemoryDuplex;

use mpz_garble::{config::Visibility, Evaluator, Generator, GeneratorConfigBuilder, ValueMemory};

#[tokio::test]
async fn test_semi_honest() {
let (mut gen_channel, mut ev_channel) = MemoryDuplex::<GarbleMessage>::new();
let (ot_send, ot_recv) = mock_ot_shared_pair();
let (ot_send, ot_recv) = ideal_ot_shared_pair();

let gen = Generator::new(
GeneratorConfigBuilder::default().build().unwrap(),
Expand Down
4 changes: 2 additions & 2 deletions ot/mpz-ot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ edition = "2021"
name = "mpz_ot"

[features]
default = ["mock", "rayon", "actor"]
default = ["ideal", "rayon", "actor"]
rayon = ["mpz-ot-core/rayon"]
actor = ["dep:serde"]
mock = []
ideal = []

[dependencies]
mpz-core.workspace = true
Expand Down
8 changes: 4 additions & 4 deletions ot/mpz-ot/src/actor/kos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub(crate) fn into_kos_stream<'a, St: IoStream<msgs::Message<T>> + Send + Unpin,
#[cfg(test)]
mod tests {
use crate::{
ideal::{ideal_ot_pair, IdealOTReceiver, IdealOTSender},
kos::{Receiver, Sender},
mock::{mock_ot_pair, MockOTReceiver, MockOTSender},
OTReceiverShared, OTSenderShared, VerifiableOTReceiverShared,
};

Expand Down Expand Up @@ -83,12 +83,12 @@ mod tests {
count: usize,
) -> (
SenderActor<
MockOTReceiver<Block>,
IdealOTReceiver<Block>,
SplitSink<MemoryDuplex<Message<()>>, Message<()>>,
SplitStream<MemoryDuplex<Message<()>>>,
>,
ReceiverActor<
MockOTSender<Block>,
IdealOTSender<Block>,
SplitSink<MemoryDuplex<Message<()>>, Message<()>>,
SplitStream<MemoryDuplex<Message<()>>>,
>,
Expand All @@ -98,7 +98,7 @@ mod tests {
let (sender_sink, sender_stream) = sender_channel.split();
let (receiver_sink, receiver_stream) = receiver_channel.split();

let (base_sender, base_receiver) = mock_ot_pair();
let (base_sender, base_receiver) = ideal_ot_pair();

let sender = Sender::new(sender_config, base_receiver);
let receiver = Receiver::new(receiver_config, base_sender);
Expand Down
7 changes: 7 additions & 0 deletions ot/mpz-ot/src/ideal/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Mock implementations of the OT protocols.
mod owned;
mod shared;

pub use owned::{ideal_ot_pair, IdealOTReceiver, IdealOTSender};
pub use shared::{ideal_ot_shared_pair, IdealSharedOTReceiver, IdealSharedOTSender};
Loading

0 comments on commit d95ea00

Please sign in to comment.