sim only.Expand description
Multiparty protocol simulation
Simulator is an essential developer tool for testing the multiparty protocol locally. It covers most of the boilerplate of emulating MPC protocol execution.
The entry point is either run or run_with_setup functions. They take a protocol
defined as an async function, provide simulated networking, carry out the simulation,
and return the result.
If you need more control over execution, you can use Simulation. For instance, it allows
creating a simulation that has parties defined by different functions, which is helpful, for
instance, in simulation in presence of an adversary (e.g. one set of parties can be defined
with a regular function/protocol implementation, when the other set of parties may be defined
by other function which emulates adversary behavior).
§Limitations
Simulation works by converting each party (defined as an async function) into the
state machine. That should work without problems in most cases, providing
better UX, without requiring an async runtime (simulation is entirely sync).
However, a protocol wrapped into a state machine cannot poll any futures except provided within
MpcParty (so it can only await on sending/receiving messages and yielding).
For instance, if the protocol implementation makes use of tokio timers, it will result into an
execution error.
In general, we do not recommend awaiting on the futures that aren’t provided by MpcParty in
the MPC protocol implementation, to keep the protocol implementation runtime-agnostic.
If you do really need to make use of unsupported futures, you can use async_env instead,
which provides a simulation on tokio runtime, but has its own limitations.
§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::run(
n,
|i, party| protocol_of_random_generation(party, i, n),
)
.unwrap()
// unwrap `Result`s
.expect_ok()
// check that all parties produced the same response
.expect_eq();
println!("Output randomness: {}", hex::encode(output));Modules§
- async_
env sim-async - Fully async simulation
Structs§
- SimError
- Error indicating that simulation failed
- SimResult
- Result of the simulation
- Simulation
- Simulates MPC protocol with parties defined as state machines
Functions§
- run
- Simulates execution of the protocol
- run_
with_ setup - Simulates execution of the protocol