pub async fn run_with_setup<S, M, F>(
setups: impl IntoIterator<Item = S>,
party_start: impl FnMut(u16, MpcParty<M, MockedDelivery<M>>, S) -> F,
) -> SimResult<F::Output>Available on crate features
sim and sim-async only.Expand description
Simulates execution of the protocol
Similar to run, but allows some setup to be provided to the protocol execution
function.
Simulation will have as many parties as setups iterator yields
ยงExample
use round_based::{Mpc, PartyIndex};
// Any MPC protocol you want to test
pub async fn protocol_of_random_generation<M>(
rng: impl rand::RngCore,
party: M,
i: PartyIndex,
n: u16
) -> Result<Randomness>
where
M: Mpc<ProtocolMessage = Msg>
{
// ...
}
let mut rng = rand_dev::DevRng::new();
let n = 3;
let output = round_based::sim::async_env::run_with_setup(
core::iter::repeat_with(|| rng.fork()).take(n.into()),
|i, party, rng| protocol_of_random_generation(rng, 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));