Using extcodehash instead of extcodesize for less gas (#1802)

* Using extcodehash instead of extcodesize for less gas

`extcodehash` uses less gas then `extcodesize`. You can tell which address is a contract by the hash (see EIP-1052).

* Fix

* Add explainer

* Update Address.sol

* add changelog entry
This commit is contained in:
Philippe Castonguay
2019-07-08 12:41:55 -04:00
committed by Francisco Giordano
parent c9f328ef66
commit 0282c3608d
2 changed files with 13 additions and 4 deletions

View File

@ -18,11 +18,15 @@ library Address {
// 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;
// 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;
// solhint-disable-next-line no-inline-assembly
assembly { size := extcodesize(account) }
return size > 0;
assembly { codehash := extcodehash(account) }
return (codehash != 0x0 && codehash != accountHash);
}
/**