Skip to content
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

feat: use extcodesize for isContract to reduce gas #2311

Merged
merged 2 commits into from
Jul 14, 2020

Conversation

julianmrodri
Copy link
Contributor

#2310

Fixes #2310

  • Restablishes extcodesize to check if an address isContract as this now consumes less gas than extcodehash.

@julianmrodri
Copy link
Contributor Author

@nventuro @frangio just implemented the change so we have it there. I will run some verifications to confirm less gas is consumed with this method.

@julianmrodri
Copy link
Contributor Author

julianmrodri commented Jul 13, 2020

Execution costs (tested on Remix - solidity 0.6.6):
extcodehash

  1. If address is EOA: 1079 gas
  2. If address is contract: 1099 gas

With extcodesize:

  1. if address is EOA: 1015 gas
  2. if address is contract: 1015 gas

So there is a reduction in the execution costs by using extcodesize. Whether it iss significant I will leave it up to you guys, would really appreciate to understand your rationale.

@frangio
Copy link
Contributor

frangio commented Jul 14, 2020

Thanks @julianmrodri! I wouldn't call the reduction significant but it's still a welcome change!

Can you add a small changelog entry?

@julianmrodri
Copy link
Contributor Author

Sure will do right now.

Copy link
Contributor

@frangio frangio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@frangio frangio merged commit c801c8d into OpenZeppelin:master Jul 14, 2020
frangio added a commit to frangio/openzeppelin-contracts that referenced this pull request Jul 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider switching Address.isContract back to extcodesize
2 participants