MpcExecution

Trait MpcExecution 

Source
pub trait MpcExecution {
    type Round<R: RoundInfo>;
    type Msg;
    type CompleteRoundErr<E>;
    type SendErr;
    type SendMany: SendMany<Exec = Self, Msg = Self::Msg, SendErr = Self::SendErr>;

    // Required methods
    async fn complete<R>(
        &mut self,
        round: Self::Round<R>,
    ) -> Result<R::Output, Self::CompleteRoundErr<R::Error>>
       where R: RoundInfo,
             Self::Msg: RoundMsg<R::Msg>;
    async fn send(
        &mut self,
        msg: Outgoing<Self::Msg>,
    ) -> Result<(), Self::SendErr>;
    fn send_many(self) -> Self::SendMany;
    async fn yield_now(&self);

    // Provided methods
    async fn send_p2p(
        &mut self,
        recipient: PartyIndex,
        msg: Self::Msg,
    ) -> Result<(), Self::SendErr> { ... }
    async fn send_to_all(&mut self, msg: Self::Msg) -> Result<(), Self::SendErr> { ... }
    async fn reliably_broadcast(
        &mut self,
        msg: Self::Msg,
    ) -> Result<(), Self::SendErr> { ... }
}
Expand description

Abstracts functionalities needed for MPC protocol execution

Required Associated Types§

Source

type Round<R: RoundInfo>

Witness that round was registered

It’s obtained by registering round in Mpc::add_round, which then can be used to retrieve messages from associated round by calling MpcExecution::complete.

Source

type Msg

Protocol message

Source

type CompleteRoundErr<E>

Error indicating that completing a round has failed

Source

type SendErr

Error indicating that sending a message has failed

Source

type SendMany: SendMany<Exec = Self, Msg = Self::Msg, SendErr = Self::SendErr>

Returned by .send_many()

Required Methods§

Source

async fn complete<R>( &mut self, round: Self::Round<R>, ) -> Result<R::Output, Self::CompleteRoundErr<R::Error>>
where R: RoundInfo, Self::Msg: RoundMsg<R::Msg>,

Completes the round

Waits until we receive all the messages in the round R from other parties. Returns received messages.

Source

async fn send(&mut self, msg: Outgoing<Self::Msg>) -> Result<(), Self::SendErr>

Sends a message

This method awaits until the message is sent, which might be not the best method to use if you need to send many messages at once. If it’s the case, prefer using .send_many().

Source

fn send_many(self) -> Self::SendMany

Creates a buffer of outgoing messages so they can be sent all at once

When you have many messages that you want to send at once, using .send() may be inefficient, as delivery implementation may pause the execution until the message is received by the recipient. Use this method to send many messages in a batch.

This method takes ownership of self to create the impl SendMany object. After enqueueing all the messages, you need to reclaim self back by calling SendMany::flush.

Source

async fn yield_now(&self)

Yields execution back to the async runtime

Used in MPC protocols with many heavy synchronous computations. The protocol implementors can manually insert yield points to ease the CPU contention

Provided Methods§

Source

async fn send_p2p( &mut self, recipient: PartyIndex, msg: Self::Msg, ) -> Result<(), Self::SendErr>

Sends a p2p message to another party

Note: when you send many messages at once (it’s most likely the case when you send a p2p message), this method is not efficient, prefer using .send_many().

Source

async fn send_to_all(&mut self, msg: Self::Msg) -> Result<(), Self::SendErr>

Sends a message that will be received by all parties

Message will be broadcasted, but not reliably. If you need a reliable broadcast, use MpcExecution::reliably_broadcast method.

Source

async fn reliably_broadcast( &mut self, msg: Self::Msg, ) -> Result<(), Self::SendErr>

Reliably broadcasts a message

Message will be received by all participants of the protocol. Moreover, when recipient receives a message, it will be assured (cryptographically or through other trust assumptions) that all honest participants of the protocol received the same message.

It’s a responsibility of a message delivery layer to provide the reliable broadcast mechanism. If it’s not supported, this method returns an error. Note that not every MPC protocol requires the reliable broadcast, so it’s totally normal to have a message delivery implementation that does not support it.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<D, M, MainMsg> MpcExecution for WithEchoBroadcast<D, M, MainMsg>
where D: Digest + 'static, M: MpcExecution<Msg = Msg<D, MainMsg>>, MainMsg: ProtocolMsg + Digestable + Clone + 'static,

Available on crate feature echo-broadcast only.
Source§

impl<M, D, IoErr, AsyncR> MpcExecution for MpcParty<M, D, AsyncR, true>
where M: ProtocolMsg + 'static, D: Stream<Item = Result<Incoming<M>, IoErr>> + Unpin + Sink<Outgoing<M>, Error = IoErr>, AsyncR: AsyncRuntime,

Source§

type Round<R: RoundInfo> = Round<R>

Source§

type Msg = M

Source§

type CompleteRoundErr<E> = CompleteRoundError<E, IoErr>

Source§

type SendErr = IoErr

Source§

type SendMany = SendMany<M, D, AsyncR>