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
From issue #796 we are in the process of adding runtime overflow checks. At commit 3f833c9, the addition of two signed numbers is not protected against overflows. This can be seen in
$ cat test.sol
contract Test {
function test(int x, int y) returns (int r) {
r = x + y;
}
}
$ solc/solc test.sol --opcodes --optimize | grep CALLDATA
<snip>
PUSH1 0x24 CALLDATALOAD PUSH1 0x4 CALLDATALOAD ADD PUSH1 0x60 SWAP1 DUP2 MSTORE PUSH1 0x20 SWAP1 RETURN
I think it's reasonable to add overflow checks for additions, especially on signed numbers.
Note that we might need to change the optimizer, because after making this change, the ordering of addition changes the result. With the overflow checks a + (b - c) is not always equal to (a + b) - c because a + b might cause an exception for the overflow.
The text was updated successfully, but these errors were encountered:
From issue #796 we are in the process of adding runtime overflow checks. At commit 3f833c9, the addition of two signed numbers is not protected against overflows. This can be seen in
I think it's reasonable to add overflow checks for additions, especially on signed numbers.
Note that we might need to change the optimizer, because after making this change, the ordering of addition changes the result. With the overflow checks
a + (b - c)
is not always equal to(a + b) - c
becausea + b
might cause an exception for the overflow.The text was updated successfully, but these errors were encountered: