The safetyCheck function performs an unsafe subtraction on two uint256 before casting them to int256.
The subtraction can underflow and the cast to int256 can either fail and revert the transaction (if greater than type(int256).max), or, fit into an int256 and corrupt the safetyCheck making it always return false.
// _ratio - lastRatio[i] are uint256s and underflows
_ratio = abs(int256(_ratio - lastRatio[i]));
If the lastRatio[i] is even just 1 "wei" less than _ratio, the result will be type(uint256).max and the cast to int256 will fail due to the size limit of signed integers.
All functions implementing the safetyCheck will revert and the protocol can become stuck and unusable.
Recommended Mitigation Steps
As only the absolute value is relevant the following code should work without having to cast to int256:
Handle
cmichel
Vulnerability details
Vulnerability Details
The
safetyCheck
function performs an unsafe subtraction on two uint256 before casting them toint256
. The subtraction can underflow and the cast toint256
can either fail and revert the transaction (if greater thantype(int256).max
), or, fit into anint256
and corrupt thesafetyCheck
making it always returnfalse
.If the
lastRatio[i]
is even just 1 "wei" less than_ratio
, the result will betype(uint256).max
and the cast toint256
will fail due to the size limit of signed integers. All functions implementing thesafetyCheck
will revert and the protocol can become stuck and unusable.Recommended Mitigation Steps
As only the absolute value is relevant the following code should work without having to cast to
int256
: