Skip to content
Business logic Audit finding Intermediate

User can earn rewards by frontrunning the new rewards accumulation in Ron staking without actually delegating his tokens

A user could deposit tokens into LiquidRon just before a rewards epoch update and then withdraw immediately after, capturing a share of rewards without actually delegating tokens or bearing risk. This was possible because new deposits were not subject to any lock-up or time restriction, unlike direct delegation to Ron staking.

Aamir Follow with 0rpse, 0x0dd and 5 others

Originally disclosed on Code4rena

Submitted by Aamir, also found by 0rpse, 0x0dd, 0xrex, gesha17, ilchovski, KupiaSec, and spuriousdragon

LiquidProxy.sol#L39

Finding Description and Impact

The Ron staking contract let us earn rewards by delegating our tokens to a validator. But you will only earn rewards on the lowest balance of the day (source). So if you delegate your tokens on the first day, you are going to earn 0 rewards for that day as your lowest balance was 0 on that day. This will happens with every new delegator.

Now the issue with LiquidRon is that, there will be many users who will be depositing their tokens in it. And there is no such kind of time or amount restriction for new delegators if some people have already delegated before them. So with direct delegation, the new rewards flow will be this:

User -> delegate -> RonStaking -> Wait atleast a day -> New Rewards

But if we deposit through LiquidRon it has become this:

User -> LiquidRon -> LiquidProxy -> New Rewards

Now a user can earn rewards by just depositing the tokens into the LiquidRon by frontrunning the new rewards arrival and immediately withdraw them. But if a user try to do this by frontrunning the LiquidRon::harvest(...) call, this will not be possible. Because when he deposits, he will get shares in return which will already be accounting for any unclaimed rewards through getTotalRewards(...) in LiqiuidRon::totalAssets(...):

    function totalAssets() public view override returns (uint256) {
@>        return super.totalAssets() + getTotalStaked() + getTotalRewards();
    }

But instead of frontrunning this harvest(...) call, a user can just frontrun the new rewards arrival in the RonStaking contract itself. Because as per the Ronin staking docs, a user will be able to claim new rewards after every 24 hours.

Also, if we look at the _getReward(...) (used by claimRewards etc.) function of the Ronin staking contract, the rewards will be same as before as long as we are not in new period:

  function _getReward(
    address poolId,
    address user,
    uint256 latestPeriod,
    uint256 latestStakingAmount
  ) internal view returns (uint256) {
    UserRewardFields storage _reward = _userReward[poolId][user];

@>    if (_reward.lastPeriod == latestPeriod) {
@>      return _reward.debited;
    }

Github: Link

So if a user frontrun before this, the getTotalRewards(...) function will also not account for new rewards as long as we are not in new period.

Also note that, if a user frontruns and deposit, he didn’t not actually delegated his tokens as the tokens are only delegated once the operator calls LiquidRon::delegateAmount(...) function:

    function delegateAmount(uint256 _proxyIndex, uint256[] calldata _amounts, address[] calldata _consensusAddrs)
        external
        onlyOperator
        whenNotPaused
    {
        address stakingProxy = stakingProxies[_proxyIndex];
        uint256 total;

        if (stakingProxy == address(0)) revert ErrBadProxy();
        // @audit how many max validators can be there?
        for (uint256 i = 0; i < _amounts.length; i++) {
            if (_amounts[i] == 0) revert ErrNotZero();
            _tryPushValidator(_consensusAddrs[i]);
            total += _amounts[i];
        }
@>        _withdrawRONTo(stakingProxy, total);
@>        ILiquidProxy(stakingProxy).delegateAmount(_amounts, _consensusAddrs);
    }

So a user is just depositing, claiming and withdrawing his tokens but not actually delegating.

The following attack can be summarized like this:

  1. There are currently millions of delegated tokens deposited into the LiquidRon which are delegated to many validators through LiquidProxy. And each day the LiquidRon is earning let’s 1000 tokens as a reward.
  2. But these rewards are only claimable in the new epoch.
  3. So a user keeps an eye on the new rewards arrival into the RonStaking for the LiquidRon and also on the new epoch update.
  4. Once rewards are arrived he waits for the epoch update, and frontruns this epoch update and deposits into the LiquidRon.
  5. Once this new epoch is updated, these new rewards will be starting to reflect into the the share price through LiquidRon::totalAssets(...).
  6. User withdraws immediately with the profit.

In the above case, the user didn’t have to stake his tokens and still earns the share of the rewards. Also, this can be done each and every time to claim the rewards.

He also didn’t have to bear any risk of loss in case something bad happens (maybe some kind of attack) and the share price value goes down; while others will also have to bear this loss.

Recommended Mitigation Steps

Incorporate some kind of locking mechanism for new depositor like Ron staking contract does. Or, go for some alternate option.

Owl (Liquid Ron) confirmed and commented:

Vampire attack as I like to call it.

Valid finding, definitely need to think of a viable mitigation solution. For now, adding a deposit fee seems the best solution I have found (deposit fee would be equivalent to 1 day worth of reward expected based on amount deposited).

0xsomeone (judge) commented:

The finding and its duplicates outline a valid attack path via which users are able to arbitrage upcoming reward updates to capture the rewards without actually staking their assets for a long period of time in the system.

I believe a medium-severity rating is justifiable, and mitigation for the vulnerability outlined will be hard to implement properly unless a simplistic measure such as a deposit fee is implemented. Alternatives would be to finalize deposits via operators or permit deposits to occur within a predefined time window of a reward issuance, ensuring new deposits are finalized after a reward update has occurred recently.

Liquid Ron mitigated:

Add a deposit fee that can be reset every period based on daily expected rewards.

Status: Mitigation confirmed. Full details in report from Aamir.


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

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 absence of a lock-up or time-based restriction on new deposits, allowing users to enter just before a rewards update and exit immediately after to capture a share of rewards without staking for a meaningful period.

Impact

A user could earn a share of rewards without actually delegating tokens or bearing any risk of loss, and could repeat this each reward period.

What the attacker needed

Ability to frontrun transactions; LiquidRon has existing delegated tokens earning rewards; no lock-up or deposit fee on new deposits

The fix

A deposit fee equivalent to one day's expected rewards was added and can be reset each period; the mitigation was confirmed.

How it was found

  1. Monitor the Ron staking contract for new rewards arrival and the upcoming epoch update.
  2. Frontrun the epoch update by depositing tokens into LiquidRon.
  3. After the epoch update, the new rewards are reflected in the share price via totalAssets.
  4. Withdraw immediately to realise a profit from the rewards share.

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.

In many staking systems, rewards are paid based on how long your tokens have been staked. Here, a person could put tokens in just before rewards were added and take them out right after, getting a cut of rewards meant for long-term stakers. This is like joining a lottery just before the draw and then leaving immediately after collecting a prize.

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 Aamir

View all

2 more disclosed reports, best first.

More from Liquid Ron

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.