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

Use extcodehash instead of extcodesize #135

Closed
abhi3700 opened this issue Nov 16, 2021 · 2 comments
Closed

Use extcodehash instead of extcodesize #135

abhi3700 opened this issue Nov 16, 2021 · 2 comments

Comments

@abhi3700
Copy link

🧐 Motivation
This is for saving gas by 300 unit.

📝 Details
The extcodesize uses 300 gas more than extcodehash to determine whether or not an address is a contract. Hence, this is pertaining to that.

This line-27 refers to the isContract function in AddressUpgradeable.sol file. This function is supposed to modified to this:

function isContract(address account) public view returns (bool) {
    bytes32 hash;
    assembly {
        hash := extcodehash(account)
    }
    return (hash != 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470);
}
@Amxx
Copy link
Collaborator

Amxx commented Nov 16, 2021

Hello @abhi3700

I think this is a really interesting proposal. It should however be done on the @openzeppelin-contracts repository. Can you please open an issue there?

@frangio
Copy link
Contributor

frangio commented Nov 16, 2021

See OpenZeppelin/openzeppelin-contracts#1802 (comment). We used extcodehash in the past but went back to extcodesize as it was shown to be more efficient. If this is no longer the case please open another issue.

@frangio frangio closed this as completed Nov 16, 2021
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

No branches or pull requests

3 participants