Skip to content
Business logic Audit finding Intermediate

ShortLongSpell#openPosition can cause user unexpected liquidation when increasing position size

When increasing a position, the contract burns all collateral and sends the underlying tokens to the user, leaving the position with only isolated collateral. This can cause the user to be liquidated unexpectedly if the price moves slightly.

0x52 Follow with Ch_301

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-04-blueberry-judging/issues/135

Found by

0x52, Ch_301

Summary

When increasing a position, all collateral is sent to the user rather than being kept in the position. This can cause serious issues because this collateral keeps the user from being liquidated. It may unexpectedly leave the user on the brink of liquidation where a small change in price leads to their liquidation.

Vulnerability Detail

ShortLongSpell.sol#L129-L141

    {
        IBank.Position memory pos = bank.getCurrentPositionInfo();
        address posCollToken = pos.collToken;
        uint256 collSize = pos.collateralSize;
        address burnToken = address(ISoftVault(strategy.vault).uToken());
        if (collSize > 0) {
            if (posCollToken != address(wrapper))
                revert Errors.INCORRECT_COLTOKEN(posCollToken);
            bank.takeCollateral(collSize);
            wrapper.burn(burnToken, collSize);
            _doRefund(burnToken);
        }
    }

In the above lines we can see that all collateral is burned and the user is sent the underlying tokens. This is problematic as it sends all the collateral to the user, leaving the position collateralized by only the isolated collateral.

Best case the user's transaction reverts but worst case they will be liquidated almost immediately.

Impact

Unfair liquidation for users

Code Snippet

ShortLongSpell.sol#L111-L151

Tool used

Manual Review

Recommendation

Don't burn the collateral

The original report as published on Sherlock, by 0x52. 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 function burns all collateral and refunds the underlying tokens to the user instead of keeping it in the position.

Impact

Users could be liquidated unfairly, especially if the price changes slightly after increasing their position.

What the attacker needed

User increases position size

The fix

The collateral should not be burned; it should remain in the position to protect the user.

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 a lending system, collateral is what you put up to borrow. If you add to a position, the code should keep your collateral in the position to protect you. Here, the code gives all your collateral back to you, so your position has less protection and can be liquidated (closed at a loss) if the price moves a little.

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 0x52

View all

211 more disclosed reports, best first.

More from Blueberry Update #3

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.