فهرست منبع

Revert "feat: use extcodesize for isContract to reduce gas (#2311)"

This reverts commit c801c8d2bbaeeab413fc792ae0d44f720fb81bc9.
Francisco Giordano 5 سال پیش
والد
کامیت
4eb8d2bb10
2فایلهای تغییر یافته به همراه7 افزوده شده و 12 حذف شده
  1. 0 5
      CHANGELOG.md
  2. 7 7
      contracts/utils/Address.sol

+ 0 - 5
CHANGELOG.md

@@ -1,10 +1,5 @@
 # Changelog
 
-## 3.1.1 (Unreleased)
-
-### Improvements
- * `Address.isContract`: switched from `extcodehash` to `extcodesize` for less gas usage. ([#2311](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2311))
-
 ## 3.1.0 (2020-06-23)
 
 ### New features

+ 7 - 7
contracts/utils/Address.sol

@@ -24,14 +24,14 @@ library Address {
      * ====
      */
     function isContract(address account) internal view returns (bool) {
-        // 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 != accountHash && codehash != 0x0);
     }
 
     /**