The updateTotalDelegatedCredit function in the Market library is vulnerable to an underflow error when updating the total delegated credit. If a negative creditDeltaUsdX18 (e.g., during a vault withdrawal) causes the total delegated credit to become negative, the conversion to UD60x18 will revert, freezing all credit updates. This can permanently brick the protocol's credit delegation and withdrawal functionality.
The issue isin the updateTotalDelegatedCredit function:
Underflow Condition:
The function adds creditDeltaUsdX18 (which can be negative) to the current totalDelegatedCreditUsd. If the result is negative, the conversion to UD60x18 will revert due to the underflow check in the intoUD60x18 function:
Example Scenario:
totalDelegatedCreditUsd = 100
creditDeltaUsdX18 = -150
The calculation attempts to compute: 100 + (-150) = -50
The conversion to UD60x18 reverts because -50 is negative.
All credit delegation and withdrawal functions will revert if the total delegated credit becomes negative, effectively bricking the protocol.
Manual review
To fix the issue, add a check to ensure that the total delegated credit does not become negative after applying the creditDeltaUsdX18. If the result would be negative, revert with a descriptive error message.
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.