Skip to content

Commit

Permalink
Merge pull request #173 from NethermindEth/anshu/immutables-refactoring
Browse files Browse the repository at this point in the history
Add getters for immutables
  • Loading branch information
AnshuJalan authored Oct 6, 2024
2 parents b1a4501 + 2a1b965 commit 9ef5df8
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 21 deletions.
6 changes: 5 additions & 1 deletion SmartContracts/src/avs/PreconfRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
46 changes: 32 additions & 14 deletions SmartContracts/src/avs/PreconfServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
}
_;
}
Expand All @@ -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);
}
}
20 changes: 20 additions & 0 deletions SmartContracts/src/avs/PreconfTaskManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions SmartContracts/src/interfaces/IPreconfRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
22 changes: 16 additions & 6 deletions SmartContracts/src/interfaces/IPreconfServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
}
15 changes: 15 additions & 0 deletions SmartContracts/src/interfaces/IPreconfTaskManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
4 changes: 4 additions & 0 deletions SmartContracts/src/mock/MockPreconfRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 9ef5df8

Please sign in to comment.