-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Exponentiation producing inconsistent results #4893
Comments
This is unrelated to the part of the documentation you cite because due to the type conversions to I would assume this is due to cleanup not being performed for intermediate values. "Lazy cleanup" can be done as long as cleanup and operation "commute" which is the case for addition and multiplication and I would guess also "almost" for EXP except for the special case of zero. |
The following returns
|
I would assume that we do not have to clean the base, but we do have to clean the exponent, and the only special case here would be where the exponent is zero (in the respective representation). |
So basically |
Thanks for the replies. Is the following case - which also involves the exponentiation operator - a duplicate, or something else? It behaves differently for me in Remix by producing an unexpected result rather than a VM error. I construct a value of 1 to use as exponent using the unary minus operator, which results in some invalid value, see:
|
Phew, I almost thought that we have the same problem with unary minus, but this is actually another incarnation of the missing cleanup for exponentiation. |
Across multiple unsigned integer types I've tried - e.g. uint8 - the exponentiation operator can produce a result which is outside of the range of that type in some contexts, but exhibits the truncation behavior I'd expect in other contexts.
I get different failure modes in the truffle-based test framework I'm using (with ganache-cli, Linux, solc-js 0.4.24 - this produces unexpected values) and http://remix.ethereum.org/ (this produces a VM error).
See:
This probably has something to do with this statement from the docs, which indicates that intermediate results exceeding the size of their input operand types can be produced:
If I understand this correctly, the expression "x ** y" is dynamically typed and may produce a result which is outside of the range of x's type. But in that case using an explicit conversion to the smaller type should at least consistently always truncate (preferred, IMO) or never truncate.
(This report is part of an ICE Center@ETH Zurich project on automated compiler validation funded by the Ethereum Foundation.)
The text was updated successfully, but these errors were encountered: