From ba034ffb7ac15cea5d014e4e70ae12ab55d8fd87 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+shaspitz@users.noreply.github.com> Date: Wed, 6 Nov 2024 15:22:39 -0800 Subject: [PATCH] chore: appease linter --- contracts/contracts/core/PreconfManager.sol | 5 +- .../middleware/MevCommitMiddleware.sol | 68 +++++++++---------- 2 files changed, 35 insertions(+), 38 deletions(-) diff --git a/contracts/contracts/core/PreconfManager.sol b/contracts/contracts/core/PreconfManager.sol index e637711c2..bdbc5fff6 100644 --- a/contracts/contracts/core/PreconfManager.sol +++ b/contracts/contracts/core/PreconfManager.sol @@ -82,10 +82,7 @@ contract PreconfManager is __Pausable_init(); // Compute the domain separators - uint256 chainId; - assembly { - chainId := chainid() - } + uint256 chainId = block.chainid; domainSeparatorPreconf = keccak256( abi.encode( keccak256( diff --git a/contracts/contracts/validator-registry/middleware/MevCommitMiddleware.sol b/contracts/contracts/validator-registry/middleware/MevCommitMiddleware.sol index d5d12a624..8705a1038 100644 --- a/contracts/contracts/validator-registry/middleware/MevCommitMiddleware.sol +++ b/contracts/contracts/validator-registry/middleware/MevCommitMiddleware.sol @@ -324,6 +324,11 @@ contract MevCommitMiddleware is IMevCommitMiddleware, MevCommitMiddlewareStorage _setSlashPeriodSeconds(slashPeriodSeconds_); } + /// @dev Sets the slash oracle, restricted to contract owner. + function setSlashOracle(address slashOracle_) external onlyOwner { + _setSlashOracle(slashOracle_); + } + /// @dev Checks if a vault would be valid with a given slashPeriodSeconds. /// @return True if the vault would be valid, reverts otherwise. function wouldVaultBeValidWith(address vault, uint256 potentialSLashPeriodSeconds) external view returns (bool) { @@ -331,11 +336,6 @@ contract MevCommitMiddleware is IMevCommitMiddleware, MevCommitMiddlewareStorage return true; } - /// @dev Sets the slash oracle, restricted to contract owner. - function setSlashOracle(address slashOracle_) external onlyOwner { - _setSlashOracle(slashOracle_); - } - /// @notice Queries if a validator is opted-in to mev-commit through a vault. /// @dev The oracle must continuously call this function for upcoming proposers, in order to maintain /// the most recent (finalized) block timestamp that a validator was queried as "opted-in", see `captureTimestamp` in README.md. @@ -476,35 +476,6 @@ contract MevCommitMiddleware is IMevCommitMiddleware, MevCommitMiddlewareStorage emit VaultRegistered(vault, slashAmount); } - function _validateVaultParams(address vault, uint256 slashPeriodSeconds) internal view { - IEntity delegator = IEntity(IVault(vault).delegator()); - if (delegator.TYPE() == _FULL_RESTAKE_DELEGATOR_TYPE) { - revert FullRestakeDelegatorNotSupported(vault); - } else if (delegator.TYPE() != _NETWORK_RESTAKE_DELEGATOR_TYPE) { - revert UnknownDelegatorType(vault, delegator.TYPE()); - } - IVaultStorage vaultContract = IVaultStorage(vault); - uint256 vaultEpochDurationSeconds = vaultContract.epochDuration(); - - address slasher = IVault(vault).slasher(); - require(slasher != address(0), SlasherNotSetForVault(vault)); - uint256 slasherType = IEntity(slasher).TYPE(); - if (slasherType == _VETO_SLASHER_TYPE) { - IVetoSlasher vetoSlasher = IVetoSlasher(slasher); - uint256 vetoDuration = vetoSlasher.vetoDuration(); - // For veto slashers, veto duration is repurposed as the phase in which the oracle can feasibly call `executeSlash`. - require(vetoDuration >= _MIN_VETO_DURATION, VetoDurationTooShort(vault, vetoDuration)); - // Incorporate that veto duration will eat into portion of the epoch that oracle can feasibly request slashes. - vaultEpochDurationSeconds -= vetoDuration; /// @dev No underflow possible, vetoDuration must be less than epochDuration as enforced by VetoSlasher.sol. - require(vetoSlasher.resolver(_getSubnetwork(), new bytes(0)) == address(0), - VetoSlasherMustHaveZeroResolver(vault)); - } else if (slasherType != _INSTANT_SLASHER_TYPE) { - revert UnknownSlasherType(vault, slasherType); - } - require(vaultEpochDurationSeconds > slashPeriodSeconds, - InvalidVaultEpochDuration(vault, vaultEpochDurationSeconds, slashPeriodSeconds)); - } - function _updateSlashAmount(address vault, uint160 slashAmount) internal { VaultRecord storage record = vaultRecords[vault]; require(record.exists, VaultNotRegistered(vault)); @@ -656,6 +627,35 @@ contract MevCommitMiddleware is IMevCommitMiddleware, MevCommitMiddlewareStorage // solhint-disable-next-line no-empty-blocks function _authorizeUpgrade(address) internal override onlyOwner {} + function _validateVaultParams(address vault, uint256 slashPeriodSeconds) internal view { + IEntity delegator = IEntity(IVault(vault).delegator()); + if (delegator.TYPE() == _FULL_RESTAKE_DELEGATOR_TYPE) { + revert FullRestakeDelegatorNotSupported(vault); + } else if (delegator.TYPE() != _NETWORK_RESTAKE_DELEGATOR_TYPE) { + revert UnknownDelegatorType(vault, delegator.TYPE()); + } + IVaultStorage vaultContract = IVaultStorage(vault); + uint256 vaultEpochDurationSeconds = vaultContract.epochDuration(); + + address slasher = IVault(vault).slasher(); + require(slasher != address(0), SlasherNotSetForVault(vault)); + uint256 slasherType = IEntity(slasher).TYPE(); + if (slasherType == _VETO_SLASHER_TYPE) { + IVetoSlasher vetoSlasher = IVetoSlasher(slasher); + uint256 vetoDuration = vetoSlasher.vetoDuration(); + // For veto slashers, veto duration is repurposed as the phase in which the oracle can feasibly call `executeSlash`. + require(vetoDuration >= _MIN_VETO_DURATION, VetoDurationTooShort(vault, vetoDuration)); + // Incorporate that veto duration will eat into portion of the epoch that oracle can feasibly request slashes. + vaultEpochDurationSeconds -= vetoDuration; /// @dev No underflow possible, vetoDuration must be less than epochDuration as enforced by VetoSlasher.sol. + require(vetoSlasher.resolver(_getSubnetwork(), new bytes(0)) == address(0), + VetoSlasherMustHaveZeroResolver(vault)); + } else if (slasherType != _INSTANT_SLASHER_TYPE) { + revert UnknownSlasherType(vault, slasherType); + } + require(vaultEpochDurationSeconds > slashPeriodSeconds, + InvalidVaultEpochDuration(vault, vaultEpochDurationSeconds, slashPeriodSeconds)); + } + function _checkOperator(address operator) internal view { require(operatorRegistry.isEntity(operator), OperatorNotEntity(operator)); OperatorRecord storage record = operatorRecords[operator];