Skip to content

Commit 170e3dc

Browse files
committed
feat: substitute calcSlashedAmount for scaleForBurning
1 parent b6cfb82 commit 170e3dc

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

src/contracts/core/DelegationManager.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,8 +793,8 @@ contract DelegationManager is
793793
// less than or equal to MIN_WITHDRAWAL_DELAY_BLOCKS ago. These shares are still slashable.
794794
uint256 scaledSharesAdded = curQueuedScaledShares - prevQueuedScaledShares;
795795

796-
return SlashingLib.scaleForBurning({
797-
scaledShares: scaledSharesAdded,
796+
return SlashingLib.calcSlashedAmount({
797+
operatorShares: scaledSharesAdded.mulWad(prevMaxMagnitude),
798798
prevMaxMagnitude: prevMaxMagnitude,
799799
newMaxMagnitude: newMaxMagnitude
800800
});

src/contracts/libraries/SlashingLib.sol

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,6 @@ library SlashingLib {
7474
return scaledShares.mulWad(slashingFactor);
7575
}
7676

77-
/**
78-
* @notice Scales shares according to the difference in an operator's magnitude before and
79-
* after being slashed. This is used to calculate the number of slashable shares in the
80-
* withdrawal queue.
81-
* NOTE: max magnitude is guaranteed to only ever decrease.
82-
*/
83-
function scaleForBurning(
84-
uint256 scaledShares,
85-
uint64 prevMaxMagnitude,
86-
uint64 newMaxMagnitude
87-
) internal pure returns (uint256) {
88-
return scaledShares.mulWad(prevMaxMagnitude - newMaxMagnitude);
89-
}
90-
9177
function update(
9278
DepositScalingFactor storage dsf,
9379
uint256 prevDepositShares,
@@ -178,6 +164,10 @@ library SlashingLib {
178164
uint256 prevMaxMagnitude,
179165
uint256 newMaxMagnitude
180166
) internal pure returns (uint256) {
167+
if (prevMaxMagnitude == 0) {
168+
// TODO: consider throwing an error instead
169+
return 0;
170+
}
181171
// round up mulDiv so we don't overslash
182172
return operatorShares - operatorShares.mulDiv(newMaxMagnitude, prevMaxMagnitude, Math.Rounding.Up);
183173
}

0 commit comments

Comments
 (0)