The protocol's health factor check is incorrectly placed during collateral redemption, allowing users to bypass critical insolvency protections by exploiting intermediate states where their debt is set to zero. This logic flaw enables full collateral withdrawal even after severe price drops, risking total protocol insolvency.
The protocol uses a "health factor" mechanism to ensure that collateral remains sufficient, preventing users from redeeming collateral when prices drop significantly. This mechanism is enforced through the _revert_if_health_factor_is_broken
function, which reverts transactions if the user's health factor falls below a safe threshold.
However, the correct placement of this health factor check depends on the specific process being executed:
Depositing Collateral
When depositing collateral, the health factor should be checked after updating the user’s collateral balance.
Redeeming Collateral
When redeeming collateral, the health factor check should be performed before any state changes, such as reducing collateral balances or burning tokens. This prevents the system from being manipulated by intermediate states where balances are reduced or set to zero. For this protocol, the redeeming process is implemented incorrectly because the health factor check happens after these critical state changes.
For example, in the redeem_collateral_for_dsc
function, if a user withdraws all collateral and burns all tokens, the system will see total_dsc_minted = 0
when performing the health factor check, returning the maximum possible value due to this logic:
This logic flaw allows bypassing the critical health factor check, enabling users to redeem full collateral even after a severe price drop, putting the protocol at risk of insolvency.
Note: The current implementation might assume max_value(uint256)
as a valid return for users without any DSC debt. The critical risk occurs only when users have non-zero DSC debt but can still withdraw collateral due to bypassing the health factor check.
This logic flaw allows users with outstanding DSC debt to potentially redeem more collateral than intended after a severe price drop, risking protocol insolvency due to miscalculated health factors.
Manual review
This can be proved by running the following unit test:
The health factor check should happen before calculations that are related with collateral redemption or token burning:
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.