Skip to main content
The StoffelCoordinator is an abstract contract that implements a 7-phase state machine for orchestrating MPC computations on-chain.

Overview

Inheritance:
  • StoffelAccessControl: Role-based permissions
  • StoffelInputManager: Client input handling
  • Ownable: OpenZeppelin ownership

State Machine

Round Enum

Round Descriptions

RoundPurposeWho Acts
PreprocessingRoundInitialize input mask bufferDesignated Party
ClientInputMaskReservationRoundClients reserve mask indicesClients
CollectingClientInputRoundClients submit masked inputsClients
ClientInputsCollectionEndRoundFinalize input collectionCoordinator
MPCTaskExecutionRoundOff-chain MPC computationMPC Nodes
MPCTaskExecutionEndRoundSignal computation completeMPC Nodes
ClientOutputCollectionRoundDistribute results to clientsMPC Nodes

State Transitions

Constructor

Parameters:
  • stoffelProgramHash: Keccak256 hash of the compiled Stoffel program
  • n: Number of MPC parties
  • t: Fault tolerance threshold
  • designatedParty: Address with elevated privileges
  • initialMPCNodes: Array of addresses to grant PARTY_ROLE
Validation:
  • Checks n >= 3t + 1 (HoneyBadger requirement)
Initialization:
  • Stores _stoffelProgramHash
  • Records creationTime
  • Grants roles to parties and designated party
  • Emits CoordinatorInitialized event

Round Modifiers

atRound

Enforces the current round matches the expected round.

nextRound

Advances to the next round.

goToRound

Jumps to a specific round (for skipping phases).

timedRoundTransition

Automatically advances if timeout elapsed since contract creation.

timedRoundTransitionGoto

Timeout-based jump to specific round.

Virtual Functions

Subclasses must implement these:

Example Implementation

Events

Storage

Example: Complete Coordinator

Best Practices

  1. Use timeouts: Prevent deadlock with timedRoundTransition
  2. Emit events: Enable off-chain monitoring of round transitions
  3. Validate inputs: Check constraints before round transitions
  4. Test thoroughly: Use Foundry’s fuzzing for edge cases

Next Steps