Struct MpcFabric

Source
pub struct MpcFabric { /* private fields */ }
Expand description

A fabric for the MPC protocol, defines a dependency injection layer that dynamically schedules circuit gate evaluations onto the network to be executed

The fabric does not block on gate evaluations, but instead returns a handle to a future result that may be polled to obtain the materialized result. This allows the application layer to continue using the fabric, scheduling more gates to be evaluated and maximally exploiting gate-level parallelism within the circuit

Implementations§

Source§

impl MpcFabric

Source

pub fn new<N: 'static + MpcNetwork, S: 'static + SharedValueSource>( network: N, beaver_source: S, ) -> Self

Constructor

Source

pub fn new_with_size_hint<N: 'static + MpcNetwork, S: 'static + SharedValueSource>( size_hint: usize, network: N, beaver_source: S, ) -> Self

Constructor that takes an additional size hint, indicating how much buffer space the fabric should allocate for results. The size is given in number of gates

Source

pub fn party_id(&self) -> PartyId

Get the party ID of the local party

Source

pub fn shutdown(self)

Shutdown the fabric and the threads it has spawned

Source

pub fn register_waiter(&self, waiter: ResultWaiter)

Register a waiter on a result

Source

pub fn zero(&self) -> ScalarResult

Get the hardcoded zero wire as a raw ScalarResult

Source

pub fn zero_authenticated(&self) -> AuthenticatedScalarResult

Get the hardcoded zero wire as an AuthenticatedScalarResult

Both parties hold the share 0 directly in this case

Source

pub fn zeros_authenticated(&self, n: usize) -> Vec<AuthenticatedScalarResult>

Get a batch of references to the zero wire as an AuthenticatedScalarResult

Source

pub fn one(&self) -> ScalarResult

Get the hardcoded one wire as a raw ScalarResult

Source

pub fn one_authenticated(&self) -> AuthenticatedScalarResult

Get the hardcoded one wire as an AuthenticatedScalarResult

Party 0 holds the value zero and party 1 holds the value one

Source

pub fn ones_authenticated(&self, n: usize) -> Vec<AuthenticatedScalarResult>

Get a batch of references to the one wire as an AuthenticatedScalarResult

Source

pub fn curve_identity(&self) -> ResultHandle<StarkPoint>

Get the hardcoded curve identity wire as a raw StarkPoint

Source

pub fn curve_identity_authenticated(&self) -> AuthenticatedStarkPointResult

Get the hardcoded curve identity wire as an AuthenticatedStarkPointResult

Both parties hold the identity point directly in this case

Source

pub fn share_scalar<T: Into<Scalar>>( &self, val: T, sender: PartyId, ) -> AuthenticatedScalarResult

Share a Scalar value with the counterparty

Source

pub fn batch_share_scalar<T: Into<Scalar>>( &self, vals: Vec<T>, sender: PartyId, ) -> Vec<AuthenticatedScalarResult>

Share a batch of Scalar values with the counterparty

Source

pub fn share_point( &self, val: StarkPoint, sender: PartyId, ) -> AuthenticatedStarkPointResult

Share a StarkPoint value with the counterparty

Source

pub fn batch_share_point( &self, vals: Vec<StarkPoint>, sender: PartyId, ) -> Vec<AuthenticatedStarkPointResult>

Share a batch of StarkPoints with the counterparty

Source

pub fn allocate_scalar<T: Into<Scalar>>(&self, value: T) -> ResultHandle<Scalar>

Allocate a public value in the fabric

Source

pub fn allocate_scalars<T: Into<Scalar>>( &self, values: Vec<T>, ) -> Vec<ResultHandle<Scalar>>

Allocate a batch of scalars in the fabric

Source

pub fn allocate_preshared_scalar<T: Into<Scalar>>( &self, value: T, ) -> AuthenticatedScalarResult

Allocate a scalar as a secret share of an already shared value

Source

pub fn batch_allocate_preshared_scalar<T: Into<Scalar>>( &self, values: Vec<T>, ) -> Vec<AuthenticatedScalarResult>

Allocate a batch of scalars as secret shares of already shared values

Source

pub fn allocate_point(&self, value: StarkPoint) -> ResultHandle<StarkPoint>

Allocate a public curve point in the fabric

Source

pub fn allocate_points( &self, values: Vec<StarkPoint>, ) -> Vec<ResultHandle<StarkPoint>>

Allocate a batch of points in the fabric

Source

pub fn send_value<T: From<ResultValue> + Into<NetworkPayload>>( &self, value: ResultHandle<T>, ) -> ResultHandle<T>

Send a value to the peer, placing the identity in the local result buffer at the send ID

Source

pub fn send_values<T>(&self, values: &[ResultHandle<T>]) -> ResultHandle<Vec<T>>

Send a batch of values to the counterparty

Source

pub fn receive_value<T: From<ResultValue>>(&self) -> ResultHandle<T>

Receive a value from the peer

Source

pub fn exchange_value<T: From<ResultValue> + Into<NetworkPayload>>( &self, value: ResultHandle<T>, ) -> ResultHandle<T>

Exchange a value with the peer, i.e. send then receive or receive then send based on the party ID

Returns a handle to the received value, which will be different for different parties

Source

pub fn exchange_values<T>( &self, values: &[ResultHandle<T>], ) -> ResultHandle<Vec<T>>

Exchange a batch of values with the peer, i.e. send then receive or receive then send based on party ID

Source

pub fn share_plaintext<T>(&self, value: T, sender: PartyId) -> ResultHandle<T>
where T: 'static + From<ResultValue> + Into<NetworkPayload> + Send + Sync,

Share a public value with the counterparty

Source

pub fn batch_share_plaintext<T>( &self, values: Vec<T>, sender: PartyId, ) -> ResultHandle<Vec<T>>
where T: 'static + From<ResultValue> + Send + Sync, Vec<T>: Into<NetworkPayload> + From<ResultValue>,

Share a batch of public values with the counterparty

Source

pub fn new_gate_op<F, T>( &self, args: Vec<ResultId>, function: F, ) -> ResultHandle<T>
where F: 'static + FnOnce(Vec<ResultValue>) -> ResultValue + Send + Sync, T: From<ResultValue>,

Construct a new gate operation in the fabric, i.e. one that can be evaluated immediate given its inputs

Source

pub fn new_batch_gate_op<F, T>( &self, args: Vec<ResultId>, output_arity: usize, function: F, ) -> Vec<ResultHandle<T>>
where F: 'static + FnOnce(Vec<ResultValue>) -> Vec<ResultValue> + Send + Sync, T: From<ResultValue>,

Construct a new batch gate operation in the fabric, i.e. one that can be evaluated to return an array of results

The array must be sized so that the fabric knows how many results to allocate buffer space for ahead of execution

Source

pub fn new_network_op<F, T>( &self, args: Vec<ResultId>, function: F, ) -> ResultHandle<T>
where F: 'static + FnOnce(Vec<ResultValue>) -> NetworkPayload + Send + Sync, T: From<ResultValue>,

Construct a new network operation in the fabric, i.e. one that requires a value to be sent over the channel

Source

pub fn next_beaver_triple( &self, ) -> (MpcScalarResult, MpcScalarResult, MpcScalarResult)

Sample the next beaver triplet from the beaver source

Source

pub fn next_beaver_triple_batch( &self, n: usize, ) -> (Vec<MpcScalarResult>, Vec<MpcScalarResult>, Vec<MpcScalarResult>)

Sample a batch of beaver triples

Source

pub fn next_authenticated_triple( &self, ) -> (AuthenticatedScalarResult, AuthenticatedScalarResult, AuthenticatedScalarResult)

Sample the next beaver triplet with MACs from the beaver source

TODO: Authenticate these values either here or in the pre-processing phase as per the SPDZ paper

Source

pub fn next_authenticated_triple_batch( &self, n: usize, ) -> (Vec<AuthenticatedScalarResult>, Vec<AuthenticatedScalarResult>, Vec<AuthenticatedScalarResult>)

Sample the next batch of beaver triples as AuthenticatedScalars

Source

pub fn random_shared_scalars(&self, n: usize) -> Vec<ScalarResult>

Sample a batch of random shared values from the beaver source

Source

pub fn random_shared_scalars_authenticated( &self, n: usize, ) -> Vec<AuthenticatedScalarResult>

Sample a batch of random shared values from the beaver source and allocate them as AuthenticatedScalars

Source

pub fn random_inverse_pair( &self, ) -> (AuthenticatedScalarResult, AuthenticatedScalarResult)

Sample a pair of values that are multiplicative inverses of one another

Source

pub fn random_inverse_pairs( &self, n: usize, ) -> (Vec<AuthenticatedScalarResult>, Vec<AuthenticatedScalarResult>)

Sample a batch of values that are multiplicative inverses of one another

Source

pub fn random_shared_bit(&self) -> AuthenticatedScalarResult

Sample a random shared bit from the beaver source

Source

pub fn random_shared_bits(&self, n: usize) -> Vec<AuthenticatedScalarResult>

Sample a batch of random shared bits from the beaver source

Trait Implementations§

Source§

impl Clone for MpcFabric

Source§

fn clone(&self) -> MpcFabric

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MpcFabric

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more