Skip to content

Commit

Permalink
Merge pull request #267 from theref/infraction
Browse files Browse the repository at this point in the history
InfractionCollector Contract
  • Loading branch information
cygnusv authored Aug 20, 2024
2 parents c31756d + b97dd03 commit 2211cd3
Show file tree
Hide file tree
Showing 9 changed files with 833 additions and 2 deletions.
70 changes: 70 additions & 0 deletions contracts/contracts/coordination/InfractionCollector.sol
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
);
}
}
}
1 change: 0 additions & 1 deletion contracts/contracts/testnet/OpenAccessAuthorizer.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later

pragma solidity ^0.8.0;

import "../coordination/IEncryptionAuthorizer.sol";
Expand Down
239 changes: 239 additions & 0 deletions deployment/artifacts/lynx.json
Original file line number Diff line number Diff line change
Expand Up @@ -5476,6 +5476,245 @@
"block_number": 9101909,
"deployer": "0x3B42d26E19FF860bC4dEbB920DD8caA53F93c600"
},
"InfractionCollector": {
"address": "0xad8dADaB38eC94B8fe3c482f7550044201506369",
"abi": [
{
"type": "constructor",
"stateMutability": "nonpayable",
"inputs": [
{
"name": "_coordinator",
"type": "address",
"components": null,
"internal_type": "contract Coordinator"
},
{
"name": "_tacoChildApplication",
"type": "address",
"components": null,
"internal_type": "contract ITACoChildApplication"
}
]
},
{
"type": "error",
"name": "InvalidInitialization",
"inputs": []
},
{
"type": "error",
"name": "NotInitializing",
"inputs": []
},
{
"type": "error",
"name": "OwnableInvalidOwner",
"inputs": [
{
"name": "owner",
"type": "address",
"components": null,
"internal_type": "address"
}
]
},
{
"type": "error",
"name": "OwnableUnauthorizedAccount",
"inputs": [
{
"name": "account",
"type": "address",
"components": null,
"internal_type": "address"
}
]
},
{
"type": "event",
"name": "InfractionReported",
"inputs": [
{
"name": "ritualId",
"type": "uint32",
"components": null,
"internal_type": "uint32",
"indexed": true
},
{
"name": "stakingProvider",
"type": "address",
"components": null,
"internal_type": "address",
"indexed": true
},
{
"name": "infractionType",
"type": "uint8",
"components": null,
"internal_type": "enum InfractionCollector.InfractionType",
"indexed": false
}
],
"anonymous": false
},
{
"type": "event",
"name": "Initialized",
"inputs": [
{
"name": "version",
"type": "uint64",
"components": null,
"internal_type": "uint64",
"indexed": false
}
],
"anonymous": false
},
{
"type": "event",
"name": "OwnershipTransferred",
"inputs": [
{
"name": "previousOwner",
"type": "address",
"components": null,
"internal_type": "address",
"indexed": true
},
{
"name": "newOwner",
"type": "address",
"components": null,
"internal_type": "address",
"indexed": true
}
],
"anonymous": false
},
{
"type": "function",
"name": "coordinator",
"stateMutability": "view",
"inputs": [],
"outputs": [
{
"name": "",
"type": "address",
"components": null,
"internal_type": "contract Coordinator"
}
]
},
{
"type": "function",
"name": "infractions",
"stateMutability": "view",
"inputs": [
{
"name": "ritualId",
"type": "uint32",
"components": null,
"internal_type": "uint32"
},
{
"name": "stakingProvider",
"type": "address",
"components": null,
"internal_type": "address"
},
{
"name": "",
"type": "uint8",
"components": null,
"internal_type": "enum InfractionCollector.InfractionType"
}
],
"outputs": [
{
"name": "",
"type": "bool",
"components": null,
"internal_type": "bool"
}
]
},
{
"type": "function",
"name": "owner",
"stateMutability": "view",
"inputs": [],
"outputs": [
{
"name": "",
"type": "address",
"components": null,
"internal_type": "address"
}
]
},
{
"type": "function",
"name": "renounceOwnership",
"stateMutability": "nonpayable",
"inputs": [],
"outputs": []
},
{
"type": "function",
"name": "reportMissingTranscript",
"stateMutability": "nonpayable",
"inputs": [
{
"name": "ritualId",
"type": "uint32",
"components": null,
"internal_type": "uint32"
},
{
"name": "stakingProviders",
"type": "address[]",
"components": null,
"internal_type": "address[]"
}
],
"outputs": []
},
{
"type": "function",
"name": "tacoChildApplication",
"stateMutability": "view",
"inputs": [],
"outputs": [
{
"name": "",
"type": "address",
"components": null,
"internal_type": "contract ITACoChildApplication"
}
]
},
{
"type": "function",
"name": "transferOwnership",
"stateMutability": "nonpayable",
"inputs": [
{
"name": "newOwner",
"type": "address",
"components": null,
"internal_type": "address"
}
],
"outputs": []
}
],
"tx_hash": "0x36762db270b4706dfe829502e5b6469f783acb4bc74e9d21908ecdc88f150629",
"block_number": 10661923,
"deployer": "0x3B42d26E19FF860bC4dEbB920DD8caA53F93c600"
},
"LynxRitualToken": {
"address": "0x064Be2a9740e565729BC0d47bC616c5bb8Cc87B9",
"abi": [
Expand Down
Loading

0 comments on commit 2211cd3

Please sign in to comment.