Skip to content
DoS Audit finding Intermediate

SingleSidedLiquidityVault._accumulateInternalRewards will revert with underflow error if rewardToken.lastRewardTime is bigger than current time

A reward-accumulation function subtracts a stored last-reward timestamp from the current block time without checking which is larger. If an admin adds a reward token with a future start time, that subtraction underflows and every function relying on it reverts, blocking the vault until the token is removed.

joestakey Follow with cccz, mahdikarimi and 7 others

Originally disclosed on Sherlock

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

Found by

joestakey, cccz, mahdikarimi, xAlismx, hansfriese, GimelSec, cducrest-brainbot, 0x52, Ruhum, rvierdiiev

Summary

SingleSidedLiquidityVault._accumulateInternalRewards will revert with underflow error if rewardToken.lastRewardTime is bigger than current time

Vulnerability Detail

Function _accumulateInternalRewards is used by almost all external function of SingleSidedLiquidityVault. https://github.com/sherlock-audit/2023-02-olympus/blob/main/src/policies/lending/abstracts/SingleSidedLiquidityVault.sol#L463-L484

Solidity
    function _accumulateInternalRewards() internal view returns (uint256[] memory) {
        uint256 numInternalRewardTokens = internalRewardTokens.length;
        uint256[] memory accumulatedInternalRewards = new uint256[](numInternalRewardTokens);


        for (uint256 i; i < numInternalRewardTokens; ) {
            InternalRewardToken memory rewardToken = internalRewardTokens[i];


            uint256 totalRewards;
            if (totalLP > 0) {
                uint256 timeDiff = block.timestamp - rewardToken.lastRewardTime;
                totalRewards = (timeDiff * rewardToken.rewardsPerSecond);
            }


            accumulatedInternalRewards[i] = totalRewards;


            unchecked {
                ++i;
            }
        }


        return accumulatedInternalRewards;
    }

The line is needed to see is this uint256 timeDiff = block.timestamp - rewardToken.lastRewardTime. In case if rewardToken.lastRewardTime > block.timestamp than function will revert and ddos functions that use it.

This is how this can happen. https://github.com/sherlock-audit/2023-02-olympus/blob/main/src/policies/lending/abstracts/SingleSidedLiquidityVault.sol#L674-L688

Solidity
    function addInternalRewardToken(
        address token_,
        uint256 rewardsPerSecond_,
        uint256 startTimestamp_
    ) external onlyRole("liquidityvault_admin") {
        InternalRewardToken memory newInternalRewardToken = InternalRewardToken({
            token: token_,
            decimalsAdjustment: 10**ERC20(token_).decimals(),
            rewardsPerSecond: rewardsPerSecond_,
            lastRewardTime: block.timestamp > startTimestamp_ ? block.timestamp : startTimestamp_,
            accumulatedRewardsPerShare: 0
        });


        internalRewardTokens.push(newInternalRewardToken);
    }

In case if startTimestamp_ is in the future, then it will be set and cause that problem. lastRewardTime: block.timestamp > startTimestamp_ ? block.timestamp : startTimestamp_.

Now till, startTimestamp_ time, _accumulateInternalRewards will not work, so vault will be stopped. And of course, admin can remove that token and everything will be fine. That's why i think this is medium.

Impact

SingleSidedLiquidityVault will be blocked

Code Snippet

Provided above.

Tool used

Manual Review

Recommendation

Skip token if it's lastRewardTime is in future.

The original report as published on Sherlock, by joestakey. 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 code assumes the stored last-reward time is never later than the current block time, so it performs an unchecked subtraction that underflows when a token is registered with a future start timestamp.

Impact

The vault's reward-dependent functions revert, blocking the vault until the future start time arrives or the admin removes the token, so the reporter rates it medium.

What the attacker needed

Admin adds token with future start time

The fix

The accumulation loop should skip any reward token whose last-reward time is still in the future.

How it was found

  1. An admin adds an internal reward token whose start timestamp lies in the future.
  2. The token is stored with its last-reward time set to that future timestamp.
  3. Any vault function that accumulates rewards then subtracts the future time from the current time.
  4. The subtraction underflows and the call reverts until the start time passes or the token is removed.

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.

A smart contract keeps track of when rewards were last counted and works out how much time has passed by subtracting that moment from the current time. If the stored moment is in the future, the subtraction goes below zero, which this language treats as an error, so the whole call fails. Because many actions in the vault call this same routine, the vault effectively stops working.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by joestakey

View all

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

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.