Skip to content

Commit aab8446

Browse files
committedNov 27, 2024
Update docs
Signed-off-by: Denis Varlakov <denis@dfns.co>
1 parent e662e71 commit aab8446

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed
 

‎round-based/src/simulation/async_env.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
//! Simulation provided in a [parent module](super) should be used in most cases. It works
44
//! by converting all parties (defined as async functions) into [state machines](crate::state_machine),
55
//! which has certain limitations. In particular, the protocol cannot await on any futures that
6-
//! aren't provided by [`MpcParty`](crate::MpcParty), for instance, awaiting on the timer will
7-
//! cause a simulation error.
6+
//! aren't provided by [`MpcParty`], for instance, awaiting on the timer will cause a simulation error.
87
//!
98
//! We suggest to avoid awaiting on the futures that aren't provided by `MpcParty` in the MPC protocol
109
//! implementation as it likely makes it runtime-dependent. However, if you do ultimately need to

‎round-based/src/simulation/mod.rs

+23-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
11
//! Multiparty protocol simulation
22
//!
33
//! Simulator is an essential developer tool for testing the multiparty protocol locally.
4-
//! It covers most of the boilerplate by mocking networking.
4+
//! It covers most of the boilerplate of emulating MPC protocol execution.
55
//!
66
//! The entry point is either [`run`] or [`run_with_setup`] functions. They take a protocol
77
//! defined as an async function, provide simulated networking, carry out the simulation,
88
//! and return the result.
99
//!
10-
//! If you need more control over execution, you can use [`Network`] to simulate the networking
11-
//! and carry out the protocol manually.
10+
//! If you need more control over execution, you can use [`Simulation`]. For instance, it allows
11+
//! creating a simulation that has parties defined by different functions, which is helpful, for
12+
//! instance, in simulation in presence of an adversary (e.g. one set of parties can be defined
13+
//! with a regular function/protocol implementation, when the other set of parties may be defined
14+
//! by other function which emulates adversary behavior).
1215
//!
13-
//! When `state-machine` feature is enabled, [`SimulationSync`] is available which can carry out
14-
//! protocols defined as a state machine.
16+
//! ## Limitations
17+
//! [`Simulation`] works by converting each party (defined as an async function) into the
18+
//! [state machine](crate::state_machine). That should work without problems in most cases, providing
19+
//! better UX, without requiring an async runtime (simulation is entirely sync).
20+
//!
21+
//! However, a protocol wrapped into a state machine cannot poll any futures except provided within
22+
//! [`MpcParty`](crate::MpcParty) (so it can only await on sending/receiving messages and yielding).
23+
//! For instance, if the protocol implementation makes use of tokio timers, it will result into an
24+
//! execution error.
25+
//!
26+
//! In general, we do not recommend awaiting on the futures that aren't provided by `MpcParty` in
27+
//! the MPC protocol implementation, to keep the protocol implementation runtime-agnostic.
28+
//!
29+
//! If you do really need to make use of unsupported futures, you can use [`async_env`] instead,
30+
//! which provides a simulation on tokio runtime, but has its own limitations.
1531
//!
1632
//! ## Example
1733
//! ```rust,no_run
@@ -308,7 +324,7 @@ where
308324
}
309325
}
310326

311-
/// Error returned by [`SimulationSync::run`]
327+
/// Error indicating that simulation failed
312328
#[derive(Debug, thiserror::Error)]
313329
#[error(transparent)]
314330
pub struct SimError(#[from] Reason);
@@ -385,7 +401,7 @@ impl<M: Clone> MessagesQueue<M> {
385401
/// Simulates execution of the protocol
386402
///
387403
/// Takes amount of participants, and a function that carries out the protocol for
388-
/// one party. The function takes as input: index of the party, and [`MpcParty`]
404+
/// one party. The function takes as input: index of the party, and [`MpcParty`](crate::MpcParty)
389405
/// that can be used to communicate with others.
390406
///
391407
/// ## Example

0 commit comments

Comments
 (0)