Skip to content

Commit 359c496

Browse files
committed
chore: bring back non-arrayified slashOperatorShares (#1400)
**Motivation:** We want to minimize the diff between slashing and redistribution. Bring back the single call from ALM to DM for slashes. **Modifications:** Bring back single call from ALM to DM for slash, instead of aggregating all mags. **Result:** Smaller Diff
1 parent 7639742 commit 359c496

File tree

5 files changed

+116
-227
lines changed

5 files changed

+116
-227
lines changed

src/contracts/core/AllocationManager.sol

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,11 @@ contract AllocationManager is
6363
function slashOperator(
6464
address avs,
6565
SlashingParams calldata params
66-
)
67-
external
68-
onlyWhenNotPaused(PAUSED_OPERATOR_SLASHING)
69-
checkCanCall(avs)
70-
returns (uint256 slashId, uint256[] memory shares)
71-
{
66+
) external onlyWhenNotPaused(PAUSED_OPERATOR_SLASHING) checkCanCall(avs) returns (uint256, uint256[] memory) {
7267
// Check that the operator set exists and the operator is registered to it
7368
OperatorSet memory operatorSet = OperatorSet(avs, params.operatorSetId);
74-
7569
require(params.strategies.length == params.wadsToSlash.length, InputArrayLengthMismatch());
7670
require(_operatorSets[operatorSet.avs].contains(operatorSet.id), InvalidOperatorSet());
77-
7871
require(isOperatorSlashable(params.operator, operatorSet), OperatorNotSlashable());
7972

8073
return _slashOperator(params, operatorSet);
@@ -327,13 +320,11 @@ contract AllocationManager is
327320
OperatorSet memory operatorSet
328321
) internal returns (uint256 slashId, uint256[] memory shares) {
329322
uint256[] memory wadSlashed = new uint256[](params.strategies.length);
323+
shares = new uint256[](params.strategies.length);
330324

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

334-
uint64[] memory prevMaxMagnitudes = new uint64[](params.strategies.length);
335-
uint64[] memory newMaxMagnitudes = new uint64[](params.strategies.length);
336-
337328
// For each strategy in the operator set, slash any existing allocation
338329
for (uint256 i = 0; i < params.strategies.length; i++) {
339330
// Check that `strategies` is in ascending order.
@@ -390,26 +381,24 @@ contract AllocationManager is
390381
// 5. Update state
391382
_updateAllocationInfo(params.operator, operatorSet.key(), params.strategies[i], info, allocation);
392383

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

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

399-
prevMaxMagnitudes[i] = prevMaxMagnitude;
400-
newMaxMagnitudes[i] = info.maxMagnitude;
391+
// 6. Slash operators shares in the DelegationManager
392+
shares[i] = delegation.slashOperatorShares({
393+
operator: params.operator,
394+
operatorSet: operatorSet,
395+
slashId: slashId,
396+
strategy: params.strategies[i],
397+
prevMaxMagnitude: prevMaxMagnitude,
398+
newMaxMagnitude: info.maxMagnitude
399+
});
401400
}
402401

403-
// 6. Slash operators shares in the DelegationManager
404-
shares = delegation.slashOperatorShares({
405-
operator: params.operator,
406-
operatorSet: operatorSet,
407-
slashId: slashId,
408-
strategies: params.strategies,
409-
prevMaxMagnitudes: prevMaxMagnitudes,
410-
newMaxMagnitudes: newMaxMagnitudes
411-
});
412-
413402
emit OperatorSlashed(params.operator, operatorSet, params.strategies, wadSlashed, params.description);
414403
}
415404

src/contracts/core/DelegationManager.sol

Lines changed: 35 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -285,16 +285,40 @@ contract DelegationManager is
285285
address operator,
286286
OperatorSet calldata operatorSet,
287287
uint256 slashId,
288-
IStrategy[] calldata strategies,
289-
uint64[] calldata prevMaxMagnitudes,
290-
uint64[] calldata newMaxMagnitudes
291-
) external onlyAllocationManager nonReentrant returns (uint256[] memory totalDepositSharesToBurn) {
292-
totalDepositSharesToBurn = new uint256[](strategies.length);
293-
for (uint256 i = 0; i < strategies.length; i++) {
294-
totalDepositSharesToBurn[i] = _slashOperatorShares(
295-
operator, operatorSet, slashId, strategies[i], prevMaxMagnitudes[i], newMaxMagnitudes[i]
296-
);
297-
}
288+
IStrategy strategy,
289+
uint64 prevMaxMagnitude,
290+
uint64 newMaxMagnitude
291+
) external onlyAllocationManager nonReentrant returns (uint256 totalDepositSharesToBurn) {
292+
uint256 operatorSharesSlashed = SlashingLib.calcSlashedAmount({
293+
operatorShares: operatorShares[operator][strategy],
294+
prevMaxMagnitude: prevMaxMagnitude,
295+
newMaxMagnitude: newMaxMagnitude
296+
});
297+
298+
uint256 scaledSharesSlashedFromQueue = _getSlashableSharesInQueue({
299+
operator: operator,
300+
strategy: strategy,
301+
prevMaxMagnitude: prevMaxMagnitude,
302+
newMaxMagnitude: newMaxMagnitude
303+
});
304+
305+
// Calculate the total deposit shares to burn - slashed operator shares plus still-slashable
306+
// shares sitting in the withdrawal queue.
307+
totalDepositSharesToBurn = operatorSharesSlashed + scaledSharesSlashedFromQueue;
308+
309+
// Remove shares from operator
310+
_decreaseDelegation({
311+
operator: operator,
312+
staker: address(0), // we treat this as a decrease for the 0-staker (only used for events)
313+
strategy: strategy,
314+
sharesToDecrease: operatorSharesSlashed
315+
});
316+
317+
// Emit event for operator shares being slashed
318+
emit OperatorSharesSlashed(operator, strategy, totalDepositSharesToBurn);
319+
320+
_getShareManager(strategy).increaseBurnableShares(operatorSet, slashId, strategy, totalDepositSharesToBurn);
321+
298322
return totalDepositSharesToBurn;
299323
}
300324

@@ -667,54 +691,8 @@ contract DelegationManager is
667691
emit OperatorSharesDecreased(operator, staker, strategy, sharesToDecrease);
668692
}
669693

670-
/// @dev Slashes operator shares and queues a redistribution for the slashable shares in the queue.
671-
/// See `slashOperatorShares` for more details.
672-
function _slashOperatorShares(
673-
address operator,
674-
OperatorSet memory operatorSet,
675-
uint256 slashId,
676-
IStrategy strategy,
677-
uint64 prevMaxMagnitude,
678-
uint64 newMaxMagnitude
679-
) internal returns (uint256 totalDepositSharesToBurn) {
680-
// Avoid emitting events if nothing has changed for sanitization.
681-
if (prevMaxMagnitude == newMaxMagnitude) return 0;
682-
683-
uint256 operatorSharesSlashed = SlashingLib.calcSlashedAmount({
684-
operatorShares: operatorShares[operator][strategy],
685-
prevMaxMagnitude: prevMaxMagnitude,
686-
newMaxMagnitude: newMaxMagnitude
687-
});
688-
689-
uint256 scaledSharesSlashedFromQueue = _getSlashableSharesInQueue({
690-
operator: operator,
691-
strategy: strategy,
692-
prevMaxMagnitude: prevMaxMagnitude,
693-
newMaxMagnitude: newMaxMagnitude
694-
});
695-
696-
// Calculate the total deposit shares to burn - slashed operator shares plus still-slashable
697-
// shares sitting in the withdrawal queue.
698-
totalDepositSharesToBurn = operatorSharesSlashed + scaledSharesSlashedFromQueue;
699-
700-
// Remove shares from operator
701-
_decreaseDelegation({
702-
operator: operator,
703-
staker: address(0), // we treat this as a decrease for the 0-staker (only used for events)
704-
strategy: strategy,
705-
sharesToDecrease: operatorSharesSlashed
706-
});
707-
708-
// Emit event for operator shares being slashed
709-
emit OperatorSharesSlashed(operator, strategy, totalDepositSharesToBurn);
710-
711-
_getShareManager(strategy).increaseBurnableShares(operatorSet, slashId, strategy, totalDepositSharesToBurn);
712-
713-
return totalDepositSharesToBurn;
714-
}
715-
716694
/// @dev If `operator` has configured a `delegationApprover`, check that `signature` and `salt`
717-
/// are a valid approval for `staker` delegating to `operator`.
695+
/// are a valid appfroval for `staker` delegating to `operator`.
718696
function _checkApproverSignature(
719697
address staker,
720698
address operator,

src/contracts/interfaces/IDelegationManager.sol

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,9 @@ interface IDelegationManager is ISignatureUtilsMixin, IDelegationManagerErrors,
362362
* @param operator The operator to decrease shares for.
363363
* @param operatorSet The operator set to decrease shares for.
364364
* @param slashId The slash id to decrease shares for.
365-
* @param strategies The strategies to decrease shares for.
366-
* @param prevMaxMagnitudes The previous maxMagnitudes of the operator.
367-
* @param newMaxMagnitudes The new maxMagnitudes of the operator.
365+
* @param strategy The strategy to decrease shares for.
366+
* @param prevMaxMagnitude The previous maxMagnitude of the operator.
367+
* @param newMaxMagnitude The new maxMagnitude of the operator.
368368
* @dev Callable only by the AllocationManager.
369369
* @dev Note: Assumes `prevMaxMagnitude <= newMaxMagnitude`. This invariant is maintained in
370370
* the AllocationManager.
@@ -374,10 +374,10 @@ interface IDelegationManager is ISignatureUtilsMixin, IDelegationManagerErrors,
374374
address operator,
375375
OperatorSet calldata operatorSet,
376376
uint256 slashId,
377-
IStrategy[] calldata strategies,
378-
uint64[] calldata prevMaxMagnitudes,
379-
uint64[] calldata newMaxMagnitudes
380-
) external returns (uint256[] memory totalDepositSharesToBurn);
377+
IStrategy strategy,
378+
uint64 prevMaxMagnitude,
379+
uint64 newMaxMagnitude
380+
) external returns (uint256 totalDepositSharesToBurn);
381381

382382
/**
383383
*

src/test/mocks/DelegationManagerMock.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ contract DelegationManagerMock is Test {
3636
uint[] memory amountSlashed = new uint[](strategies.length);
3737

3838
for (uint i = 0; i < strategies.length; i++) {
39-
if (prevMaxMagnitudes[i] == newMaxMagnitudes[i]) continue;
40-
4139
amountSlashed[i] = SlashingLib.calcSlashedAmount({
4240
operatorShares: operatorShares[operator][strategies[i]],
4341
prevMaxMagnitude: prevMaxMagnitudes[i],

0 commit comments

Comments
 (0)