Skip to content

Commit

Permalink
feat: restricted strategy list (broken tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xClandestine committed Oct 16, 2024
1 parent dc7e929 commit 947f6d9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/contracts/core/AVSDirectory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,24 @@ contract AVSDirectory is
}
}

/// @inheritdoc IAVSDirectory
function isOperatorSetStrategy(OperatorSet calldata operatorSet, IStrategy strategy) external view returns (bool) {
return _operatorSetStrategies[_encodeOperatorSet(operatorSet)].contains(address(strategy));
}

/// @inheritdoc IAVSDirectory
function isOperatorSetStrategyBatch(
OperatorSet calldata operatorSet,
IStrategy[] calldata strategies
) external view returns (bool) {
for (uint256 i; i < strategies.length; ++i) {
if (!_operatorSetStrategies[_encodeOperatorSet(operatorSet)].contains(address(strategies[i]))) {
return false;
}
}
return true;
}

/// @inheritdoc IAVSDirectory
function getNumOperatorsInOperatorSet(
OperatorSet memory operatorSet
Expand Down
15 changes: 13 additions & 2 deletions src/contracts/core/AllocationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,19 @@ contract AllocationManager is
function slashOperator(
SlashingParams calldata params
) external onlyWhenNotPaused(PAUSED_OPERATOR_SLASHING) {
// Assert that the amount to slash is within bounds of 1 and WAD (1e18).
require(0 < params.wadToSlash && params.wadToSlash <= WAD, InvalidWadToSlash());

// Check that the operator is registered and slashable
OperatorSet memory operatorSet = OperatorSet({avs: msg.sender, operatorSetId: params.operatorSetId});
bytes32 operatorSetKey = _encodeOperatorSet(operatorSet);

// Assert that the provided strategies are all whitelisted for the given operator set.
require(avsDirectory.isOperatorSetStrategyBatch(operatorSet, params.strategies), InvalidStrategy());
// Asser that the operator is slashable for the given operator set.
require(avsDirectory.isOperatorSlashable(params.operator, operatorSet), InvalidOperator());

// Check that the operator is registered and slashable
bytes32 operatorSetKey = _encodeOperatorSet(operatorSet);

// Record the proportion of 1e18 that the operator's total shares that are being slashed
uint256[] memory wadSlashed = new uint256[](params.strategies.length);

Expand Down Expand Up @@ -161,6 +167,11 @@ contract AllocationManager is
if (info.pendingDiff < 0) {
info.effectTimestamp = uint32(block.timestamp) + DEALLOCATION_DELAY;
} else if (info.pendingDiff > 0) {
require(
avsDirectory.isOperatorSetStrategy(allocation.operatorSets[i], allocation.strategy),
InvalidStrategy()
);

info.effectTimestamp = uint32(block.timestamp) + operatorAllocationDelay;

// For allocations, immediately add to encumberedMagnitude to ensure the operator
Expand Down
9 changes: 9 additions & 0 deletions src/contracts/interfaces/IAVSDirectory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,15 @@ interface IAVSDirectory is IAVSDirectoryEvents, IAVSDirectoryErrors, ISignatureU
OperatorSet memory operatorSet
) external view returns (IStrategy[] memory strategies);

/// @notice Returns whether or not a strategy is allocatable/slashable for an operator set.
function isOperatorSetStrategy(OperatorSet calldata operatorSet, IStrategy strategy) external view returns (bool);

/// @notice Returns whether or not a list of strategies are all allocatable/slashable for an operator set.
function isOperatorSetStrategyBatch(
OperatorSet calldata operatorSet,
IStrategy[] calldata strategy
) external view returns (bool);

/**
* @notice Returns the number of operators registered to an operatorSet.
* @param operatorSet The operatorSet to get the member count for
Expand Down
2 changes: 2 additions & 0 deletions src/contracts/interfaces/IAllocationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ interface IAllocationManagerErrors {
error InvalidOperatorSet();
/// @dev Thrown when an invalid operator is provided.
error InvalidOperator();
/// @dev Thrown when an invalid strategy is provided.
error InvalidStrategy();
/// @dev Thrown when caller is not the delegation manager.
error OnlyDelegationManager();
/// @dev Thrown when an operator attempts to set their allocation for an operatorSet to the same value
Expand Down

0 comments on commit 947f6d9

Please sign in to comment.