-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #267 from theref/infraction
InfractionCollector Contract
- Loading branch information
Showing
9 changed files
with
833 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin-upgradeable/contracts/access/OwnableUpgradeable.sol"; | ||
import "./Coordinator.sol"; | ||
import "../../threshold/ITACoChildApplication.sol"; | ||
|
||
contract InfractionCollector is OwnableUpgradeable { | ||
event InfractionReported( | ||
uint32 indexed ritualId, | ||
address indexed stakingProvider, | ||
InfractionType infractionType | ||
); | ||
// infraction types | ||
enum InfractionType { | ||
MISSING_TRANSCRIPT | ||
} | ||
Coordinator public immutable coordinator; | ||
// Reference to the TACoChildApplication contract | ||
ITACoChildApplication public immutable tacoChildApplication; | ||
// Mapping to keep track of reported infractions | ||
mapping(uint32 ritualId => mapping(address stakingProvider => mapping(InfractionType => uint256))) | ||
public infractionsForRitual; | ||
|
||
constructor(Coordinator _coordinator) { | ||
require(address(_coordinator) != address(0), "Contracts must be specified"); | ||
coordinator = _coordinator; | ||
tacoChildApplication = coordinator.application(); | ||
_disableInitializers(); | ||
} | ||
|
||
function initialize() external initializer { | ||
__Ownable_init(msg.sender); | ||
} | ||
|
||
function reportMissingTranscript( | ||
uint32 ritualId, | ||
address[] calldata stakingProviders | ||
) external { | ||
// Ritual must have failed | ||
require( | ||
coordinator.getRitualState(ritualId) == Coordinator.RitualState.DKG_TIMEOUT, | ||
"Ritual must have failed" | ||
); | ||
|
||
for (uint256 i = 0; i < stakingProviders.length; i++) { | ||
// Check if the infraction has already been reported | ||
require( | ||
infractionsForRitual[ritualId][stakingProviders[i]][ | ||
InfractionType.MISSING_TRANSCRIPT | ||
] == 0, | ||
"Infraction already reported" | ||
); | ||
Coordinator.Participant memory participant = coordinator.getParticipantFromProvider( | ||
ritualId, | ||
stakingProviders[i] | ||
); | ||
require(participant.transcript.length == 0, "Transcript is not missing"); | ||
infractionsForRitual[ritualId][stakingProviders[i]][ | ||
InfractionType.MISSING_TRANSCRIPT | ||
] = 1; | ||
emit InfractionReported( | ||
ritualId, | ||
stakingProviders[i], | ||
InfractionType.MISSING_TRANSCRIPT | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.