Skip to content

Commit

Permalink
feat: use extcodesize for isContract to reduce gas
Browse files Browse the repository at this point in the history
  • Loading branch information
julianmrodri committed Jul 13, 2020
1 parent 98e862e commit f2d0304
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions contracts/utils/Address.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ library Address {
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// This method relies in extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.

uint256 size;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
assembly { size := extcodesize(account) }
return size > 0;
}

/**
Expand Down

0 comments on commit f2d0304

Please sign in to comment.