Crate round_based[][src]

Expand description

Round-based protocols execution

Crate defines a generic round-based protocol and provides utilities for it. We give formal definition below, but you may have already seen such protocols: most of MPC protocols follow round-based communication model.

By defining the generic round-based protocol, we can implement generic transport layer for it. See AsyncProtocol: it allows executing the protocol by providing channels of incoming and outgoing messages.

What is round-based protocol?

In round-based protocol we have n parties that can send messages to and receive messages from other parties within rounds (number of parties n is known prior to starting protocol).

At every round party may send a P2P or broadcast message, and it receives all broadcast messages sent by other parties and P2P messages sent directly to it. After party’s received enough round messages in this round, it either proceeds (evaluates something on received messages and goes to next round) or finishes the protocol.

How to define own round-based protocol

To define own round-based protocol, you need to implement StateMachine trait. I.e. you need to define type of protocol message which will be transmitted on wire, determine rules how to handle incoming message and how to proceed state, etc.

We divide methods in StateMachine on which can block and which can not. Most of MPC protocols rely on computationally expensive math operations, such operations should not be executed in async environment (i.e. on green-thread), that’s why the only method which capable of doing expensive operations is proceed.

How to execute round-based protocol

To run round-based protocol you need only to provide incoming and outgoing channels. Then you can execute the protocol using AsyncProtocol:

fn incoming() -> impl Stream<Item=Result<Msg<M>, Error>> + FusedStream + Unpin {
    // ...
}
fn outgoing() -> impl Sink<Msg<M>, Error=Error> + Unpin {
    // ...
}
let output: State::Output = AsyncProtocol::new(State::initial(), incoming(), outgoing())
    .run().await?;
// ...

Usually protocols assume that P2P messages are encrypted and every message is authenticated, in this case underlying sink and stream must meet such requirements.

For development purposes, you can also find useful Simulation and AsyncSimulation simulations that can run protocols locally.

Re-exports

pub use async_runtime::AsyncProtocol;

Modules

async_runtimeasync-runtime

Instruments for executing protocol in async environment

containers

Containers convenient for implementing StateMachine trait

devdev

Useful development utils

Structs

Msg

Represent a message transmitting between parties on wire

Traits

IsCritical

Distinguish a critical error from not critical

StateMachine

State machine of party involved in round-based protocol