At compile-time, division is using the same logic for both signed and unsigned integers. This is causing some corectness issues.
Compile time div operation for both signed and unsigned are defined by evm_div
But there should be an edge case according to the Ethereum yellow paper:
As you can see, DIV
and SDIV
are not purely equivalent. There is an edge case when and .
If we evaluate the expression with the Python engine, this is what we get for this function:
It's 2**255
, while it should be -2**255
.
Here are some examples at looking how this could be exploited:
Doesn't work, caught by the type checker:
While it should compile.
But we can for instance make it compile this way, while it should revert since as_wei_value
does not support negative values.
This compiles while the value should evaluate to a negative value, and returns 0x8000000000000000000000000000000000000000000000000000000000000000
.
Another example:
returns 0x8000000000000000000000000000000000000000000000000000000000000000
because max
is evaluated at compile-time with the wrong computation of -2**255 / -1
. The expected result should be 0
.
returns 0
Other things that compile while it shouldn't:
Manual review
(might be better to create a evm_sdiv
to make sure that it won't cause any issue in the future)
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.