Skip to content

feat: use extcodesize for isContract to reduce gas#2311

Merged
frangio merged 2 commits intoOpenZeppelin:masterfrom
julianmrodri:feat/use-extcodesize-#2310
Jul 14, 2020
Merged

feat: use extcodesize for isContract to reduce gas#2311
frangio merged 2 commits intoOpenZeppelin:masterfrom
julianmrodri:feat/use-extcodesize-#2310

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.

@julianmrodri julianmrodri force-pushed the feat/use-extcodesize-#2310 branch from ff38178 to 35ea6ea Compare July 14, 2020 19:24
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