-
Notifications
You must be signed in to change notification settings - Fork 177
Description
https://www.evm.codes/?fork=cancun#07:
Note the overflow semantic when
$−2^{255}$ is negated.
This is a controversial statement for this opcode.
There is no such statement in https://ethereum.github.io/yellowpaper/paper.pdf.
If needed, you may look deeper into implementation details:
-
opSdiv: https://github.com/ethereum/go-ethereum/blob/master/core/vm/instructions.go#L53
-
Sdiv: https://github.com/holiman/uint256/blob/master/uint256.go#L789
-
opSmod: https://github.com/ethereum/go-ethereum/blob/master/core/vm/instructions.go#L65
-
Smod: https://github.com/holiman/uint256/blob/master/uint256.go#L662C1-L682C2
The main point is that SDIV comment—
"Note the overflow semantic when
refers to an overflow case.
In contrast, SMOD does not overflow because its arithmetic logic disregards the sign of the second operand.