Skip to content

Commit 616ea70

Browse files
0xClandestineypatil12
authored andcommitted
fix: beaconchain slashable shares in queue (#1087)
1 parent 6397cb5 commit 616ea70

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/contracts/core/DelegationManager.sol

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -770,13 +770,11 @@ contract DelegationManager is
770770

771771
/// @dev Add to the cumulative withdrawn scaled shares from an operator for a given strategy
772772
function _addQueuedSlashableShares(address operator, IStrategy strategy, uint256 scaledShares) internal {
773-
if (strategy != beaconChainETHStrategy) {
774-
uint256 currCumulativeScaledShares = _cumulativeScaledSharesHistory[operator][strategy].latest();
775-
_cumulativeScaledSharesHistory[operator][strategy].push({
776-
key: uint32(block.number),
777-
value: currCumulativeScaledShares + scaledShares
778-
});
779-
}
773+
uint256 currCumulativeScaledShares = _cumulativeScaledSharesHistory[operator][strategy].latest();
774+
_cumulativeScaledSharesHistory[operator][strategy].push({
775+
key: uint32(block.number),
776+
value: currCumulativeScaledShares + scaledShares
777+
});
780778
}
781779

782780
/// @dev Get the shares from a queued withdrawal.

src/test/unit/DelegationUnit.t.sol

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7491,8 +7491,8 @@ contract DelegationManagerUnitTests_slashingShares is DelegationManagerUnitTests
74917491
delegationManager.queueWithdrawals(queuedWithdrawalParams);
74927492
assertEq(
74937493
delegationManager.getSlashableSharesInQueue(operator, beaconChainETHStrategy),
7494-
0,
7495-
"there should be 0 withdrawAmount slashable shares in queue since this is beaconChainETHStrategy"
7494+
withdrawAmount,
7495+
"there should be withdrawAmount slashable shares in queue"
74967496
);
74977497
}
74987498

@@ -7504,6 +7504,7 @@ contract DelegationManagerUnitTests_slashingShares is DelegationManagerUnitTests
75047504
// Therefore amount of shares to burn should be what the staker still has remaining + staker1 shares and then
75057505
// divided by 2 since the operator was slashed 50%
75067506
uint256 sharesToDecrease = (shares + depositAmount - withdrawAmount) * 3 / 4;
7507+
uint256 sharesToBurn = sharesToDecrease + (delegationManager.getSlashableSharesInQueue(operator, beaconChainETHStrategy) * 3 / 4);
75077508

75087509
// 4. Burn shares
75097510
_setOperatorMagnitude(operator, beaconChainETHStrategy, newMagnitude);
@@ -7512,7 +7513,7 @@ contract DelegationManagerUnitTests_slashingShares is DelegationManagerUnitTests
75127513

75137514
// Assert OperatorSharesSlashed event was emitted with correct params
75147515
cheats.expectEmit(true, true, true, true, address(delegationManager));
7515-
emit OperatorSharesSlashed(operator, beaconChainETHStrategy, sharesToDecrease);
7516+
emit OperatorSharesSlashed(operator, beaconChainETHStrategy, sharesToBurn);
75167517

75177518
cheats.prank(address(allocationManagerMock));
75187519
delegationManager.slashOperatorShares({
@@ -7525,8 +7526,8 @@ contract DelegationManagerUnitTests_slashingShares is DelegationManagerUnitTests
75257526
// 5. Assert expected values
75267527
uint256 queuedSlashableSharesAfter = delegationManager.getSlashableSharesInQueue(operator, beaconChainETHStrategy);
75277528
uint256 operatorSharesAfter = delegationManager.operatorShares(operator, beaconChainETHStrategy);
7528-
assertEq(queuedSlashableSharesBefore, 0, "Slashable shares in queue should be 0 for beaconChainStrategy");
7529-
assertEq(queuedSlashableSharesAfter, 0, "Slashable shares in queue should be 0 for beaconChainStrategy");
7529+
assertEq(queuedSlashableSharesBefore, withdrawAmount, "Slashable shares in queue should be full withdraw amount");
7530+
assertEq(queuedSlashableSharesAfter, withdrawAmount / 4, "Slashable shares in queue should be 1/4 withdraw amount after slashing");
75307531
assertEq(operatorSharesAfter, operatorSharesBefore - sharesToDecrease, "operator shares should be decreased by sharesToDecrease");
75317532
}
75327533

0 commit comments

Comments
 (0)