When users' CR falls below the liquidation CR, their positions become liquidatable, and users will experience loss through liquidation.
To avoid this, users should try to increase their CR by depositing more collateral or repaying their debts.
However, repaying the full debt can be difficult, so there is a compensate function that allows users to repay their debts partially.
The compensate function checks whether the user's CR is larger than the liquidation CR.
In scenarios where collateral prices fall suddenly and users' CR falls below the liquidation CR, users need to try to increase their CR.
It's not always possible for users to have additional collateral, and repaying the full debt before maturity is not effective.
Some users will try to partially repay their debts using their USDC tokens.
However, the CR will remain unchanged, and their attempt will be reverted due to their CR is still below the liquidation CR.
This means that their positions could still be liquidated, leading to losses.
Proof of Concept
Imagine Bobborrows100 USDC from Alice and has enough WETH as collateral.
The WETH price suddenly falls, and Bob's CR becomes 129, while the current liquidation CR is 130.
This means that Bob's debt position is liquidatable.
To avoid loss, Bob tries to repay his debt partially.
For example, he has 50 USDC and attempts to split his 100 USDCdebt into two smaller debts of 50 USDC each, then repay one of them.
However, his attempt will be reverted due to the last check in the compensate function.
function compensate(CompensateParams calldata params) external payable override(ISize) whenNotPaused {
state.validateCompensate(params);
state.executeCompensate(params);
state.validateUserIsNotUnderwater(msg.sender); // @audit, here
}
His CR remains 129, which is still less than 130.
As a result, his 100 USDCdebt position will be liquidated, leading to a loss.
Of course, in the compensate function, the user's CR can decrease when there is a fragmentation fee.
However, in most cases, the CR can increase when users try to compensate using already existing credit positions or remain unchanged when creating new debt and credit positions.
Therefore, it is sufficient to revert only when the CR decreases and is less than the liquidation CR.
If there is no decrease in CR, this action will benefit the protocol's health.
Please add below test to the test/local/actions/Compensate.t.sol:
Lines of code
https://github.com/code-423n4/2024-06-size/blob/8850e25fb088898e9cf86f9be1c401ad155bea86/src/libraries/actions/Compensate.sol#L120-L125 https://github.com/code-423n4/2024-06-size/blob/8850e25fb088898e9cf86f9be1c401ad155bea86/src/Size.sol#L250
Vulnerability details
Impact
When users'
CR
falls below theliquidation CR
, their positions becomeliquidatable
, and users will experienceloss
throughliquidation
. To avoid this, users should try to increase theirCR
by depositing morecollateral
orrepaying
theirdebts
. However,repaying
thefull debt
can be difficult, so there is acompensate
function that allows users torepay
theirdebts
partially.The
compensate
function checks whether the user'sCR
is larger than theliquidation CR
. In scenarios wherecollateral
prices fall suddenly and users'CR
falls below theliquidation CR
, users need to try to increase theirCR
. It's not always possible for users to have additionalcollateral
, andrepaying
thefull debt
before maturity is not effective.Some users will try to partially
repay
theirdebts
using theirUSDC
tokens. However, theCR
will remain unchanged, and their attempt will be reverted due to theirCR
is still below theliquidation CR
. This means that their positions could still beliquidated
, leading tolosses
.Proof of Concept
Imagine
Bob
borrows
100 USDC
fromAlice
and has enoughWETH
as collateral. TheWETH price
suddenly falls, andBob
'sCR
becomes129
, while the currentliquidation CR
is130
. This means thatBob
'sdebt
position isliquidatable
. To avoidloss
,Bob
tries torepay
hisdebt
partially. For example, he has50 USDC
and attempts to split his100 USDC
debt
into two smallerdebts
of50 USDC
each, thenrepay
one of them.However, his attempt will be reverted due to the last check in the
compensate
function.His
CR
remains129
, which is still less than130
. As a result, his100 USDC
debt
position will beliquidated
, leading to aloss
.Of course, in the
compensate
function, the user'sCR
can decrease when there is afragmentation fee
. However, in most cases, theCR
can increase when users try tocompensate
using already existingcredit
positions or remain unchanged when creating newdebt
andcredit
positions. Therefore, it is sufficient to revert only when theCR
decreases and is less than theliquidation CR
. If there is no decrease inCR
, this action will benefit theprotocol's health
.Please add below test to the
test/local/actions/Compensate.t.sol
:Tools Used
Recommended Mitigation Steps
Revert only when the
CR
decreases and is less than theliquidation CR
.Assessed type
Invalid Validation