Skip to content
Business logic Audit finding Intermediate

SingleSidedLiquidityVault.withdraw will decreases ohmMinted, which will make the calculation involving ohmMinted incorrect

The withdraw function in SingleSidedLiquidityVault incorrectly decreases ohmMinted instead of only increasing ohmRemoved, causing accounting errors in deposit limit checks and emission calculations. An attacker could exploit this to bypass deposit limits or misreport OHM emissions.

joestakey Follow with cccz, psy4n0n and 5 others

Originally disclosed on Sherlock

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

Found by

joestakey, cccz, psy4n0n, Bobface, jonatascm, immeas, favelanky, rvierdiiev

Summary

SingleSidedLiquidityVault.withdraw will decreases ohmMinted, which will make the calculation involving ohmMinted incorrect.

Vulnerability Detail

In SingleSidedLiquidityVault, ohmMinted indicates the number of ohm minted in the contract, and ohmRemoved indicates the number of ohm burned in the contract. So the contract just needs to increase ohmMinted in deposit() and increase ohmRemoved in withdraw(). But withdraw() decreases ohmMinted, which makes the calculation involving ohmMinted incorrect.

Solidity
        ohmMinted -= ohmReceived > ohmMinted ? ohmMinted : ohmReceived;
        ohmRemoved += ohmReceived > ohmMinted ? ohmReceived - ohmMinted : 0;

Consider that a user minted 100 ohm in deposit() and immediately burned 100 ohm in withdraw().

In _canDeposit, the amount_ is less than LIMIT + 1000 instead of LIMIT

Solidity
    function _canDeposit(uint256 amount_) internal view virtual returns (bool) {
        if (amount_ + ohmMinted > LIMIT + ohmRemoved) revert LiquidityVault_LimitViolation();
        return true;
    }

getOhmEmissions() returns 1000 instead of 0

Solidity
    function getOhmEmissions() external view returns (uint256 emitted, uint256 removed) {
        uint256 currentPoolOhmShare = _getPoolOhmShare();

        if (ohmMinted > currentPoolOhmShare + ohmRemoved)
            emitted = ohmMinted - currentPoolOhmShare - ohmRemoved;
        else removed = currentPoolOhmShare + ohmRemoved - ohmMinted;
    }

Impact

It will make the calculation involving ohmMinted incorrect.

Code Snippet

https://github.com/sherlock-audit/2023-02-olympus/blob/main/src/policies/lending/abstracts/SingleSidedLiquidityVault.sol#L276-L277 https://github.com/sherlock-audit/2023-02-olympus/blob/main/src/policies/lending/abstracts/SingleSidedLiquidityVault.sol#L392-L409

Tool used

Manual Review

Recommendation

Diff
    function withdraw(
        uint256 lpAmount_,
        uint256[] calldata minTokenAmounts_,
        bool claim_
    ) external onlyWhileActive nonReentrant returns (uint256) {
        // Liquidity vaults should always be built around a two token pool so we can assume
        // the array will always have two elements
        if (lpAmount_ == 0 || minTokenAmounts_[0] == 0 || minTokenAmounts_[1] == 0)
            revert LiquidityVault_InvalidParams();
        if (!_isPoolSafe()) revert LiquidityVault_PoolImbalanced();

        _withdrawUpdateRewardState(lpAmount_, claim_);

        totalLP -= lpAmount_;
        lpPositions[msg.sender] -= lpAmount_;

        // Withdraw OHM and pairToken from LP
        (uint256 ohmReceived, uint256 pairTokenReceived) = _withdraw(lpAmount_, minTokenAmounts_);

        // Reduce deposit values
        uint256 userDeposit = pairTokenDeposits[msg.sender];
        pairTokenDeposits[msg.sender] -= pairTokenReceived > userDeposit
            ? userDeposit
            : pairTokenReceived;
-       ohmMinted -= ohmReceived > ohmMinted ? ohmMinted : ohmReceived;
        ohmRemoved += ohmReceived > ohmMinted ? ohmReceived - ohmMinted : 0;

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

The withdraw function subtracts from ohmMinted instead of only adding to ohmRemoved, leading to incorrect state tracking.

Impact

The incorrect accounting could allow users to bypass deposit limits and cause misreporting of OHM emissions.

What the attacker needed

A user with deposit and withdraw capability

How it was found

  1. A user deposits and mints 100 OHM, increasing ohmMinted.
  2. The same user immediately withdraws and burns 100 OHM.
  3. The withdraw function decreases ohmMinted instead of increasing ohmRemoved.
  4. The deposit limit check now allows more than the intended limit because ohmMinted is lower.
  5. The emission calculation returns an incorrect value (e.g., 1000 instead of 0).

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.

This smart contract tracks how much of a token (OHM) has been minted and burned. When a user withdraws, the contract should record that some OHM was burned, but instead it reduces the 'minted' count, which messes up later checks and reports. This could let someone deposit more than allowed or make the system report wrong emission numbers.

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

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.