Skip to content
Business logic Audit finding Intermediate

Withdrawals can be frozen by creating null deposits

A deposit with zero liquidity is accepted and stored as a valid position, but the withdrawal function treats any position with zero liquidity as non-existent and reverts. An attacker can create such a null deposit, causing all subsequent withdrawals to fail and freezing funds.

erebus Follow with hash and BugzyVonBuggernaut

Originally disclosed on Code4rena

Submitted by erebus, also found by hash and BugzyVonBuggernaut

It won’t be possible to withdraw any LP token after doing a deposit of $0$ liquidity, leading to withdrawals being effectively freezed.

Proof of Concept

In liquidity_lockbox, function withdraw

        ...

        uint64 positionLiquidity = mapPositionAccountLiquidity[positionAddress];
        // Check that the token account exists
        if (positionLiquidity == 0) {
            revert("No liquidity on a provided token account");
        }

        ...

The code checks for the existence of a position via the recorded liquidity. This is a clever idea, as querying a non-existant value from a mapping will return $0$. However, in deposit, due to a flawed input validation, it is possible to make positions with $0$ liquidity as the only check being done is for liquidity to not be higher than type(uint64).max:

liquidity*lockbox, function *getPositionData

        ...

        // Check that the liquidity is within uint64 bounds
        if (positionData.liquidity > type(uint64).max) {
            revert("Liquidity overflow");
        }

        ...

As it will pass the input validation inside _getPositionData, the only way for such a tx to revert is in the transfer/mint, which are low-level calls with no checks for success, as stated in my report Missing checks for failed calls to the token program will corrupt user's positions.

Due to the reasons above, this deposit with $0$ liquidity will be treated as a valid one and will be stored inside the mapPositionAccountLiquidity and positionAccounts arrays. If we add the fact that withdrawals are done by looping LINEARLY through positionAccounts:

liquidity_lockbox, function withdraw

    function withdraw(uint64 amount) external {
        address positionAddress = positionAccounts[firstAvailablePositionAccountIndex]; // @audit linear loop

        ...

        uint64 positionLiquidity = mapPositionAccountLiquidity[positionAddress];
        // Check that the token account exists
        if (positionLiquidity == 0) { // @audit it will revert here once it reaches the flawed position
            revert("No liquidity on a provided token account");
        }

        ...

        if (remainder == 0) { // @audit if the liquidity after the orca call is 0, close the position and ++ the index
            ...

            // Increase the first available position account index
            firstAvailablePositionAccountIndex++; // @audit it won't reach here as the revert above will roll-back the whole tx
        }
    }

It can be seen that once it encounters such a “fake” deposit with $0$ liquidity provided, it will always revert due to the existence check. As there is no other way to update firstAvailablePositionAccountIndex to bypass the flawed position, withdrawals will be completely freezed.

Recommended Mitigation Steps

Just check for the supplied liquidity to not be $0$ in

liquidity*lockbox, function *getPositionData

        ...
+       // Check that the liquidity > 0
+       if (positionData.liquidity == 0) {
+           revert("Liquidity cannot be 0");
+       }

        // Check that the liquidity is within uint64 bounds
        if (positionData.liquidity > type(uint64).max) {
            revert("Liquidity overflow");
        }

        ...

mariapiamo (Olas) confirmed


The original report as published on Code4rena, by erebus. 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 deposit function does not reject zero liquidity, while the withdrawal function uses zero liquidity as a marker for a non-existent position.

Impact

Withdrawals of LP tokens are completely frozen after a zero-liquidity deposit is created.

What the attacker needed

Ability to call deposit with zero liquidity

The fix

The deposit function should reject zero liquidity by adding a check that the supplied liquidity is greater than zero.

How it was found

  1. Call the deposit function with zero liquidity.
  2. The deposit passes validation and is stored in the position mapping and array.
  3. Call the withdraw function.
  4. The withdraw function reads the first position, sees zero liquidity, and reverts.
  5. Because the index is not advanced, all future withdrawals also revert.

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 lets users deposit tokens and later withdraw them. It records each deposit, but it does not check that the deposited amount is greater than zero. If someone deposits zero, the contract still saves that empty deposit. Later, when anyone tries to withdraw, the contract checks the first saved deposit, sees it is empty, and refuses to continue. Because the contract always starts from the first deposit, every withdrawal fails.

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 erebus

View all

5 more disclosed reports, best first.

More from Olas

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.