Skip to content
Business logic Audit finding Intermediate

claimFees may cause some external rewards to be locked in the contract

The claimFees function updates the lastBalance of external reward tokens to the current contract balance without first accruing pending rewards, so any unaccrued rewards become permanently unclaimable by users. An attacker could front-run the admin's claimFees call by triggering getReward to inflate the contract's reward token balance, causing those rewards to be locked.

cccz Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-02-olympus-judging/issues/100

Found by

cccz

Summary

claimFees will update rewardToken.lastBalance so that if there are unaccrued reward tokens in the contract, users will not be able to claim them.

Vulnerability Detail

_accumulateExternalRewards takes the difference between the contract's reward token balance and lastBalance as the reward. and the accumulated reward tokens are updated by _updateExternalRewardState.

Solidity
    function _accumulateExternalRewards() internal override returns (uint256[] memory) {
        uint256 numExternalRewards = externalRewardTokens.length;

        auraPool.rewardsPool.getReward(address(this), true);

        uint256[] memory rewards = new uint256[](numExternalRewards);
        for (uint256 i; i < numExternalRewards; ) {
            ExternalRewardToken storage rewardToken = externalRewardTokens[i];
            uint256 newBalance = ERC20(rewardToken.token).balanceOf(address(this));

            // This shouldn't happen but adding a sanity check in case
            if (newBalance < rewardToken.lastBalance) {
                emit LiquidityVault_ExternalAccumulationError(rewardToken.token);
                continue;
            }

            rewards[i] = newBalance - rewardToken.lastBalance;
            rewardToken.lastBalance = newBalance;

            unchecked {
                ++i;
            }
        }
        return rewards;
    }
...
    function _updateExternalRewardState(uint256 id_, uint256 amountAccumulated_) internal {
        // This correctly uses 1e18 because the LP tokens of all major DEXs have 18 decimals
        if (totalLP != 0)
            externalRewardTokens[id_].accumulatedRewardsPerShare +=
                (amountAccumulated_ * 1e18) /
                totalLP;
    }

auraPool.rewardsPool.getReward can be called by anyone to send the reward tokens to the contract

Solidity
    function getReward(address _account, bool _claimExtras) public updateReward(_account) returns(bool){
        uint256 reward = earned(_account);
        if (reward > 0) {
            rewards[_account] = 0;
            rewardToken.safeTransfer(_account, reward);
            IDeposit(operator).rewardClaimed(pid, _account, reward);
            emit RewardPaid(_account, reward);
        }

        //also get rewards from linked rewards
        if(_claimExtras){
            for(uint i=0; i < extraRewards.length; i++){
                IRewards(extraRewards[i]).getReward(_account);
            }
        }
        return true;
    }

However, in claimFees, the rewardToken.lastBalance will be updated to the current contract balance after the admin has claimed the fees.

Solidity
    function claimFees() external onlyRole("liquidityvault_admin") {
        uint256 numInternalRewardTokens = internalRewardTokens.length;
        uint256 numExternalRewardTokens = externalRewardTokens.length;

        for (uint256 i; i < numInternalRewardTokens; ) {
            address rewardToken = internalRewardTokens[i].token;
            uint256 feeToSend = accumulatedFees[rewardToken];

            accumulatedFees[rewardToken] = 0;

            ERC20(rewardToken).safeTransfer(msg.sender, feeToSend);

            unchecked {
                ++i;
            }
        }

        for (uint256 i; i < numExternalRewardTokens; ) {
            ExternalRewardToken storage rewardToken = externalRewardTokens[i];
            uint256 feeToSend = accumulatedFees[rewardToken.token];

            accumulatedFees[rewardToken.token] = 0;

            ERC20(rewardToken.token).safeTransfer(msg.sender, feeToSend);
            rewardToken.lastBalance = ERC20(rewardToken.token).balanceOf(address(this));

            unchecked {
                ++i;
            }
        }
    }

Consider the following scenario.

  1. Start with rewardToken.lastBalance = 200.
  2. After some time, the rewardToken in aura is increased by 100.
  3. Someone calls getReward to claim the reward tokens to the contract, and the 100 reward tokens increased have not yet been accumulated via _accumulateExternalRewards and _updateExternalRewardState.
  4. The admin calls claimFees to update rewardToken.lastBalance to 290(10 as fees).
  5. Users call claimRewards and receives 0 reward tokens. 90 reward tokens will be locked in the contract

Impact

It will cause some external rewards to be locked in the contract

Code Snippet

https://github.com/sherlock-audit/2023-02-olympus/blob/main/src/policies/lending/WstethLiquidityVault.sol#L192-L216 https://github.com/sherlock-audit/2023-02-olympus/blob/main/src/policies/lending/abstracts/SingleSidedLiquidityVault.sol#L496-L503 https://github.com/sherlock-audit/2023-02-olympus/blob/main/src/policies/lending/abstracts/SingleSidedLiquidityVault.sol#L736-L766

Tool used

Manual Review

Recommendation

Use _accumulateExternalRewards and _updateExternalRewardState in claimFees to accrue rewards.

Diff
    function claimFees() external onlyRole("liquidityvault_admin") {
        uint256 numInternalRewardTokens = internalRewardTokens.length;
        uint256 numExternalRewardTokens = externalRewardTokens.length;

        for (uint256 i; i < numInternalRewardTokens; ) {
            address rewardToken = internalRewardTokens[i].token;
            uint256 feeToSend = accumulatedFees[rewardToken];

            accumulatedFees[rewardToken] = 0;

            ERC20(rewardToken).safeTransfer(msg.sender, feeToSend);

            unchecked {
                ++i;
            }
        }
+       uint256[] memory accumulatedExternalRewards = _accumulateExternalRewards();
        for (uint256 i; i < numExternalRewardTokens; ) {
+           _updateExternalRewardState(i, accumulatedExternalRewards[i]);
            ExternalRewardToken storage rewardToken = externalRewardTokens[i];
            uint256 feeToSend = accumulatedFees[rewardToken.token];

            accumulatedFees[rewardToken.token] = 0;

            ERC20(rewardToken.token).safeTransfer(msg.sender, feeToSend);
            rewardToken.lastBalance = ERC20(rewardToken.token).balanceOf(address(this));

            unchecked {
                ++i;
            }
        }
    }

Discussion

IAm0x52

Escalate for 25 USDC.

This should be medium for two reasons:

  1. Funds aren't actually lost because they can be rescued
  2. This is an admin only function so unless admin was malicious and called this repeatedly the amount of locked tokens would be small

sherlock-admin

Escalate for 25 USDC.

This should be medium for two reasons:

  1. Funds aren't actually lost because they can be rescued
  2. This is an admin only function so unless admin was malicious and called this repeatedly the amount of locked tokens would be small

You've created a valid escalation for 25 USDC!

To remove the escalation from consideration: Delete your comment. To change the amount you've staked on this escalation: Edit your comment (do not create a new comment).

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

thereksfour

Escalate for 25 USDC. Disagree with @IAm0x52 's comments

1.Funds aren't actually lost because they can be rescued

For users, they have lost the rewards they deserve, and even though they can get a refund afterwards, the reputation of the protocol has been compromised.

2.This is an admin only function so unless admin was malicious and called this repeatedly the amount of locked tokens would be small.

Using minimum impact to downgrade the issue here doesn't hold water. I could say that a large number of rewards are left in aura due to a long period of no user activity, and when a malicious user observes the owner calling claimFees, he can preempt the call to getReward to make a large number of rewards locked in the contract

sherlock-admin

Escalate for 25 USDC. Disagree with @IAm0x52 's comments

1.Funds aren't actually lost because they can be rescued

For users, they have lost the rewards they deserve, and even though they can get a refund afterwards, the reputation of the protocol has been compromised.

2.This is an admin only function so unless admin was malicious and called this repeatedly the amount of locked tokens would be small.

Using minimum impact to downgrade the issue here doesn't hold water. I could say that a large number of rewards are left in aura due to a long period of no user activity, and when a malicious user observes the owner calling claimFees, he can preempt the call to getReward to make a large number of rewards locked in the contract

You've created a valid escalation for 25 USDC!

To remove the escalation from consideration: Delete your comment. To change the amount you've staked on this escalation: Edit your comment (do not create a new comment).

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

hrishibhat

Escalation accepted

This is a valid medium There are multiple reasons why this issue should be medium, While there is still a dos attack possible, funds are not lost. And can be recovered by admin. Also, the claimFees is an admin function. This does not break the core functionality but a DOS of rewards. Hence medium is fair

sherlock-admin

Escalation accepted

This is a valid medium There are multiple reasons why this issue should be medium, While there is still a dos attack possible, funds are not lost. And can be recovered by admin. Also, the claimFees is an admin function.

This issue's escalations have been accepted!

Contestants' payouts and scores will be updated according to the changes made on this issue.

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

Root cause

Likely the claimFees function updates rewardToken.lastBalance without first calling _accumulateExternalRewards and _updateExternalRewardState to account for unaccrued rewards.

Impact

Some external rewards could be locked in the contract, causing users to lose the rewards they deserve; the funds are not permanently lost and can be recovered by the admin, and the issue requires the admin to call claimFees.

What the attacker needed

Admin calls claimFees; unaccrued rewards in contract; attacker can front-run getReward

The fix

The claimFees function should call _accumulateExternalRewards and _updateExternalRewardState to accrue rewards before updating lastBalance.

How it was found

  1. Start with rewardToken.lastBalance = 200.
  2. After some time, the rewardToken in aura is increased by 100.
  3. Someone calls getReward to claim the reward tokens to the contract, and the 100 reward tokens increased have not yet been accumulated via _accumulateExternalRewards and _updateExternalRewardState.
  4. The admin calls claimFees to update rewardToken.lastBalance to 290(10 as fees).
  5. Users call claimRewards and receives 0 reward tokens. 90 reward tokens will be locked in the contract

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 this smart contract, users earn rewards that are tracked by comparing the contract's current token balance to a stored 'lastBalance'. When the admin calls claimFees, it resets lastBalance to the current balance without first recording any new rewards that arrived. As a result, those new rewards are never counted and users cannot claim them. An attacker can make this worse by causing rewards to arrive just before the admin's call.

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 cccz

View all

104 more disclosed reports, best first.

More from Olympus RBS 2.0

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.