Skip to content

Commit

Permalink
Replace reference to adjudicator in TACoChildApplication with `in…
Browse files Browse the repository at this point in the history
…fractionCollector`

Fix formatting errors and tests

Include Participant struct

Fix types

Fix test reversion message
  • Loading branch information
theref committed May 20, 2024
1 parent 0577c1d commit 7704038
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
28 changes: 19 additions & 9 deletions contracts/contracts/coordination/InfractionCollector.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,45 @@ import "./Coordinator.sol";
import "./TACoChildApplication.sol";

contract InfractionCollector is OwnableUpgradeable {
// Reference to the Coordinator contract
Coordinator private coordinator;

// Reference to the TACoChildApplication contract
TACoChildApplication private tacoChildApplication;

// Mapping to keep track of reported infractions
mapping(bytes32 => mapping(address => bool)) private infractions;

function initialize(Coordinator _coordinator, TACoChildApplication _tacoChildApplication) public initializer {
__Ownable_init();
mapping(uint32 => mapping(address => bool)) private infractions;

function initialize(
Coordinator _coordinator,
TACoChildApplication _tacoChildApplication
) public initializer {
__Ownable_init(msg.sender);
coordinator = _coordinator;
tacoChildApplication = _tacoChildApplication;
}

function reportMissingTranscript(bytes32 ritualId, address[] calldata stakingProviders) external {
function reportMissingTranscript(
uint32 ritualId,
address[] calldata stakingProviders
) external {
// Ritual must have failed
require(coordinator.getRitualState(ritualId) == Coordinator.RitualState.DKG_TIMEOUT, "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(!infractions[ritualId][stakingProviders[i]], "Infraction already reported");
participant = coordinator.getParticipantFromProvider(ritualId, stakingProviders[i]);
Coordinator.Participant memory participant = coordinator.getParticipantFromProvider(
ritualId,
stakingProviders[i]
);
if (participant.transcript.length == 0) {
// Penalize the staking provider
tacoChildApplication.penalize(stakingProviders[i]);
infractions[ritualId][stakingProviders[i]] = true;
}
}
}
}
}
18 changes: 12 additions & 6 deletions contracts/contracts/coordination/TACoChildApplication.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ contract TACoChildApplication is ITACoRootToChild, ITACoChildApplication, Initia

ITACoChildToRoot public immutable rootApplication;
address public coordinator;
address public adjudicator;
address public infractionCollector;

uint96 public immutable minimumAuthorization;

Expand Down Expand Up @@ -61,18 +61,21 @@ contract TACoChildApplication is ITACoRootToChild, ITACoChildApplication, Initia
/**
* @notice Initialize function for using with OpenZeppelin proxy
*/
function initialize(address _coordinator, address _adjudicator) external initializer {
require(coordinator == address(0) || adjudicator == address(0), "Contracts already set");
function initialize(address _coordinator, address _infractionCollector) external initializer {
require(
_coordinator != address(0) && _adjudicator != address(0),
coordinator == address(0) || infractionCollector == address(0),
"Contracts already set"
);
require(
_coordinator != address(0) && _infractionCollector != address(0),
"Contracts must be specified"
);
require(
address(Coordinator(_coordinator).application()) == address(this),
"Invalid coordinator"
);
coordinator = _coordinator;
adjudicator = _adjudicator;
infractionCollector = _infractionCollector;
}

function authorizedStake(address _stakingProvider) external view returns (uint96) {
Expand Down Expand Up @@ -200,7 +203,10 @@ contract TACoChildApplication is ITACoRootToChild, ITACoChildApplication, Initia
* @param _stakingProvider Staking provider address
*/
function penalize(address _stakingProvider) external override {
require(msg.sender == address(adjudicator), "Only adjudicator allowed to penalize");
require(
msg.sender == address(infractionCollector),
"Only infractionCollector allowed to penalize"
);
rootApplication.penalize(_stakingProvider);
emit Penalized(_stakingProvider);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_child_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def test_penalize(accounts, root_application, child_application, coordinator):
) = accounts[0:]

# Penalize can be done only from adjudicator address
with ape.reverts("Only adjudicator allowed to penalize"):
with ape.reverts("Only infractionCollector allowed to penalize"):
child_application.penalize(staking_provider, sender=staking_provider)

tx = child_application.penalize(staking_provider, sender=creator)
Expand Down

0 comments on commit 7704038

Please sign in to comment.