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.
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
{
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
Tool used
Manual Review
Recommendation
Don't burn the collateral
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.