Function run

Source
pub async fn run<M, F>(
    n: u16,
    party_start: impl FnMut(u16, MpcParty<M, MockedDelivery<M>>) -> F,
) -> SimResult<F::Output>
where M: Clone + Send + Unpin + 'static, F: Future,
Available on crate features sim and sim-async only.
Expand description

Simulates execution of the protocol

Takes amount of participants, and a function that carries out the protocol for one party. The function takes as input: index of the party, and MpcParty that can be used to communicate with others.

ยงExample

use round_based::{Mpc, PartyIndex};

// Any MPC protocol you want to test
pub async fn protocol_of_random_generation<M>(
    party: M,
    i: PartyIndex,
    n: u16
) -> Result<Randomness>
where
    M: Mpc<ProtocolMessage = Msg>
{
    // ...
}

let n = 3;

let output = round_based::sim::async_env::run(
    n,
    |i, party| protocol_of_random_generation(party, i, n),
)
.await
// unwrap `Result`s
.expect_ok()
// check that all parties produced the same response
.expect_eq();

println!("Output randomness: {}", hex::encode(output));