Skip to content
Business logic Audit finding Intermediate

Balance check for swapToken in ShortLongSpell#_deposit is incorrect and will result in nonfunctional contract

The balance check in ShortLongSpell#_deposit incorrectly assumes that the swapped token differs from the borrowed token, but they are always the same. As a result, any swap causes the balance check to fail and revert, making the contract nonfunctional.

0x52 Follow with Ch_301 and sinarette

Originally disclosed on Sherlock

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

Found by

0x52, Ch_301, sinarette

Summary

The balance checks on ShortLongSpell#_withdraw are incorrect and will make contract basically nonfunctional

Vulnerability Detail

swapToken is always vault.uToken. borrowToken is always required to be vault.uToken which means that swapToken == borrowToken. This means that the token borrowed is always required to be swapped.

ShortLongSpell.sol#L83-L89

    uint256 strTokenAmt = _doBorrow(param.borrowToken, param.borrowAmount);

    // 3. Swap borrowed token to strategy token
    IERC20Upgradeable swapToken = ISoftVault(strategy.vault).uToken();
    // swapData.fromAmount = strTokenAmt;
    PSwapLib.megaSwap(augustusSwapper, tokenTransferProxy, swapData);
    strTokenAmt = swapToken.balanceOf(address(this)) - strTokenAmt; <- @audit-issue will always revert on swap

Because swapToken == borrowToken if there is ever a swap then the swapToken balance will decrease. This causes L89 to always revert when a swap happens, making the contract completely non-functional

Impact

ShortLongSpell is nonfunctional

Code Snippet

ShortLongSpell.sol#L160-L202

Tool used

Manual Review

Recommendation

Remove check

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

The code incorrectly assumes that the token being swapped is different from the borrowed token, but they are always the same, so the balance check after the swap is wrong.

Impact

The ShortLongSpell contract becomes nonfunctional because any swap will cause a revert.

What the attacker needed

None

The fix

The balance check should be removed or corrected to account for the fact that the swapped token is the same as the borrowed token.

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 report is about a smart contract function that borrows a token and then swaps it for another. The code checks the balance after the swap, but because the borrowed token and the swapped token are the same, the balance goes down instead of up, so the check always fails and the function stops working.

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.