Slashing penalty is unfairly paid by a subset of users if a deficit is accumulated
When a deficit accumulates in EigenPodManager due to slashing during a withdrawal, the first cohort to settle a withdrawal pays the entire penalty, potentially receiving zero ETH, while later cohorts pay nothing. This unfairly concentrates the slashing cost on a subset of users.
Source: https://github.com/sherlock-audit/2024-02-rio-network-core-protocol-judging/issues/363
The protocol has acknowledged this issue.
Found by
monrel
Summary
If a deficit is accumulated in the EigenPodManager due to slashing when ETH is being withdrawn the slashing payment will be taken from the first cohort to complete a withdrawal.
Vulnerability Detail
A deficit can happen in podOwnerShares[podOwner] in the EigenPodManager in the EigenLayer protocol. This can happen if validators are slashed when ETH is queued for withdrawal.
The issue is that this deficit will be paid for by the next cohort to complete a withdrawal by calling settleEpochFromEigenLayer().
In the following code we can see how epochWithdrawals.assetsReceived is calculated based on the amount received from the delegationManager.completeQueuedWithdrawal call
uint256 balanceBefore = asset.getSelfBalance();
address[] memory assets = asset.toArray();
bytes32[] memory roots = new bytes32[](queuedWithdrawalCount);
IDelegationManager.Withdrawal memory queuedWithdrawal;
for (uint256 i; i < queuedWithdrawalCount; ++i) {
queuedWithdrawal = queuedWithdrawals[i];
roots[i] = _computeWithdrawalRoot(queuedWithdrawal);
delegationManager.completeQueuedWithdrawal(queuedWithdrawal, assets, middlewareTimesIndexes[i], true);
// Decrease the amount of ETH queued for withdrawal. We do not need to validate the staker as
// the aggregate root will be validated below.
if (asset == ETH_ADDRESS) {
IRioLRTOperatorDelegator(queuedWithdrawal.staker).decreaseETHQueuedForUserSettlement(
queuedWithdrawal.shares[0]
);
}
}
if (epochWithdrawals.aggregateRoot != keccak256(abi.encode(roots))) {
revert INVALID_AGGREGATE_WITHDRAWAL_ROOT();
}
epochWithdrawals.shareValueOfAssetsReceived = SafeCast.toUint120(epochWithdrawals.sharesOwed);
uint256 assetsReceived = asset.getSelfBalance() - balanceBefore;
epochWithdrawals.assetsReceived += SafeCast.toUint120(assetsReceived);
the amount received could be 0 if the deficit is larger than the amount queued for this cohort. See following code in withdrawSharesAsTokens() EigenPodManager
} else {
podOwnerShares[podOwner] += int256(shares);
emit PodSharesUpdated(podOwner, int256(shares));
return;
}
These users will pay for all slashing penalties instead of it being spread out among all LRT holders.
Impact
If a deficit is accumulated the first cohort to settle will pay for the entire amount. If they can not cover it fully, they will receive 0 and the following cohort will pay for the rest.
Code Snippet
Tool used
Manual Review
Recommendation
A potential solution to deal with this is to check if a deficit exists in settleEpochFromEigenLayer(). If it exists functionality has to be added that spreads the cost of the penalty fairly among all LRT holders.
Discussion
nevillehuang
request poc
sherlock-admin3
PoC requested from @0xmonrel
Requests remaining: 16
0xmonrel
For this POC to run we need to first fix the epoch increment issue. Done by adding currentEpochsByAsset[asset] += 1; to queueCurrentEpcohSettlement().
POC
This shows that users in the first withdrawal pay for 100% of the penalty if we have a deficit due to slashing
Course of events
- Deposit such that we have 2 validators
- Request withdrawal 8 ETH and rebalance for epoch 0
- Request withdrawal 31.99 ETH and rebalance for epoch 1
- Slashing during withdrawal period such that we have a -8 ETH deficit in the EigenpodManager
- VerifyAndProcess both withdrawals
- Settle and claim epoch 0, we get 0 ETH since penalty is paid for 100% by these users.
- Settle and claim epoch 1, we get 31.99 ETH since 0% of penalty is paid for.
- Users in epoch 1 has stolen 4 ETH from users in epoch 0.
Create a new file RioLRTDeficit.t.sol in the test folder and paste the code below. Run with forge test --match-test test_deficitPenaltyTrue -vvv
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.23;
import {BEACON_CHAIN_STRATEGY, ETH_ADDRESS, ETH_DEPOSIT_SIZE, GWEI_TO_WEI} from 'contracts/utils/Constants.sol';
import {IDelegationManager} from 'contracts/interfaces/eigenlayer/IDelegationManager.sol';
import {IRioLRTWithdrawalQueue} from 'contracts/interfaces/IRioLRTWithdrawalQueue.sol';
import {RioDeployer} from 'test/utils/RioDeployer.sol';
import {Asset} from 'contracts/utils/Asset.sol';
import {Array} from 'contracts/utils/Array.sol';
import {IRioLRTOperatorRegistry} from 'contracts/interfaces/IRioLRTOperatorRegistry.sol';
import {RioLRTOperatorDelegator} from 'contracts/restaking/RioLRTOperatorDelegator.sol';
import {CredentialsProofs, BeaconWithdrawal} from 'test/utils/beacon-chain/MockBeaconChain.sol';
import "forge-std/console2.sol";
import {IEigenPodManager} from 'contracts/interfaces/eigenlayer/IEigenPodManager.sol';
import {stdStorage, StdStorage} from "forge-std/Test.sol";
contract RioLRTDeficit is RioDeployer {
using stdStorage for StdStorage;
using Asset for *;
using Array for *;
TestLRTDeployment public reETH;
TestLRTDeployment public reLST;
IRioLRTOperatorRegistry.StrategyShareCap[] public emptyStrategyShareCaps;
function setUp() public {
deployRio();
(reETH,) = issueRestakedETH();
(reLST,) = issueRestakedLST();
}
function test_deficitPenaltyTrue() public{
uint8[] memory operatorIds = addOperatorDelegators( //add 2 validators to 1 operator
reETH.operatorRegistry,
address(reETH.rewardDistributor),
1,
emptyStrategyShareCaps,
2
);
uint256 depositAmount = 2*ETH_DEPOSIT_SIZE - address(reETH.depositPool).balance;
reETH.coordinator.depositETH{value: depositAmount}();
vm.prank(EOA, EOA);
reETH.coordinator.rebalance(ETH_ADDRESS); // Rebalance to stake 2 validators
uint40[] memory validatorIndices = verifyCredentialsForValidators(reETH.operatorRegistry, 1, 2);
address delegator = reETH.operatorRegistry.getOperatorDetails(operatorIds[0]).delegator;
int256 shares = RioLRTOperatorDelegator(payable(delegator)).getEigenPodShares();
console2.log("Total shares after deposit:",shares);
require(shares == 64 ether);
//----- First withdrawal
uint256 withdrawalAmount = 8 ether;
reETH.coordinator.requestWithdrawal(ETH_ADDRESS, withdrawalAmount);
uint256 firstEpoch = reETH.withdrawalQueue.getCurrentEpoch(ETH_ADDRESS);
skip(reETH.coordinator.rebalanceDelay());
vm.prank(EOA, EOA);
reETH.coordinator.rebalance(ETH_ADDRESS);
//----- Second Withdrawal
uint256 withdrawalAmount2 = 31.99 ether;
reETH.coordinator.requestWithdrawal(ETH_ADDRESS, withdrawalAmount2);
uint256 secondEpoch = reETH.withdrawalQueue.getCurrentEpoch(ETH_ADDRESS);
skip(reETH.coordinator.rebalanceDelay());
vm.prank(EOA, EOA);
reETH.coordinator.rebalance(ETH_ADDRESS);
// ------ SIMULATE SLASHING
// EigenLayer accounts for slashing during withdrawl period by decreasing shares.
// if shares < 0, these shares will be adjusted for in the next withdrawal.
/** We simulate slashing by directly setting the podownerShars[delegator] = slashedAmount
this is equivalent to calling recordBeaconChainETHBalanceUpdate to decrease the balance
due to slashing.
*/
IEigenPodManager manager = IEigenPodManager(EIGEN_POD_MANAGER_ADDRESS);
stdstore.target(EIGEN_POD_MANAGER_ADDRESS).sig("podOwnerShares(address)").with_key(delegator).checked_write_int(int256(-8 ether));
int256 loadInt = stdstore.target(EIGEN_POD_MANAGER_ADDRESS).sig("podOwnerShares(address)").with_key(delegator).read_int();
console2.log("Slashing 8 Ether during withdrawal process, deficit in shares:", loadInt);
// verify both
verifyAndProcessWithdrawalsForValidatorIndexes(delegator, validatorIndices);
// First withdrawal will pay for entire slashing amount
{
IDelegationManager.Withdrawal[] memory withdrawals = new IDelegationManager.Withdrawal[](1);
withdrawals[0] = IDelegationManager.Withdrawal({
staker: delegator,
delegatedTo: address(1),
withdrawer: address(reETH.withdrawalQueue),
nonce: 0,
startBlock: 1,
strategies: BEACON_CHAIN_STRATEGY.toArray(),
shares: withdrawalAmount.toArray()
});
reETH.withdrawalQueue.settleEpochFromEigenLayer(ETH_ADDRESS, 0, withdrawals, new uint256[](1));
uint256 amountOut = reETH.withdrawalQueue.claimWithdrawalsForEpoch(
IRioLRTWithdrawalQueue.ClaimRequest({asset: ETH_ADDRESS, epoch: 0})
);
console2.log("First Withdrawal:", amountOut); // Users in this cohort pay for 100% of slashing
}
IDelegationManager.Withdrawal[] memory withdrawals2 = new IDelegationManager.Withdrawal[](1);
withdrawals2[0] = IDelegationManager.Withdrawal({
staker: delegator,
delegatedTo: address(1),
withdrawer: address(reETH.withdrawalQueue),
nonce: 1,
startBlock: 1,
strategies: BEACON_CHAIN_STRATEGY.toArray(),
shares: withdrawalAmount2.toArray()
});
reETH.withdrawalQueue.settleEpochFromEigenLayer(ETH_ADDRESS, 1, withdrawals2, new uint256[](1));
uint256 amountOut2 = reETH.withdrawalQueue.claimWithdrawalsForEpoch(
IRioLRTWithdrawalQueue.ClaimRequest({asset: ETH_ADDRESS, epoch: 1})
);
console2.log("Second Withdrawal:", amountOut2); // Users in this cohort pay 0% of slashing
console2.log("Users in first withdrawal paid for 100% of penalty");
}
receive() external payable {}
}
Results
Logs:
Total shares after deposit: 64000000000000000000
Slashing 8 Ether during withdrawal process, deficit in shares: -8000000000000000000
First Withdrawal: 0
Second Withdrawal: 31990000000000000000
Users in first withdrawal paid for 100% of penalty
nevillehuang
@solimander Might want to consider the above PoC
solimander
Reviewing
KupiaSecAdmin
Escalate
This has to be considered as Invalid/Low basically because EigenLayer's Slashing contracts do not have any features and all paused, it also won't have any features in its upgrades as well, which means no slashing exists.
sherlock-admin2
Escalate
This has to be considered as Invalid/Low basically because EigenLayer's Slashing contracts do not have any features and all paused, it also won't have any features in its upgrades as well, which means no slashing exists.
You've created a valid escalation!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
0xmonrel
You are misunderstanding the issue. This is about consensus layer slashing.
nevillehuang
@KupiaSecAdmin Could you link resources/proof to your argument so I can review?
KupiaSecAdmin
@nevillehuang - https://hackmd.io/@-HV50kYcRqOjl_7du8m1AA/BkOyFwc2T#Out-of-Scope Here's the docs about upgrades of EigenLayer, which Rio is targeting, hope it helps.
@0xmonrel - If you were meant to say about Ethereum's PoS slashing, as I described here, it should be considered as Low.
0xmonrel
The arguments does not apply here. The effect on TVL are irrelevant what matters in this issue is that only 1 cohort of users will pay for the slashing if a deficit happens.
nevillehuang
@solimander Based on targeted eigen layer contracts it seems it is correct that slashing is currently not applicable to Rio. It is also not stated in the contest details that this will be integrated to rio, so I believe this is invalid based on the following sherlock guideline:
Future issues: Issues that result out of a future integration/implementation that was not mentioned in the docs/README or because of a future change in the code (as a fix to another issue) are not valid issues.
0xmonrel
POS slashing is already live and integrated. Slashing from re-staking is not so it is not out of scope.
nevillehuang
@0xmonrel Could you point me to the correct resource. This will affect validity of #190 as well
0xmonrel
Slashing is implemented natively through the balance update process. When a validator is slashed the balance is decreased, this is then pushed to EigenLayer through verifyBalanceUpdates().
Here is the logic where slashing is accounted for and a deficit can happen:
Look here at the verifyBalanceUpdates()
Read the comment for a description of what happens when a balance is decreased.
@solimander can most likely verify that this is correct as he has deep understanding of EigenLayer.
solimander
That's right, you can find more info on the deficit edge case in the EigenLayer discord:
nevillehuang
Thanks alot guys, I believe this issue is correctly judged given the constraint of a deficit edge case.
Czar102
I'm planning to reject the escalation and leave the issue as is, unless @KupiaSecAdmin or anyone else has a valid argument not to.
Czar102
Result: Medium Unique
sherlock-admin3
Escalations have been resolved successfully!
Escalation status:
- KupiaSecAdmin: rejected
solimander
This is definitely an edge case of an edge case. First, slashing needs to occur while the withdrawal is queued. Second, the operator delegator's pod owner shares needs to be low enough that a deficit is possible. For this reason, considering leaving as-is for now and handling this out-of-protocol.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the settlement logic calculates assets received as the difference in balance before and after completing queued withdrawals, so any pre-existing deficit reduces the first cohort's payout instead of being spread across all holders.
Impact
If a deficit is accumulated, the first cohort to settle pays the entire amount and may receive zero, with the following cohort paying any remainder; the report notes this is an edge case requiring slashing during a queued withdrawal and low pod owner shares.
What the attacker needed
Slashing occurs during a queued withdrawal; pod owner shares low enough for a deficit; withdrawal queued and settled
The fix
The report recommends checking for a deficit in settleEpochFromEigenLayer() and adding functionality to spread the penalty fairly among all LRT holders; the protocol acknowledged the issue but considered leaving it as-is for now.
How it was found
- Deposit ETH so that two validators are active.
- Request a withdrawal of 8 ETH and rebalance for epoch 0.
- Request a withdrawal of 31.99 ETH and rebalance for epoch 1.
- Simulate slashing during the withdrawal period to create a deficit of 8 ETH in the EigenPodManager.
- Verify and process both withdrawals.
- Settle and claim epoch 0, which returns 0 ETH because the first cohort pays the entire penalty.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When people withdraw their staked ETH, they are grouped into batches (cohorts). If some validators get slashed (penalised) while a withdrawal is pending, the protocol ends up with a shortfall. The bug is that the first batch to finish the withdrawal absorbs the whole shortfall, so those users can lose all their withdrawal, while later batches lose nothing.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.