Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception on overflow in addition of two signed numbers #1170

Closed
pirapira opened this issue Oct 6, 2016 · 1 comment
Closed

Exception on overflow in addition of two signed numbers #1170

pirapira opened this issue Oct 6, 2016 · 1 comment

Comments

@pirapira
Copy link
Member

pirapira commented Oct 6, 2016

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.

@pirapira
Copy link
Member Author

Delegated back to #796.

axic pushed a commit that referenced this issue Nov 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant