Market::getAutoDeleverageFactor
as described in CreditDelegationBranch::withdrawUsdTokenFromMarket
should never return 1, but in fact it can return 1.
Market::getAutoDeleverageFactor
:
As you can see in above marked part in the function, the unscaledDeleverageFactor is defined as in the natspec. The issue arises if marketDebtRatio > autoDeleverageEndThreshooldX18, since numerator and denominator would simplify each other out, resulting in UD60x18 autoDeleverageFactorX18
returned as equal to 1.
While it is under these circumstances possible that the market is in a state of auto deleveraging, that above function returns a value which explicitly does not deleverage anything, the impact of this is medium, since it only affects a discrete point on the curve. While it would be possible though, that if the Registered Engine calls CreditDelegationBranch::withdrawUsdTokenFromMarket
with a considerably large withdrawal, which should have been already deleveraged, it would be processed without deleveraging. Therefor it can not be entirely ignored.
Manual Review
An easy mitigation would be to subtract an epsilon
in the numerator if autoDeleverageEndThresholdX18
was returned, with epsilon being a very small number (e.g., 1e-18 in the UD60x18 fixed-point representation) that does not materially affect normal operations but guarantees the factor is always less than 1.
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.