The getAutoDeleverageFactor function in the Market library does not handle cases where the market has excess credit (negative debt). When totalDebtUsdX18 is negative, the conversion to UD60x18 reverts due to an underflow error in the intoUD60x18 function. This prevents the ADL system from functioning correctly, even when the market is in a safe state with excess credit.
The issue is in the getAutoDeleverageFactor function:
The issue arises because totalDebtUsdX18 can be negative when the market has excess credit (a safe state). When this value is passed to intoUD60x18, it reverts due to the underflow check in the intoUD60x18 function:
totalDebtUsdX18 = -100 (market has excess credit)
delegatedCreditUsdX18 = 1000
The function attempts to calculate marketDebtRatio as totalDebtUsdX18.div(delegatedCreditUsdX18).intoUD60x18().
The conversion to UD60x18 reverts because totalDebtUsdX18 is negative.
The ADL cannot function when the market has excess credit, even though this is a safe state. This could lead to unnecessary reverts and prevent the protocol from operating as intended.
Manual review
To fix the issue, ensure that the getAutoDeleverageFactor function handles negative debt (excess credit) gracefully. Specifically, the function should return a zero deleverage factor when the market has excess credit, as no deleveraging is needed in such cases.
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.