You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If there is a unary operation happening on two (u)ints within an unchecked code block and the result is being casted into a (u)int without sufficient overflow/underflow checks depending on the operator this is a vulnerability.
There are two obvious cases where this pattern could be generalized as a vulnerability. Should probably be noted that this vulnerability could get much more nuanced than these general cases outlined.
First: +,*,<<,** Operator no overflow check in the unchecked block.
Bad:
Contract Example {
function leftBitwiseShift(uint128x) publicreturns (uint128z) {
unchecked {
z= x<<64;
};
}
function multiply(uint128x, uint128y) publicreturns (uint128z) {
unchecked {
z= x*y;
};
}
}
If there is a unary operation happening on two
(u)ints
within anunchecked
code block and the result is being casted into a(u)int
without sufficient overflow/underflow checks depending on the operator this is a vulnerability.There are two obvious cases where this pattern could be generalized as a vulnerability. Should probably be noted that this vulnerability could get much more nuanced than these general cases outlined.
First:
+,*,<<,**
Operator no overflow check in theunchecked
block.Bad:
Good:
Second: Underflow check on
-
in unchecked blocks when casting result touint
Bad:
Good:
The text was updated successfully, but these errors were encountered: