Skip to content

Commit

Permalink
chore: slashing magnitudes cleanup (#937)
Browse files Browse the repository at this point in the history
* chore: remove unused contract immutables

* chore: rename internal function for clarity

* fix: storage gap on avsd

* chore: alm renaming and cleanup

* chore: remove unused errors and interfaces

* feat: add view function for opSet inclusion

* chore: fmt
  • Loading branch information
8sunyuan authored Dec 10, 2024
1 parent b866c6c commit d310921
Show file tree
Hide file tree
Showing 25 changed files with 62 additions and 405 deletions.
7 changes: 1 addition & 6 deletions script/deploy/devnet/deploy_from_scratch.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,12 @@ contract DeployFromScratch is Script, Test {

// Second, deploy the *implementation* contracts, using the *proxy contracts* as inputs

delegationImplementation = new DelegationManager(avsDirectory, strategyManager, eigenPodManager, allocationManager, eigenLayerPauserReg, permissionController, MIN_WITHDRAWAL_DELAY);
delegationImplementation = new DelegationManager(strategyManager, eigenPodManager, allocationManager, eigenLayerPauserReg, permissionController, MIN_WITHDRAWAL_DELAY);
strategyManagerImplementation = new StrategyManager(delegation, eigenLayerPauserReg);
avsDirectoryImplementation = new AVSDirectory(delegation, eigenLayerPauserReg);
eigenPodManagerImplementation = new EigenPodManager(
ethPOSDeposit,
eigenPodBeacon,
strategyManager,
delegation,
eigenLayerPauserReg
);
Expand Down Expand Up @@ -492,10 +491,6 @@ contract DeployFromScratch is Script, Test {
eigenPodManagerContract.eigenPodBeacon() == eigenPodBeacon,
"eigenPodManager: eigenPodBeacon contract address not set correctly"
);
require(
eigenPodManagerContract.strategyManager() == strategyManager,
"eigenPodManager: strategyManager contract address not set correctly"
);

require(
rewardsCoordinatorContract.delegationManager() == delegation,
Expand Down
7 changes: 1 addition & 6 deletions script/deploy/local/Deploy_From_Scratch.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,12 @@ contract DeployFromScratch is Script, Test {

// Second, deploy the *implementation* contracts, using the *proxy contracts* as inputs

delegationImplementation = new DelegationManager(avsDirectory, strategyManager, eigenPodManager, allocationManager, eigenLayerPauserReg, permissionController, MIN_WITHDRAWAL_DELAY);
delegationImplementation = new DelegationManager(strategyManager, eigenPodManager, allocationManager, eigenLayerPauserReg, permissionController, MIN_WITHDRAWAL_DELAY);
strategyManagerImplementation = new StrategyManager(delegation, eigenLayerPauserReg);
avsDirectoryImplementation = new AVSDirectory(delegation, eigenLayerPauserReg);
eigenPodManagerImplementation = new EigenPodManager(
ethPOSDeposit,
eigenPodBeacon,
strategyManager,
delegation,
eigenLayerPauserReg
);
Expand Down Expand Up @@ -499,10 +498,6 @@ contract DeployFromScratch is Script, Test {
eigenPodManagerContract.eigenPodBeacon() == eigenPodBeacon,
"eigenPodManager: eigenPodBeacon contract address not set correctly"
);
require(
eigenPodManagerContract.strategyManager() == strategyManager,
"eigenPodManager: strategyManager contract address not set correctly"
);

require(
rewardsCoordinatorContract.delegationManager() == delegation,
Expand Down
7 changes: 1 addition & 6 deletions script/deploy/local/deploy_from_scratch.slashing.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,12 @@ contract DeployFromScratch is Script, Test {

// Second, deploy the *implementation* contracts, using the *proxy contracts* as inputs

delegationImplementation = new DelegationManager(avsDirectory, strategyManager, eigenPodManager, allocationManager, eigenLayerPauserReg, permissionController, MIN_WITHDRAWAL_DELAY);
delegationImplementation = new DelegationManager(strategyManager, eigenPodManager, allocationManager, eigenLayerPauserReg, permissionController, MIN_WITHDRAWAL_DELAY);
strategyManagerImplementation = new StrategyManager(delegation, eigenLayerPauserReg);
avsDirectoryImplementation = new AVSDirectory(delegation, eigenLayerPauserReg);
eigenPodManagerImplementation = new EigenPodManager(
ethPOSDeposit,
eigenPodBeacon,
strategyManager,
delegation,
eigenLayerPauserReg
);
Expand Down Expand Up @@ -498,10 +497,6 @@ contract DeployFromScratch is Script, Test {
eigenPodManagerContract.eigenPodBeacon() == eigenPodBeacon,
"eigenPodManager: eigenPodBeacon contract address not set correctly"
);
require(
eigenPodManagerContract.strategyManager() == strategyManager,
"eigenPodManager: strategyManager contract address not set correctly"
);

require(
rewardsCoordinatorContract.delegationManager() == delegation,
Expand Down
4 changes: 0 additions & 4 deletions script/utils/ExistingDeploymentParser.sol
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,6 @@ contract ExistingDeploymentParser is Script, Test {
eigenPodManager.eigenPodBeacon() == eigenPodBeacon,
"eigenPodManager: eigenPodBeacon contract address not set correctly"
);
require(
eigenPodManager.strategyManager() == strategyManager,
"eigenPodManager: strategyManager contract address not set correctly"
);
require(
eigenPodManager.delegationManager() == delegationManager,
"eigenPodManager: delegationManager contract address not set correctly"
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/core/AVSDirectoryStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ abstract contract AVSDirectoryStorage is IAVSDirectory {
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[41] private __gap;
uint256[47] private __gap;
}
51 changes: 25 additions & 26 deletions src/contracts/core/AllocationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ contract AllocationManager is
) external onlyWhenNotPaused(PAUSED_OPERATOR_SLASHING) checkCanCall(avs) {
// Check that the operator set exists and the operator is registered to it
OperatorSet memory operatorSet = OperatorSet(avs, params.operatorSetId);
bool isRegistered = _isRegistered(params.operator, operatorSet);
bool isOperatorSlashable = _isOperatorSlashable(params.operator, operatorSet);
require(_operatorSets[operatorSet.avs].contains(operatorSet.id), InvalidOperatorSet());
require(isRegistered, NotMemberOfSet());
require(isOperatorSlashable, OperatorNotSlashable());

uint256[] memory wadSlashed = new uint256[](params.strategies.length);

Expand All @@ -89,7 +89,7 @@ contract AllocationManager is

// 2. Skip if the operator does not have a slashable allocation
// NOTE: this "if" is equivalent to: `if (!_isAllocationSlashable)`, because the other
// conditions in this method are already true (isRegistered + operatorSetStrategies.contains)
// conditions in this method are already true (isOperatorSlashable + operatorSetStrategies.contains)
if (allocation.currentMagnitude == 0) {
continue;
}
Expand Down Expand Up @@ -165,7 +165,7 @@ contract AllocationManager is
OperatorSet memory operatorSet = params[i].operatorSet;
require(_operatorSets[operatorSet.avs].contains(operatorSet.id), InvalidOperatorSet());

bool isRegistered = _isRegistered(operator, operatorSet);
bool isOperatorSlashable = _isOperatorSlashable(operator, operatorSet);

for (uint256 j = 0; j < params[i].strategies.length; j++) {
IStrategy strategy = params[i].strategies[j];
Expand All @@ -181,7 +181,7 @@ contract AllocationManager is

// 2. Check whether the operator's allocation is slashable. If not, we allow instant
// deallocation.
bool isSlashable = _isAllocationSlashable(operatorSet, strategy, allocation, isRegistered);
bool isSlashable = _isAllocationSlashable(operatorSet, strategy, allocation, isOperatorSlashable);

// 3. Calculate the change in magnitude
allocation.pendingDiff = _calcDelta(allocation.currentMagnitude, params[i].newMagnitudes[j]);
Expand Down Expand Up @@ -242,7 +242,7 @@ contract AllocationManager is
// Check the operator set exists and the operator is not currently registered to it
OperatorSet memory operatorSet = OperatorSet(params.avs, params.operatorSetIds[i]);
require(_operatorSets[operatorSet.avs].contains(operatorSet.id), InvalidOperatorSet());
require(!_isRegistered(operator, operatorSet), AlreadyMemberOfSet());
require(!_isOperatorSlashable(operator, operatorSet), AlreadyMemberOfSet());

// Add operator to operator set
registeredSets[operator].add(operatorSet.key());
Expand Down Expand Up @@ -279,7 +279,7 @@ contract AllocationManager is
// forgefmt: disable-next-item
registrationStatus[params.operator][operatorSet.key()] = RegistrationStatus({
registered: false,
registeredUntil: uint32(block.number) + DEALLOCATION_DELAY
slashableUntil: uint32(block.number) + DEALLOCATION_DELAY
});
}

Expand Down Expand Up @@ -427,34 +427,28 @@ contract AllocationManager is
emit AllocationDelaySet(operator, delay, info.effectBlock);
}

function _isRegistered(address operator, OperatorSet memory operatorSet) internal view returns (bool) {
/// @notice returns whether the operator is slashable in the given operator set
function _isOperatorSlashable(address operator, OperatorSet memory operatorSet) internal view returns (bool) {
RegistrationStatus memory status = registrationStatus[operator][operatorSet.key()];

return status.registered || block.number < status.registeredUntil;
return status.registered || block.number < status.slashableUntil;
}

/// @notice returns whether the operator's allocation is slashable in the given operator set
function _isAllocationSlashable(
OperatorSet memory operatorSet,
IStrategy strategy,
Allocation memory allocation,
bool isRegistered
bool isOperatorSlashable
) internal view returns (bool) {
// If the operator set does not use this strategy, any allocation from it is not slashable
if (!_operatorSetStrategies[operatorSet.key()].contains(address(strategy))) {
return false;
}

// If the operator is not registered to the operator set, any allocation is not slashable
if (!isRegistered) {
return false;
}

// The allocation is not slashable if there is nothing allocated
if (allocation.currentMagnitude == 0) {
return false;
}

return true;
/// forgefmt: disable-next-item
return
// If the operator set does not use this strategy, any allocation from it is not slashable
_operatorSetStrategies[operatorSet.key()].contains(address(strategy)) &&
// If the operator is not slashable by the operatorSet, any allocation is not slashable
isOperatorSlashable &&
// If there is nothing allocated, the allocation is not slashable
allocation.currentMagnitude != 0;
}

/**
Expand Down Expand Up @@ -738,6 +732,11 @@ contract AllocationManager is
return operatorSets;
}

/// @inheritdoc IAllocationManager
function isMemberOfOperatorSet(address operator, OperatorSet memory operatorSet) public view returns (bool) {
return _operatorSetMembers[operatorSet.key()].contains(operator);
}

/// @inheritdoc IAllocationManager
function isOperatorSet(
OperatorSet memory operatorSet
Expand Down
9 changes: 1 addition & 8 deletions src/contracts/core/DelegationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,14 @@ contract DelegationManager is
* @dev Initializes the immutable addresses of the strategy mananger, eigenpod manager, and allocation manager.
*/
constructor(
IAVSDirectory _avsDirectory,
IStrategyManager _strategyManager,
IEigenPodManager _eigenPodManager,
IAllocationManager _allocationManager,
IPauserRegistry _pauserRegistry,
IPermissionController _permissionController,
uint32 _MIN_WITHDRAWAL_DELAY
)
DelegationManagerStorage(
_avsDirectory,
_strategyManager,
_eigenPodManager,
_allocationManager,
_MIN_WITHDRAWAL_DELAY
)
DelegationManagerStorage(_strategyManager, _eigenPodManager, _allocationManager, _MIN_WITHDRAWAL_DELAY)
Pausable(_pauserRegistry)
PermissionControllerMixin(_permissionController)
{
Expand Down
8 changes: 0 additions & 8 deletions src/contracts/core/DelegationManagerStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

import "../libraries/SlashingLib.sol";
import "../interfaces/IDelegationManager.sol";
import "../interfaces/IAVSDirectory.sol";
import "../interfaces/IEigenPodManager.sol";
import "../interfaces/IAllocationManager.sol";

Expand Down Expand Up @@ -41,11 +40,6 @@ abstract contract DelegationManagerStorage is IDelegationManager {

// Immutables

/// @notice The AVSDirectory contract for EigenLayer
IAVSDirectory public immutable avsDirectory;

// TODO: Switch these to ShareManagers, but this breaks a lot of tests

/// @notice The StrategyManager contract for EigenLayer
IStrategyManager public immutable strategyManager;

Expand Down Expand Up @@ -124,13 +118,11 @@ abstract contract DelegationManagerStorage is IDelegationManager {
// Construction

constructor(
IAVSDirectory _avsDirectory,
IStrategyManager _strategyManager,
IEigenPodManager _eigenPodManager,
IAllocationManager _allocationManager,
uint32 _MIN_WITHDRAWAL_DELAY_BLOCKS
) {
avsDirectory = _avsDirectory;
strategyManager = _strategyManager;
eigenPodManager = _eigenPodManager;
allocationManager = _allocationManager;
Expand Down
13 changes: 0 additions & 13 deletions src/contracts/interfaces/IAVSDirectory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,6 @@ interface IAVSDirectoryErrors {
error OperatorNotRegisteredToAVS();
/// @dev Thrown when `operator` is already registered to the AVS.
error OperatorAlreadyRegisteredToAVS();

/// @notice Enum representing the status of an operator's registration with an AVS
/// @dev Thrown when an invalid AVS is provided.
error InvalidAVS();
/// @dev Thrown when an invalid operator is provided.
error InvalidOperator();
/// @dev Thrown when an invalid operator set is provided.
error InvalidOperatorSet();
/// @dev Thrown when a strategy is already added to an operator set.
error StrategyAlreadyInOperatorSet();
/// @dev Thrown when a strategy is not in an operator set.
error StrategyNotInOperatorSet();

/// @dev Thrown when attempting to spend a spent eip-712 salt.
error SaltSpent();
}
Expand Down
17 changes: 10 additions & 7 deletions src/contracts/interfaces/IAllocationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ interface IAllocationManagerErrors {
error InvalidWadToSlash();
/// @dev Thrown when two array parameters have mismatching lengths.
error InputArrayLengthMismatch();
/// @dev Thrown when calling a view function that requires a valid block number.
error InvalidBlockNumber();
/// @dev Thrown when creating an operator set with more than max strategies.
error MaxStrategiesExceeded();

Expand Down Expand Up @@ -43,13 +41,11 @@ interface IAllocationManagerErrors {

/// @dev Thrown when an invalid operator set is provided.
error InvalidOperatorSet();
/// @dev Thrown when a strategy is referenced that does not belong to an operator set.
error InvalidStrategy();
/// @dev Thrown when provided `strategies` are not in ascending order.
error StrategiesMustBeInAscendingOrder();
/// @dev Thrown when trying to add a strategy to an operator set that already contains it.
error StrategyAlreadyInOperatorSet();
/// @dev Thrown when trying to remove a strategy from an operator set it is not a part of.
/// @dev Thrown when a strategy is referenced that does not belong to an operator set.
error StrategyNotInOperatorSet();

/// Modifying Allocations
Expand Down Expand Up @@ -93,12 +89,12 @@ interface IAllocationManagerTypes {
/**
* @notice Contains registration details for an operator pertaining to an operator set
* @param registered Whether the operator is currently registered for the operator set
* @param registeredUntil If the operator is not registered, how long until the operator is no longer
* @param slashableUntil If the operator is not registered, how long until the operator is no longer
* slashable by the AVS.
*/
struct RegistrationStatus {
bool registered;
uint32 registeredUntil;
uint32 slashableUntil;
}

/**
Expand Down Expand Up @@ -485,6 +481,13 @@ interface IAllocationManager is ISignatureUtils, IAllocationManagerErrors, IAllo
address operator
) external view returns (OperatorSet[] memory operatorSets);

/**
* @notice Returns whether the operator is registered for the operator set
* @param operator The operator to query
* @param operatorSet The operator set to query
*/
function isMemberOfOperatorSet(address operator, OperatorSet memory operatorSet) external view returns (bool);

/**
* @notice Returns whether the operator set exists
*/
Expand Down
43 changes: 0 additions & 43 deletions src/contracts/interfaces/IDelegationFaucet.sol

This file was deleted.

Loading

0 comments on commit d310921

Please sign in to comment.