// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {StoffelCoordinator} from "stoffel-solidity-sdk/StoffelCoordinator.sol";
contract SecureAuction is StoffelCoordinator {
uint256 public constant RESERVATION_TIMEOUT = 1 hours;
uint256 public constant COLLECTION_TIMEOUT = 2 hours;
mapping(address => uint256) public clientOutputs;
constructor(
bytes32 programHash,
address[] memory mpcNodes
) StoffelCoordinator(
programHash,
mpcNodes.length, // n = number of nodes
1, // t = 1
msg.sender, // deployer is designated party
mpcNodes
) {}
function startPreprocessing()
external
override
onlyDesignatedParty
atRound(Round.PreprocessingRound)
nextRound
{
initializeInputMaskBuffer(100); // Support up to 100 clients
emit PreprocessingRoundExecuted(msg.sender, block.timestamp);
}
function gatherInputs()
external
override
onlyDesignatedParty
timedRoundTransition(Round.ClientInputMaskReservationRound, RESERVATION_TIMEOUT)
atRound(Round.ClientInputMaskReservationRound)
nextRound
{
emit ClientInputMaskReservationEvent(msg.sender, block.timestamp);
}
function initiateMPCComputation()
external
override
onlyDesignatedParty
timedRoundTransition(Round.CollectingClientInputRound, COLLECTION_TIMEOUT)
atRound(Round.ClientInputsCollectionEndRound)
nextRound
{
emit MPCTaskExecuted(_stoffelProgramHash, msg.sender, block.timestamp);
}
function publishOutputs()
external
override
onlyDesignatedParty
atRound(Round.MPCTaskExecutionEndRound)
nextRound
{
// Implementation specific to your use case
}
// Allow clients to collect their outputs
function collectOutput()
external
atRound(Round.ClientOutputCollectionRound)
{
uint256 output = clientOutputs[msg.sender];
require(output != 0, "No output for client");
// Return output to client
}
}