You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think the current implementation of int256 addition overflow check is quite suboptimal. The optimizer seems not to be able to catch this possible optimization, probably because it's unaware of the bounds of the inputs.
Motivation
The compiler seems to be outputting the following Yul equivalent when intending to add two signed integers a and b (thanks to Dedaub for the decompiler):
This is just a bytecode generation improvement. Should be fully backward compatible.
PS. I don't know the structure of the codebase very well, so I'm not comfortable writing a PR for this – this is why I'm raising this as an issue. Sorry for any additional effort needed due to this.
The text was updated successfully, but these errors were encountered:
Abstract
I think the current implementation of int256 addition overflow check is quite suboptimal. The optimizer seems not to be able to catch this possible optimization, probably because it's unaware of the bounds of the inputs.
Motivation
The compiler seems to be outputting the following Yul equivalent when intending to add two signed integers
a
andb
(thanks to Dedaub for the decompiler):This is quite inefficient. Since
slt
returns 0 or 1, we can usexor
instead of anor
, twoand
s and twoiszero
s:Specification
Consider altering the following code in
YulUtilFunctions.cpp#734-737
:into the following:
Backwards Compatibility
This is just a bytecode generation improvement. Should be fully backward compatible.
PS. I don't know the structure of the codebase very well, so I'm not comfortable writing a PR for this – this is why I'm raising this as an issue. Sorry for any additional effort needed due to this.
The text was updated successfully, but these errors were encountered: