Say I have a smart contract with variable of type uint256. I write a function to increment this variable.

How does the EVM handle trying to increment the variable to store values beyond 256 bits?

The Solidity docs say the following:

Number literal expressions retain arbitrary precision until they are converted to a non-literal type (i.e. by using them together with a non-literal expression). This means that computations do not overflow and divisions do not truncate in number literal expressions.

So apparently it won't overflow, so what does it do?

  • 1
    Maybe this helps you.Is it possible to overflow uints? – BinGoBinBin Aug 9 '17 at 5:38
  • The wording is slightly confusing. It should say something like "This means that literal expressions can not overflow...". See also the example just below, (2**800 + 1) - 2**800, which is larger than any data type. – jordanpg Dec 30 '17 at 2:48

Non-literal expressions overflow. I think a 'literal' expression is something like 1223424234. That won't overflow, I suppose, because it won't even compile. A non literal expression (a = 1213232; b = 121231231 -- a and b are really large) will overflow if a+b is larger than largest uint256. At least this is my read.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy