Skip to content
Business logic Audit finding Intermediate

Liquidation bonus scales exponentially instead of linearly

bughuntoor Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-03-wagmileverage-v2-judging/issues/7

Found by

bughuntoor

Summary

Liquidation bonus scales exponentially instead of linearly.

Vulnerability Detail

Let's look at the code of getLiquidationBonus

Solidity
    function getLiquidationBonus(
        address token,
        uint256 borrowedAmount,
        uint256 times
    ) public view returns (uint256 liquidationBonus) {
        // Retrieve liquidation bonus for the given token
        Liquidation memory liq = liquidationBonusForToken[token];
        unchecked {
            if (liq.bonusBP == 0) {
                // If there is no specific bonus for the token
                // Use default bonus
                liq.minBonusAmount = Constants.MINIMUM_AMOUNT;
                liq.bonusBP = dafaultLiquidationBonusBP;
            }
            liquidationBonus = (borrowedAmount * liq.bonusBP) / Constants.BP;

            if (liquidationBonus < liq.minBonusAmount) {
                liquidationBonus = liq.minBonusAmount;
            }
            liquidationBonus *= (times > 0 ? times : 1);
        }
    }

As we can see, the liquidation bonus is based on the entire borrowAmount and multiplied by the number of new loans added. The problem is that it is unfair when the user makes a borrow against multiple lenders.

If a user takes a borrow for X against 1 lender, they'll have to pay a liquidation bonus of Y. However, if they take a borrow for 3X against 3 lenders, they'll have to pay 9Y, meaning that taking a borrow against N lenders leads to overpaying liquidation bonus by N times.

Furthermore, if the user simply does it in multiple transactions, they can avoid these extra fees (as they can simply call borrow for X 3 times and pay 3Y in Liquidation bonuses)

Impact

Loss of funds

Code Snippet

https://github.com/sherlock-audit/2024-03-wagmileverage-v2/blob/main/wagmi-leverage/contracts/LiquidityBorrowingManager.sol#L280

Tool used

Manual Review

Recommendation

make liquidation bonus simply a % of totalBorrowed

Discussion

fann95

We discussed as a team multiplying the bonus depending on the method of taking out a loan and ultimately decided to abandon it completely. a few days ago I made the corresponding commit https://github.com/RealWagmi/wagmi-leverage/commit/7575ab6659e99e59f5b7b7d1454649091c0295c6

sherlock-admin4

The protocol team fixed this issue in PR/commit https://github.com/RealWagmi/wagmi-leverage/commit/7575ab6659e99e59f5b7b7d1454649091c0295c6.

sherlock-admin3

2 comment(s) were left on this issue during the judging contest.

WangAudit commented:

decided that it's a H not an M cause even if it's intended behaviour; user can easily bypass it; or if it's not intended' then it will be applied every time when times > 2

takarez commented:

i think that is a design choice to charge whenever there's a borrow.

fann95

2 comment(s) were left on this issue during the judging contest.

WangAudit commented:

decided that it's a H not an M cause even if it's intended behaviour; user can easily bypass it; or if it's not intended' then it will be applied every time when times > 2

takarez commented:

i think that is a design choice to charge whenever there's a borrow.

The liquidation bonus was charged more than initially expected, so the user’s cunning could only lead to a fair payment. But ultimately the bonus would still be returned to the trader. The trader paid a more liquidation bonus if he extracted more than one NFT position, which in itself is a rare case... anyway, we removed it from the code..

spacegliderrrr

Fix looks good, liquidation bonus is now correctly proportional to borrow amount, no matter the number of lenders.

sherlock-admin4

The Lead Senior Watson signed off on the fix.

The original report as published on Sherlock, by bughuntoor. 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.

What is known

A medium-severity business logic bug in WagmiLeverage V2. Sherlock made it public on 30 March 2024. Found in the 281 audit contest (finding M-1).

About Business logic

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

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 bughuntoor

View all

16 more disclosed reports, best first.

More from WagmiLeverage V2

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.