Struct ark_mpc::MpcFabric

source ·
pub struct MpcFabric<C: CurveGroup> { /* 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<C: CurveGroup> MpcFabric<C>

source

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

Constructor

source

pub fn new_with_size_hint<N: 'static + MpcNetwork<C>, S: 'static + SharedValueSource<C>>( 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<C>)

Register a waiter on a result

source

pub fn zero(&self) -> ScalarResult<C>

Get the hardcoded zero wire as a raw ScalarResult

source

pub fn zero_authenticated(&self) -> AuthenticatedScalarResult<C>

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<C>>

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

source

pub fn one(&self) -> ScalarResult<C>

Get the hardcoded one wire as a raw ScalarResult

source

pub fn one_authenticated(&self) -> AuthenticatedScalarResult<C>

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<C>>

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

source

pub fn curve_identity(&self) -> CurvePointResult<C>

Get the hardcoded curve identity wire as a raw CurvePointResult

source

pub fn curve_identity_authenticated(&self) -> AuthenticatedPointResult<C>

Get the hardcoded curve identity wire as an AuthenticatedPointResult

Both parties hold the identity point directly in this case

source

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

Share a Scalar value with the counterparty

source

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

Share a batch of Scalar values with the counterparty

source

pub fn share_point( &self, val: CurvePoint<C>, sender: PartyId ) -> AuthenticatedPointResult<C>

Share a CurvePoint value with the counterparty

source

pub fn batch_share_point( &self, vals: Vec<CurvePoint<C>>, sender: PartyId ) -> Vec<AuthenticatedPointResult<C>>

Share a batch of CurvePoints with the counterparty

source

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

Allocate a public value in the fabric

source

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

Allocate a batch of scalars in the fabric

source

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

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

source

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

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

source

pub fn allocate_point(&self, value: CurvePoint<C>) -> CurvePointResult<C>

Allocate a public curve point in the fabric

source

pub fn allocate_points( &self, values: Vec<CurvePoint<C>> ) -> Vec<CurvePointResult<C>>

Allocate a batch of points in the fabric

source

pub fn send_value<T: From<ResultValue<C>> + Into<NetworkPayload<C>>>( &self, value: ResultHandle<C, T> ) -> ResultHandle<C, 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<C, T>] ) -> ResultHandle<C, Vec<T>> where T: From<ResultValue<C>>, Vec<T>: Into<NetworkPayload<C>> + From<ResultValue<C>>,

Send a batch of values to the counterparty

source

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

Receive a value from the peer

source

pub fn exchange_value<T: From<ResultValue<C>> + Into<NetworkPayload<C>>>( &self, value: ResultHandle<C, T> ) -> ResultHandle<C, 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<C, T>] ) -> ResultHandle<C, Vec<T>> where T: From<ResultValue<C>>, Vec<T>: From<ResultValue<C>> + Into<NetworkPayload<C>>,

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<C, T> where T: 'static + From<ResultValue<C>> + Into<NetworkPayload<C>> + Send + Sync,

Share a public value with the counterparty

source

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

Share a batch of public values with the counterparty

source

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

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<C, T>>where F: 'static + FnOnce(Vec<ResultValue<C>>) -> Vec<ResultValue<C>> + Send + Sync, T: From<ResultValue<C>>,

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<C, T> where F: 'static + FnOnce(Vec<ResultValue<C>>) -> NetworkPayload<C> + Send + Sync, T: From<ResultValue<C>>,

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<C>, MpcScalarResult<C>, MpcScalarResult<C>)

Sample the next beaver triplet from the beaver source

source

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

Sample a batch of beaver triples

source

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

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<C>>, Vec<AuthenticatedScalarResult<C>>, Vec<AuthenticatedScalarResult<C>>)

Sample the next batch of beaver triples as AuthenticatedScalars

source

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

Sample a batch of random shared values from the beaver source

source

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

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

source

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

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

source

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

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

source

pub fn random_shared_bit(&self) -> AuthenticatedScalarResult<C>

Sample a random shared bit from the beaver source

source

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

Sample a batch of random shared bits from the beaver source

Trait Implementations§

source§

impl<C: Clone + CurveGroup> Clone for MpcFabric<C>

source§

fn clone(&self) -> MpcFabric<C>

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<C: CurveGroup> Debug for MpcFabric<C>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<C> !RefUnwindSafe for MpcFabric<C>

§

impl<C> Send for MpcFabric<C>

§

impl<C> Sync for MpcFabric<C>

§

impl<C> Unpin for MpcFabric<C>

§

impl<C> !UnwindSafe for MpcFabric<C>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
§

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

§

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