[][src]Crate round_based

Round-based protocols execution

What is round-based protocol?

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

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

Purpose

Most of MPC protocols uses round-based notation. Whereas all of them achieve various goals and rely on different math, most of them use the same communication model. Purpose of this crate is to define generic round-based protocol, and develop generic protocol executors with smallest setup.

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 stream of incoming messages and sink for outcoming ones. Then you can do the thing using AsyncProtocol (backed by tokio):

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

Usually protocols assume that P2P messages are encrypted, in this case it's up to you to provide secure channels.

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

Re-exports

pub use async_runtime::AsyncProtocol;

Modules

async_runtime

Instruments for executing protocol in async environment

containers

Containers convenient for implementing StateMachine trait

dev

Useful development utils

Structs

Msg

Represent a message transmitting between parties on wire

Traits

IsCritical

Allows to distinguish a critical error from not critical

StateMachine

State machine of party involved in round-based protocol