The convertSd59x18ToTokenAmount()
function in the Collateral library contains a critical design flaw that causes guaranteed runtime failures when processing negative values due to an improper unsigned conversion.
The current code design guarantees runtime failures for negative values. The function attempts to convert SD59x18 (signed fixed-point) numbers to token amounts using intoUint256()
, which explicitly reverts on negative inputs:
This creates a mathematical domain violation as the function's input type (SD59x18) supports the full range of signed values, but the conversion path forcibly restricts this to non-negative values only. This restriction breaks the system's ability to process legitimate negative values in financial calculations.
The issue is particularly severe because proper conversion paths exist within PRBMath for handling signed-to-unsigned conversions, but they're not being utilized. Instead, the code attempts an unsafe conversion that PRBMath explicitly prevents through runtime checks.
The impact of this flaw creates a systemic failure in the protocol's financial calculations. Since PRBMath's intoUint256() explicitly reverts on negative values, all negative numerical flows in the system will fail at runtime. This prevents handling of essential financial operations like debt positions, penalties, and price adjustments that naturally involve negative values. Protocol developers are forced to implement fragmented workarounds outside the standard conversion path, increasing complexity and risk of errors in financial calculations.
The implementation should be modified to maintain signed value support throughout the conversion process:
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.