Skip to content

Commit

Permalink
fix: beaconchain slashable shares in queue (#1087)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xClandestine authored and ypatil12 committed Feb 20, 2025
1 parent 6397cb5 commit 616ea70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
12 changes: 5 additions & 7 deletions src/contracts/core/DelegationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -770,13 +770,11 @@ contract DelegationManager is

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

/// @dev Get the shares from a queued withdrawal.
Expand Down
11 changes: 6 additions & 5 deletions src/test/unit/DelegationUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7491,8 +7491,8 @@ contract DelegationManagerUnitTests_slashingShares is DelegationManagerUnitTests
delegationManager.queueWithdrawals(queuedWithdrawalParams);
assertEq(
delegationManager.getSlashableSharesInQueue(operator, beaconChainETHStrategy),
0,
"there should be 0 withdrawAmount slashable shares in queue since this is beaconChainETHStrategy"
withdrawAmount,
"there should be withdrawAmount slashable shares in queue"
);
}

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

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

// Assert OperatorSharesSlashed event was emitted with correct params
cheats.expectEmit(true, true, true, true, address(delegationManager));
emit OperatorSharesSlashed(operator, beaconChainETHStrategy, sharesToDecrease);
emit OperatorSharesSlashed(operator, beaconChainETHStrategy, sharesToBurn);

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

Expand Down

0 comments on commit 616ea70

Please sign in to comment.