Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 12 additions & 23 deletions src/contracts/core/AllocationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,11 @@ contract AllocationManager is
function slashOperator(
address avs,
SlashingParams calldata params
)
external
onlyWhenNotPaused(PAUSED_OPERATOR_SLASHING)
checkCanCall(avs)
returns (uint256 slashId, uint256[] memory shares)
{
) external onlyWhenNotPaused(PAUSED_OPERATOR_SLASHING) checkCanCall(avs) returns (uint256, uint256[] memory) {
// Check that the operator set exists and the operator is registered to it
OperatorSet memory operatorSet = OperatorSet(avs, params.operatorSetId);

require(params.strategies.length == params.wadsToSlash.length, InputArrayLengthMismatch());
require(_operatorSets[operatorSet.avs].contains(operatorSet.id), InvalidOperatorSet());

require(isOperatorSlashable(params.operator, operatorSet), OperatorNotSlashable());

return _slashOperator(params, operatorSet);
Expand Down Expand Up @@ -327,13 +320,11 @@ contract AllocationManager is
OperatorSet memory operatorSet
) internal returns (uint256 slashId, uint256[] memory shares) {
uint256[] memory wadSlashed = new uint256[](params.strategies.length);
shares = new uint256[](params.strategies.length);

// Increment the slash count for the operator set.
slashId = ++_slashCount[operatorSet.key()];

uint64[] memory prevMaxMagnitudes = new uint64[](params.strategies.length);
uint64[] memory newMaxMagnitudes = new uint64[](params.strategies.length);

// For each strategy in the operator set, slash any existing allocation
for (uint256 i = 0; i < params.strategies.length; i++) {
// Check that `strategies` is in ascending order.
Expand Down Expand Up @@ -390,26 +381,24 @@ contract AllocationManager is
// 5. Update state
_updateAllocationInfo(params.operator, operatorSet.key(), params.strategies[i], info, allocation);

// Emit an event for the updated allocation
emit AllocationUpdated(
params.operator, operatorSet, params.strategies[i], allocation.currentMagnitude, uint32(block.number)
);

_updateMaxMagnitude(params.operator, params.strategies[i], info.maxMagnitude);

prevMaxMagnitudes[i] = prevMaxMagnitude;
newMaxMagnitudes[i] = info.maxMagnitude;
// 6. Slash operators shares in the DelegationManager
shares[i] = delegation.slashOperatorShares({
operator: params.operator,
operatorSet: operatorSet,
slashId: slashId,
strategy: params.strategies[i],
prevMaxMagnitude: prevMaxMagnitude,
newMaxMagnitude: info.maxMagnitude
});
}

// 6. Slash operators shares in the DelegationManager
shares = delegation.slashOperatorShares({
operator: params.operator,
operatorSet: operatorSet,
slashId: slashId,
strategies: params.strategies,
prevMaxMagnitudes: prevMaxMagnitudes,
newMaxMagnitudes: newMaxMagnitudes
});

emit OperatorSlashed(params.operator, operatorSet, params.strategies, wadSlashed, params.description);
}

Expand Down
92 changes: 35 additions & 57 deletions src/contracts/core/DelegationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -285,16 +285,40 @@ contract DelegationManager is
address operator,
OperatorSet calldata operatorSet,
uint256 slashId,
IStrategy[] calldata strategies,
uint64[] calldata prevMaxMagnitudes,
uint64[] calldata newMaxMagnitudes
) external onlyAllocationManager nonReentrant returns (uint256[] memory totalDepositSharesToBurn) {
totalDepositSharesToBurn = new uint256[](strategies.length);
for (uint256 i = 0; i < strategies.length; i++) {
totalDepositSharesToBurn[i] = _slashOperatorShares(
operator, operatorSet, slashId, strategies[i], prevMaxMagnitudes[i], newMaxMagnitudes[i]
);
}
IStrategy strategy,
uint64 prevMaxMagnitude,
uint64 newMaxMagnitude
) external onlyAllocationManager nonReentrant returns (uint256 totalDepositSharesToBurn) {
uint256 operatorSharesSlashed = SlashingLib.calcSlashedAmount({
operatorShares: operatorShares[operator][strategy],
prevMaxMagnitude: prevMaxMagnitude,
newMaxMagnitude: newMaxMagnitude
});

uint256 scaledSharesSlashedFromQueue = _getSlashableSharesInQueue({
operator: operator,
strategy: strategy,
prevMaxMagnitude: prevMaxMagnitude,
newMaxMagnitude: newMaxMagnitude
});

// Calculate the total deposit shares to burn - slashed operator shares plus still-slashable
// shares sitting in the withdrawal queue.
totalDepositSharesToBurn = operatorSharesSlashed + scaledSharesSlashedFromQueue;

// Remove shares from operator
_decreaseDelegation({
operator: operator,
staker: address(0), // we treat this as a decrease for the 0-staker (only used for events)
strategy: strategy,
sharesToDecrease: operatorSharesSlashed
});

// Emit event for operator shares being slashed
emit OperatorSharesSlashed(operator, strategy, totalDepositSharesToBurn);

_getShareManager(strategy).increaseBurnableShares(operatorSet, slashId, strategy, totalDepositSharesToBurn);

return totalDepositSharesToBurn;
}

Expand Down Expand Up @@ -667,54 +691,8 @@ contract DelegationManager is
emit OperatorSharesDecreased(operator, staker, strategy, sharesToDecrease);
}

/// @dev Slashes operator shares and queues a redistribution for the slashable shares in the queue.
/// See `slashOperatorShares` for more details.
function _slashOperatorShares(
address operator,
OperatorSet memory operatorSet,
uint256 slashId,
IStrategy strategy,
uint64 prevMaxMagnitude,
uint64 newMaxMagnitude
) internal returns (uint256 totalDepositSharesToBurn) {
// Avoid emitting events if nothing has changed for sanitization.
if (prevMaxMagnitude == newMaxMagnitude) return 0;

uint256 operatorSharesSlashed = SlashingLib.calcSlashedAmount({
operatorShares: operatorShares[operator][strategy],
prevMaxMagnitude: prevMaxMagnitude,
newMaxMagnitude: newMaxMagnitude
});

uint256 scaledSharesSlashedFromQueue = _getSlashableSharesInQueue({
operator: operator,
strategy: strategy,
prevMaxMagnitude: prevMaxMagnitude,
newMaxMagnitude: newMaxMagnitude
});

// Calculate the total deposit shares to burn - slashed operator shares plus still-slashable
// shares sitting in the withdrawal queue.
totalDepositSharesToBurn = operatorSharesSlashed + scaledSharesSlashedFromQueue;

// Remove shares from operator
_decreaseDelegation({
operator: operator,
staker: address(0), // we treat this as a decrease for the 0-staker (only used for events)
strategy: strategy,
sharesToDecrease: operatorSharesSlashed
});

// Emit event for operator shares being slashed
emit OperatorSharesSlashed(operator, strategy, totalDepositSharesToBurn);

_getShareManager(strategy).increaseBurnableShares(operatorSet, slashId, strategy, totalDepositSharesToBurn);

return totalDepositSharesToBurn;
}

/// @dev If `operator` has configured a `delegationApprover`, check that `signature` and `salt`
/// are a valid approval for `staker` delegating to `operator`.
/// are a valid appfroval for `staker` delegating to `operator`.
function _checkApproverSignature(
address staker,
address operator,
Expand Down
14 changes: 7 additions & 7 deletions src/contracts/interfaces/IDelegationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,9 @@ interface IDelegationManager is ISignatureUtilsMixin, IDelegationManagerErrors,
* @param operator The operator to decrease shares for.
* @param operatorSet The operator set to decrease shares for.
* @param slashId The slash id to decrease shares for.
* @param strategies The strategies to decrease shares for.
* @param prevMaxMagnitudes The previous maxMagnitudes of the operator.
* @param newMaxMagnitudes The new maxMagnitudes of the operator.
* @param strategy The strategy to decrease shares for.
* @param prevMaxMagnitude The previous maxMagnitude of the operator.
* @param newMaxMagnitude The new maxMagnitude of the operator.
* @dev Callable only by the AllocationManager.
* @dev Note: Assumes `prevMaxMagnitude <= newMaxMagnitude`. This invariant is maintained in
* the AllocationManager.
Expand All @@ -374,10 +374,10 @@ interface IDelegationManager is ISignatureUtilsMixin, IDelegationManagerErrors,
address operator,
OperatorSet calldata operatorSet,
uint256 slashId,
IStrategy[] calldata strategies,
uint64[] calldata prevMaxMagnitudes,
uint64[] calldata newMaxMagnitudes
) external returns (uint256[] memory totalDepositSharesToBurn);
IStrategy strategy,
uint64 prevMaxMagnitude,
uint64 newMaxMagnitude
) external returns (uint256 totalDepositSharesToBurn);

/**
*
Expand Down
2 changes: 0 additions & 2 deletions src/test/mocks/DelegationManagerMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ contract DelegationManagerMock is Test {
uint[] memory amountSlashed = new uint[](strategies.length);

for (uint i = 0; i < strategies.length; i++) {
if (prevMaxMagnitudes[i] == newMaxMagnitudes[i]) continue;

amountSlashed[i] = SlashingLib.calcSlashedAmount({
operatorShares: operatorShares[operator][strategies[i]],
prevMaxMagnitude: prevMaxMagnitudes[i],
Expand Down
Loading
Loading