Solidity's uint256 can cause overflow.
Why not resolve this problem in the EVM?
The reason behind this is that overflow checking is expensive.
It would be bad for overall EVM performance and by extension bad for tx rate, node performance, etc.
The way it is now, they are leaving it up to a higher level to decide, you can chose wether or not your program is slowed down for safety. Maybe in your particular case there is a much cheaper way within the logic of the program to perform the check or to prevent overflow otherwise.
Since soldity 0.4.16 there is a support for overflow checking:
From the documentation :
solc now include experimental support for automated overflow and assertion checking at compile-time using the SMT solver Z3
Adding two uint256 numbers may lead to an overflow. But the behavior is veldefined since the result of adding a
and b
will be a + b mod 2^256
.
Allowing overflow is common in processors. In Ethereum it is up to the smart contract developers to check for overflow. In some situations the overflowed addition may be desired.
But it could probably be argued that overflow should throw an exception and halt the execution. This is a design choice and perhaps the Ethereum developers has made a suboptimal choice here.