Accumulated profit/losses by the cumulative value is not dealt with in `borrowingLiquidation::liquidationType1()`, leading to losses
The liquidation function reduces two global totals without adjusting the cumulative value, so a CDS depositor's withdrawal calculation underflows and they cannot withdraw. An attacker can trigger cumulative value updates before liquidations to force this state.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-11-autonomint-judging/issues/755
Found by
0x73696d616f
Summary
borrowingLiquidation::liquidationType1() reduces omniChainData.totalVolumeOfBorrowersAmountinWei and omniChainData.totalCdsDepositedAmount without any consideration for the cumulative values so far, leading to losses. The cumulative value at each price is calculated essentially by priceDiff * omniChainData.totalVolumeOfBorrowersAmountinWei / omniChainData.totalCdsDepositedAmount, so changing these 2 variables without tracking correctly the cumulative value leads to issues, as shown below.
Root Cause
In borrowLiquidation.sol:248/252, totalCdsDepositedAmount and totalVolumeOfBorrowersAmountinWei are modified without considering the cumulative values.
Internal pre-conditions
None.
External pre-conditions
None.
Attack Path
- Consider a starting price of 1000 USD / ETH.
- Cds deposit of 1000 USDa.
- Borrow deposit of 1 ETH, borrowing 800 USDa.
- Price drops to 800 USD / ETH.
- Borrower deposits 1 wei to trigger cumulative value update, which registers a loss of roughly
1 * (1000 - 800) / 1000 = 0.2. - Liquidation of the first borrower happens, which will reduce
omnichainData.totalCdsDepositAmountto360(800 to treasury + 20 to abond calculated from 10% of 1000 - 800, cds profit of 1000 - 800 - 20 = 180, which yields a final cds deposited amount of 1000 - (800 + 20 - 180) = 360). - Cds depositor withdraws the 1000 USDa (disregarding the 1 wei borrower which doesnt really matter but technically would revert due to the 20% ratio), calculating a return amount of
1000 - 1000*0.2 = 800. Then,uint256 returnAmountWithGains = params.returnAmount + params.cdsDepositDetails.liquidationAmount - params.cdsDepositDetails.initialLiquidationAmount = 800 + 180 - 1000, which underflows. 180 comes from doing 1000 - 820, where 820 is the liquidation amounted needed (debt + return to abond).
Impact
Cds depositor can never withdraw until the cumulative value recovers. Alternatively, consider that calculating the cumulative value before liquidation yields -0.2, but after liquidating yields -0 (totalVolumeOfBorrowersAmountinWei becomes 0, so the cumulative value loss is 0), which goes to show that effectively it is incorrectly handled. Any user can trigger cumulative value updates before liquidations to force this bug, if needed.
PoC
See the calculations above.
Mitigation
Handle the cumulative values when liquidating.
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 liquidation function modifies totalCdsDepositedAmount and totalVolumeOfBorrowersAmountinWei without updating the cumulative value that depends on them.
What the attacker needed
CDS deposit exists; Borrower has a loan; Price drop triggers liquidation; Attacker can trigger cumulative value update
The fix
The cumulative values should be handled when liquidating.
How it was found
- Set starting price to 1000 USD/ETH.
- CDS deposit of 1000 USDa.
- Borrow deposit of 1 ETH, borrowing 800 USDa.
- Price drops to 800 USD/ETH.
- Borrower deposits 1 wei to trigger cumulative value update, registering a loss.
- Liquidation of the first borrower reduces totalCdsDepositAmount to 360.
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 is a smart contract bug where a liquidation changes some totals but forgets to update a running profit/loss figure. Because of that, a later withdrawal calculation goes negative and fails, locking the user's funds.
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.