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
For example the following solidity snippet
uint160 a, b; unchecked { a + b }
would be converted into (by the optimizer)
let _1 := sub(shl(160, 1), 1) let value := and(mul(a, b), _2)
Here _1 is a shorter representation of the constant.
_1
Instead the more optimized version would be
let _1 := shl(160, 1) let value := mulmod(a, b, _1)
It is shorter and avoids a sub. and + mul has the same gas as mulmod.
sub
and + mul
mulmod
Similarly, for addmod, but add + and is 6, and addmod is 8. We save a sub. So total saving of 2 gas and shorter deploy code.
addmod
add + and
6
8
2
It maybe easier to implement this as a rule and(mul(X, Y), A) -> mulmod(X, Y, 2**N) where A = 2**N - 1. Similarly, for the other?
and(mul(X, Y), A) -> mulmod(X, Y, 2**N)
A = 2**N - 1
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
For example the following solidity snippet
would be converted into (by the optimizer)
Here
_1is a shorter representation of the constant.Instead the more optimized version would be
It is shorter and avoids a
sub.and + mulhas the same gas asmulmod.Similarly, for
addmod, butadd + andis6, andaddmodis8. We save asub. So total saving of2gas and shorter deploy code.It maybe easier to implement this as a rule
and(mul(X, Y), A) -> mulmod(X, Y, 2**N)whereA = 2**N - 1. Similarly, for the other?The text was updated successfully, but these errors were encountered: