-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
EVM: overflow detection in arithmetic instructions #159
Comments
Alternatively, this could be extended to support non-arithmetic instructions, e.g if |
Is this really that much better than just doing overflow checking at HLL level? You still need one branch condition per arithmetic operation if we're doing it this way. What if we unset the overflow flag only during JUMP and JUMPI? This would allow complex expressions to be evaluated with overflow only being checked once. |
It's worse than doing it at the HLL level so far as interpreter performance unless the multiprecision code already provides a cheap overflow flag. |
There has been no activity on this issue for two months. It will be closed in a week if no further activity occurs. If you would like to move this EIP forward, please respond to any outstanding feedback or add a comment indicating that you have addressed all required feedback and are ready for a review. |
This issue was closed due to inactivity. If you are still pursuing it, feel free to reopen it and respond to any feedback or request a review in a comment. |
Abstract
The goal is to support overflow detection in arithmetic functions. An overflow flag is introduced in the VM. This flag can only be set or unset by instructions and can only be read indirectly by programs.
Motivation
Overflow detection can be accomplished by checking the inputs before the arithmetic instructions. This is what Solidity does currently (see this extensive thread: ethereum/solidity#796). This proposal would make these checks cheaper.
Specification
ADD
,MUL
,SUB
,DIV
,SDIV
,MOD
,SMOD
,ADDMOD
,MULMOD
,EXP
,SIGNEXTEND
) unsets the overflow flag at the start of execution.DIV
,SDIV
sets the overflow flag if the divisor is 0.ADD
,MUL
,EXP
sets the overflow flag if the result was truncated to fit into 256 bits.SUB
sets the overflow flag when the second argument exceeds the first.SDIV
sets the overflow flag when- 2**255
is divided by-1
(highest bit set div all bits set).ADDMOD
,MULMOD
when the mod argument is0
.SIGNEXTEND
sets the overflow flag if the position parameter is> 31
.JUMPOF
(at 0x5c) is introduced. It takes one argument, the jump destination. If the overflow flag is set it will jump.TBD: define the overflow behaviour for the rest of the arithmetic instructions.
An alternative to
JUMPOF
could be introducingPUSHOF
and using it withJUMPI
. This could be useful if in the future more flags are introduced as they could be combined:The text was updated successfully, but these errors were encountered: