From 2a1b965e2922797605c9672451833add7ff6e519 Mon Sep 17 00:00:00 2001 From: AnshuJalan Date: Fri, 4 Oct 2024 13:01:08 +0530 Subject: [PATCH] feat: add getters for immutables --- SmartContracts/src/avs/PreconfRegistry.sol | 6 ++- .../src/avs/PreconfServiceManager.sol | 46 +++++++++++++------ SmartContracts/src/avs/PreconfTaskManager.sol | 20 ++++++++ .../src/interfaces/IPreconfRegistry.sol | 3 ++ .../src/interfaces/IPreconfServiceManager.sol | 22 ++++++--- .../src/interfaces/IPreconfTaskManager.sol | 15 ++++++ .../src/mock/MockPreconfRegistry.sol | 4 ++ 7 files changed, 95 insertions(+), 21 deletions(-) diff --git a/SmartContracts/src/avs/PreconfRegistry.sol b/SmartContracts/src/avs/PreconfRegistry.sol index d45209d..c419600 100644 --- a/SmartContracts/src/avs/PreconfRegistry.sol +++ b/SmartContracts/src/avs/PreconfRegistry.sol @@ -74,7 +74,7 @@ contract PreconfRegistry is IPreconfRegistry, BLSSignatureChecker, Initializable if (removedPreconferIndex == 0) { revert PreconferNotRegistered(); } - + // Remove the preconfer and exchange its index with the last preconfer preconferToIndex[msg.sender] = 0; @@ -203,6 +203,10 @@ contract PreconfRegistry is IPreconfRegistry, BLSSignatureChecker, Initializable return _createMessage(validatorOp, expiry, preconfer); } + function getPreconfServiceManager() external view returns (address) { + return address(preconfServiceManager); + } + function getNextPreconferIndex() external view returns (uint256) { return nextPreconferIndex; } diff --git a/SmartContracts/src/avs/PreconfServiceManager.sol b/SmartContracts/src/avs/PreconfServiceManager.sol index cbffedc..787477d 100644 --- a/SmartContracts/src/avs/PreconfServiceManager.sol +++ b/SmartContracts/src/avs/PreconfServiceManager.sol @@ -19,6 +19,7 @@ contract PreconfServiceManager is IPreconfServiceManager, ReentrancyGuard { /// @dev This is currently just a flag and not actually being used to lock the stake. mapping(address operator => uint256 timestamp) public stakeLockedUntil; + uint256[199] private __gap; // 200 - 1 constructor(address _preconfRegistry, address _preconfTaskManager, IAVSDirectory _avsDirectory, ISlasher _slasher) { @@ -28,16 +29,9 @@ contract PreconfServiceManager is IPreconfServiceManager, ReentrancyGuard { slasher = _slasher; } - modifier onlyPreconfTaskManager() { - if (msg.sender != address(preconfTaskManager)) { - revert SenderIsNotPreconfTaskManager(); - } - _; - } - - modifier onlyPreconfRegistry() { - if (msg.sender != preconfRegistry) { - revert SenderIsNotPreconfRegistry(); + modifier onlyCallableBy(address allowedSender) { + if (msg.sender != allowedSender) { + revert SenderIsNotAllowed(); } _; } @@ -46,28 +40,52 @@ contract PreconfServiceManager is IPreconfServiceManager, ReentrancyGuard { function registerOperatorToAVS(address operator, IAVSDirectory.SignatureWithSaltAndExpiry memory operatorSignature) external nonReentrant - onlyPreconfRegistry + onlyCallableBy(preconfRegistry) { avsDirectory.registerOperatorToAVS(operator, operatorSignature); } /// @dev Simply relays the call to the AVS directory - function deregisterOperatorFromAVS(address operator) external nonReentrant onlyPreconfRegistry { + function deregisterOperatorFromAVS(address operator) external nonReentrant onlyCallableBy(preconfRegistry) { avsDirectory.deregisterOperatorFromAVS(operator); } /// @dev This not completely functional until Eigenlayer decides the logic of their Slasher. /// for now this simply sets a value in the storage and releases an event. - function lockStakeUntil(address operator, uint256 timestamp) external nonReentrant onlyPreconfTaskManager { + function lockStakeUntil(address operator, uint256 timestamp) + external + nonReentrant + onlyCallableBy(preconfTaskManager) + { stakeLockedUntil[operator] = timestamp; emit StakeLockedUntil(operator, timestamp); } /// @dev This not completely functional until Eigenlayer decides the logic of their Slasher. - function slashOperator(address operator) external nonReentrant onlyPreconfTaskManager { + function slashOperator(address operator) external nonReentrant onlyCallableBy(preconfTaskManager) { if (slasher.isOperatorSlashed(operator)) { revert OperatorAlreadySlashed(); } slasher.slashOperator(operator); } + + //======= + // Views + //======= + + function getPreconfRegistry() external view returns (address) { + return preconfRegistry; + } + + function getPreconfTaskManager() external view returns (address) { + return preconfTaskManager; + } + + function getAVSDirectory() external view returns (address) { + return address(avsDirectory); + } + + function getSlasher() external view returns (address) { + return address(slasher); + } } diff --git a/SmartContracts/src/avs/PreconfTaskManager.sol b/SmartContracts/src/avs/PreconfTaskManager.sol index 110c1a1..ed2c4fb 100644 --- a/SmartContracts/src/avs/PreconfTaskManager.sol +++ b/SmartContracts/src/avs/PreconfTaskManager.sol @@ -529,6 +529,26 @@ contract PreconfTaskManager is IPreconfTaskManager, Initializable { return _isLookaheadRequired(epochTimestamp, nextEpochTimestamp); } + function getPreconfServiceManager() external view returns (address) { + return address(preconfServiceManager); + } + + function getPreconfRegistry() external view returns (address) { + return address(preconfRegistry); + } + + function getTaikoL1() external view returns (address) { + return address(taikoL1); + } + + function getBeaconGenesis() external view returns (uint256) { + return beaconGenesis; + } + + function getBeaconBlockRootContract() external view returns (address) { + return beaconBlockRootContract; + } + function getLookaheadTail() external view returns (uint256) { return lookaheadTail; } diff --git a/SmartContracts/src/interfaces/IPreconfRegistry.sol b/SmartContracts/src/interfaces/IPreconfRegistry.sol index c4ebea9..cd691a9 100644 --- a/SmartContracts/src/interfaces/IPreconfRegistry.sol +++ b/SmartContracts/src/interfaces/IPreconfRegistry.sol @@ -87,4 +87,7 @@ interface IPreconfRegistry { /// @dev Returns a validator who is proposing for a registered preconfer function getValidator(bytes32 pubKeyHash) external view returns (Validator memory); + + /// @dev Returns the address of the service manager contract + function getPreconfServiceManager() external view returns (address); } diff --git a/SmartContracts/src/interfaces/IPreconfServiceManager.sol b/SmartContracts/src/interfaces/IPreconfServiceManager.sol index 1dcbfd5..c4d57a5 100644 --- a/SmartContracts/src/interfaces/IPreconfServiceManager.sol +++ b/SmartContracts/src/interfaces/IPreconfServiceManager.sol @@ -6,10 +6,8 @@ import {IAVSDirectory} from "./eigenlayer-mvp/IAVSDirectory.sol"; interface IPreconfServiceManager { event StakeLockedUntil(address indexed operator, uint256 timestamp); - /// @dev Only callable by the task manager - error SenderIsNotPreconfTaskManager(); - /// @dev Only callable by the registry - error SenderIsNotPreconfRegistry(); + /// @dev Only callable by a given address + error SenderIsNotAllowed(); /// @dev The operator is already slashed error OperatorAlreadySlashed(); @@ -20,9 +18,21 @@ interface IPreconfServiceManager { /// @dev Only callable by the registry function deregisterOperatorFromAVS(address operator) external; - /// @dev Called by PreconfTaskManager to prevent withdrawals of stake during preconf or lookahead dispute period + /// @dev Only Callable by PreconfTaskManager to prevent withdrawals of stake during preconf or lookahead dispute period function lockStakeUntil(address operator, uint256 timestamp) external; - /// @dev Called by PreconfTaskManager to slash an operator for incorret lookahead or preconfirmation + /// @dev Only Callable by PreconfTaskManager to slash an operator for incorret lookahead or preconfirmation function slashOperator(address operator) external; + + /// @dev Returns the address of the preconf registry + function getPreconfRegistry() external view returns (address); + + /// @dev Returns the address of the preconf task manager + function getPreconfTaskManager() external view returns (address); + + /// @dev Returns the address of the AVS directory + function getAVSDirectory() external view returns (address); + + /// @dev Returns the address of the slasher + function getSlasher() external view returns (address); } diff --git a/SmartContracts/src/interfaces/IPreconfTaskManager.sol b/SmartContracts/src/interfaces/IPreconfTaskManager.sol index baf5e72..ed5f97d 100644 --- a/SmartContracts/src/interfaces/IPreconfTaskManager.sol +++ b/SmartContracts/src/interfaces/IPreconfTaskManager.sol @@ -123,4 +123,19 @@ interface IPreconfTaskManager { /// @dev Returns the block proposer for a block function getBlockProposer(uint256 blockId) external view returns (address); + + /// @dev Returns the preconf service manager contract address + function getPreconfServiceManager() external view returns (address); + + /// @dev Returns the preconf registry contract address + function getPreconfRegistry() external view returns (address); + + /// @dev Returns the Taiko L1 contract address + function getTaikoL1() external view returns (address); + + /// @dev Returns the beacon genesis timestamp + function getBeaconGenesis() external view returns (uint256); + + /// @dev Returns the beacon block root contract address + function getBeaconBlockRootContract() external view returns (address); } diff --git a/SmartContracts/src/mock/MockPreconfRegistry.sol b/SmartContracts/src/mock/MockPreconfRegistry.sol index 41c86bc..0fde062 100644 --- a/SmartContracts/src/mock/MockPreconfRegistry.sol +++ b/SmartContracts/src/mock/MockPreconfRegistry.sol @@ -201,6 +201,10 @@ contract MockPreconfRegistry is IPreconfRegistry, BLSSignatureChecker, Initializ return _createMessage(validatorOp, expiry, preconfer); } + function getPreconfServiceManager() external view returns (address) { + return address(preconfServiceManager); + } + function getNextPreconferIndex() external view returns (uint256) { return nextPreconferIndex; }