#![deny(unsafe_code)]
#![deny(missing_docs)]
#![deny(clippy::missing_docs_in_private_items)]
#![allow(incomplete_features)]
#![allow(ambiguous_glob_reexports)]
#![feature(inherent_associated_types)]
use std::sync::{Arc, RwLock};
use algebra::{CurvePoint, Scalar};
use ark_ec::CurveGroup;
use rand::thread_rng;
pub mod algebra;
pub mod beaver;
#[cfg(feature = "benchmarks")]
pub mod buffer;
#[cfg(not(feature = "benchmarks"))]
pub(crate) mod buffer;
pub mod commitment;
pub mod error;
mod fabric;
pub mod gadgets;
#[cfg(feature = "benchmarks")]
pub use fabric::*;
#[cfg(not(feature = "benchmarks"))]
pub use fabric::{FabricInner, MpcFabric, ResultHandle, ResultId, ResultValue};
pub mod network;
pub const PARTY0: u64 = 0;
pub const PARTY1: u64 = 1;
pub fn random_point<C: CurveGroup>() -> CurvePoint<C> {
let mut rng = thread_rng();
CurvePoint::generator() * Scalar::random(&mut rng)
}
type Shared<T> = Arc<RwLock<T>>;
#[cfg(any(test, feature = "test_helpers"))]
pub mod test_helpers {
use futures::Future;
use crate::{
beaver::{PartyIDBeaverSource, SharedValueSource},
network::{MockNetwork, NoRecvNetwork, UnboundedDuplexStream},
MpcFabric, PARTY0, PARTY1,
};
use ark_bn254::G1Projective as Bn254Projective;
pub type TestCurve = Bn254Projective;
pub fn mock_fabric() -> MpcFabric<TestCurve> {
let network = NoRecvNetwork::default();
let beaver_source = PartyIDBeaverSource::default();
MpcFabric::new(network, beaver_source)
}
pub async fn execute_mock_mpc<T, S, F>(f: F) -> (T, T)
where
T: Send + 'static,
S: Future<Output = T> + Send + 'static,
F: FnMut(MpcFabric<TestCurve>) -> S,
{
execute_mock_mpc_with_beaver_source(
f,
PartyIDBeaverSource::new(PARTY0),
PartyIDBeaverSource::new(PARTY1),
)
.await
}
pub async fn execute_mock_mpc_with_beaver_source<B, T, S, F>(
mut f: F,
party0_beaver: B,
party1_beaver: B,
) -> (T, T)
where
B: 'static + SharedValueSource<TestCurve>,
T: Send + 'static,
S: Future<Output = T> + Send + 'static,
F: FnMut(MpcFabric<TestCurve>) -> S,
{
let (party0_stream, party1_stream) = UnboundedDuplexStream::new_duplex_pair();
let party0_fabric = MpcFabric::new(MockNetwork::new(PARTY0, party0_stream), party0_beaver);
let party1_fabric = MpcFabric::new(MockNetwork::new(PARTY1, party1_stream), party1_beaver);
let fabric0 = party0_fabric.clone();
let fabric1 = party1_fabric.clone();
let party0_task = tokio::spawn(f(fabric0));
let party1_task = tokio::spawn(f(fabric1));
let party0_output = party0_task.await.unwrap();
let party1_output = party1_task.await.unwrap();
party0_fabric.shutdown();
party1_fabric.shutdown();
(party0_output, party1_output)
}
}