-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
Optimize Address.functionCall removing redundant isContract check #3469
Optimize Address.functionCall removing redundant isContract check #3469
Conversation
Thank you @ZumZoom for this interesting proposal. Do you have any metrics on the gas savings this can produce? |
Here are gas reports from relevant tests. TLDR: saves 108 gas when checks are not triggered (which is probably the most used case due to SafeERC20 library) and loses 26 gas when checks are triggered. Master
PR
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this PR, there are two version of verifyCallResult
with different arguments.
I'm worried that the two do not have the same behavior, which is not clear from naming alone:
verifyCallResult(bool,bytes,string)
is not modified. It will return the data if success. Otherwise it will revert with data (if not empty) or with the fallback stringverifyCallResult(address,bool,bytes,string)
is a new version. It will return the data is success and if either data is not empty or target is a contract. Otherwise it will revert with data (if not empty) or with the fallback string.
The second one forces the returns data to either be not empty, of target to be a contract, but doesn't enforce that target is actually the address that was called.
I think there is a clear possibility of user error or confusion, that we want to avoid.
@ZumZoom Please rename this to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
…enZeppelin#3469) Co-authored-by: Francisco <frangio.1@gmail.com>
In
Address.functionCall
,Address.functionDelegateCall
andAddress.functionStaticCall
it is possible to skip target'sisContract
check in cases where call fails or returns non-empty data. This can only happen when target has some code so there is no point in redundantisContract
check.PR Checklist