Open c4-submissions opened 11 months ago
bytes032 marked the issue as insufficient quality report
GalloDaSballo (sponsor) disputed
The issue is true. There is a controversial statement here in the official document https://docs.ebtc.finance/ebtc/protocol-mechanics/liquidations :
... will trigger a 15 minutes period during which liquidations are blocked. This is known as the Grace Period.
But the quesion is that, should the cdp, which should have been liquidated in normal mode, be blocked for liquidation?
I think it's a valide QA, but for doc instead of code.
jhsagd76 changed the severity to QA (Quality Assurance)
jhsagd76 marked the issue as grade-a
Hi @jhsagd76 , thanks for your reviewing. Please review my comment.
According to the documentation, the Grace Period
is defined as a minimum 15
-minute period during which all liquidations are supposed to be blocked.
This implies that all CDPs
should be inaccessible for liquidation during the grace period, regardless of whether their ICR
is higher or lower than the MCR
.
Allow me to provide an example to clarify the issue.
Users understandably do not want their CDPs
to be liquidated by others, as this would result in a loss of funds through the liquidation process.
Consider a scenario where some users maintain their CDPs
with an ICR
higher than the MCR
, and the current mode is normal
. (At this point, their cdps
are safe.)
Due to certain events such as price fluctuations, the value of stEth
decreases while the value of eBTC
increases.
As a result, the TCR
becomes lower than the CCR
, triggering the system to enter recovery
mode.
Users with a ICR
lower than the TCR
will aim to enhance their ICR
during the grace period
.
Consequently, before the end of the grace period, the TCR
may once again surpass the CCR
.
In this situation, some users may find that their ICRs
become lower than the MCR
.
The user attempts to collect some stEth
and increase the collateral of their CDPs
to surpass the MCR
.
However, before they can do so, other active users have the ability to liquidate that CDP
because the grace period
does not seem to work for that particular CDP
.
Please correct me if I have misunderstood any aspect of the situation.
Thank you.
I need to explain a fundamental security guideline for over-collateralized DeFi protocols.
Liquidation is the cornerstone of the protocol security, ensuring prompt liquidation for any loan that falls below MCR. This prevents bad debt and guarantees that the system's overall collateralization ratio does not enter a death spiral.
The protocol should also operate a fast and stable liquidator bot to handle black swan. Even in cases of severe price fluctuations, this liquidator bot needs to ensure smooth liquidation, even if it incurs losses. This is because a lack of economic incentives for liquidation would imply that there are no external liquidators available. kindly ping sponsor to ensure that they are aware of this @CodingNameKiki .
In conclusion, I do not believe that the grace period should be applicable to loans below MCR. This would significantly increase the system's risk of bad debt. So as I said, it's a typo in the documentation
Yes we are aware and this is how the system is supposed to work, will explain why in a bit just waking up. Also agree that there is typo in the documentation.
In conclusion, I do not believe that the grace period should be applicable to loans below MCR.
On short explanation the main use of the grace period is to ensure that if the system goes in recovery mode and TCR < CCR, any Cdp with collateral ratio between MCR and CCR have time to top up their positions and safe them otherwise they can be further liquidated to increase the system TCR.
Any other Cdp with ICR <= MCR should not be affected by the grace period, as further liquidating this positions can increase the TCR and there is a chance that at the end of the 15 mins, the system will be back to normal mode and no further position with collateral ratio between MCR and CCR will be liquidated.
As said by @jhsagd76 this should be a typo in the documentation.
Thanks @jhsagd76 , @CodingNameKiki
jhsagd76 marked the issue as grade-b
Lines of code
https://github.com/code-423n4/2023-10-badger/blob/f2f2e2cf9965a1020661d179af46cb49e993cb7e/packages/contracts/contracts/LiquidationLibrary.sol#L80-L98 https://github.com/code-423n4/2023-10-badger/blob/f2f2e2cf9965a1020661d179af46cb49e993cb7e/packages/contracts/contracts/LiquidationLibrary.sol#L761
Vulnerability details
Impact
A
CDP
with aICR
below theMCR
may be liquidated without undergoinggrace period
checks in therecovery mode
. This significantly violates theprotocol
.Proof of Concept
When a user attempts to
liquidate
an individualCDP
, we only check thegrace period
when theICR
is greater than theMCR
.However, there is also a
scenario
where auser
is attempting toliquidate
aCDP
inrecovery mode
, even when theICR
is below theMCR
. In such a case, thegrace period check
will be skipped, and theCDP
can beliquidated
within therecovery mode duration
.Additionally, the
grace period check
is absent in the_getTotalFromBatchLiquidate_RecoveryMode
function.Here, it's important to note that
ICR < MCR
doesn't necessarily imply that the mode is not inrecovery mode
.Tools Used
Recommended Mitigation Steps
Please modify
_liquidateIndividualCdpSetup
as below:Please modify
_getTotalFromBatchLiquidate_RecoveryMode
function as below:Assessed type
Error