Closed sherlock-admin closed 1 year ago
for the current usage the value of b should not practically reach type(int256).min, a comment should be added to make the usage of Calc.boundedSub clear
"The vulnerability must be something that is not considered an acceptable risk by a reasonable protocol team." https://docs.sherlock.xyz/audits/judging/judging . This one is marked as disputed and there is no fix, so closing
IllIllI
medium
boundedSub()
reverts rather than returning a bounded value, whentype(int256).min
is usedSummary
boundedSub()
reverts ifb
istype(int256).min
Vulnerability Detail
boundedSub()
is supposed to return bounded values (type(int256).min
ortype(int256).max
) rather than overflowing. Ifb
istype(int256).min
, it reverts rather than returning a value.Impact
boundedSub()
is supposed to always return a value, so that calculations with large numbers, such as those having to do with funding amounts, do not cause orders to revert.Code Snippet
The test below shows that the function will revert under two separate conditions (A and B), both of which occur when
b
istype(int256).min
:Tool used
Manual Review
Recommendation
Change the code to what I have in
boundedSub2()
which uses anunchecked
block so that it can check for overflows/underflows, rather than reverting in those cases.