This repository has been archived by the owner on Nov 19, 2023. It is now read-only.
xiaoming90 - Possible to liquidate past the debt outstanding above the min borrow without liquidating the entire debt outstanding #194
Labels
High
A valid High severity issue
Reward
A payout will be made for this issue
Sponsor Confirmed
The sponsor acknowledged this issue is valid
Will Fix
The sponsor confirmed this issue will be fixed
xiaoming90
high
Possible to liquidate past the debt outstanding above the min borrow without liquidating the entire debt outstanding
Summary
It is possible to liquidate past the debt outstanding above the min borrow without liquidating the entire debt outstanding. Thus, leaving accounts with small debt that are not profitable to unwind if it needs to liquidate.
Vulnerability Detail
https://github.com/sherlock-audit/2023-03-notional/blob/main/contracts-v2/contracts/internal/vaults/VaultValuation.sol#L251
depositUnderlyingInternal
is always a positive value (Refer to comment on Line 250) that represents the amount of underlying deposited by the liquidatorh.debtOutstanding[currencyIndex]
is always a negative value representing debt outstanding of a specific currency in a vault accountminBorrowSize
is always a positive value that represents the minimal borrow size of a specific currency (It is stored as uint32 in storage)If liquidating past the debt outstanding above the min borrow, then the entire debt outstanding must be liquidated.
Assume the following scenario:
depositUnderlyingInternal
=70 USDC
h.debtOutstanding[currencyIndex]
=-100 USDC
minBorrowSize
=50 USDC
If the liquidation is successful, the vault account should be left with
-30 USDC
debt outstanding because70 USDC
has been paid off by the liquidator. However, this should not happen under normal circumstances because the debt outstanding (-30
) does not meet the minimal borrow size of50 USDC
and the liquidation should revert/fail.The following piece of validation logic attempts to ensure that all outstanding debt is liquidated if post-liquidation debt does not meet the minimal borrowing size.
Plugging in the values from our scenario to verify if the code will revert if the debt outstanding does not meet the minimal borrow size.
The above shows that it is possible for someone to liquidate past the debt outstanding above the min borrow without liquidating the entire debt outstanding. This shows that the math formula in the code is incorrect and not working as intended.
Impact
A liquidation can bring an account below the minimum debt. Accounts smaller than the minimum debt are not profitable to unwind if it needs to liquidate (Reference)
As a result, liquidators are not incentivized to liquidate those undercollateralized positions. This might leave the protocol with bad debts, potentially leading to insolvency if the bad debts accumulate.
Code Snippet
https://github.com/sherlock-audit/2023-03-notional/blob/main/contracts-v2/contracts/internal/vaults/VaultValuation.sol#L251
Tool used
Manual Review
Recommendation
Update the formula to as follows:
Plugging in the values from our scenario again to verify if the code will revert if the debt outstanding does not meet the minimal borrow size.
The above will trigger a revert as expected when the debt outstanding does not meet the minimal borrow size.
The text was updated successfully, but these errors were encountered: