Ver código fonte

Remove _isConstructor() check in initializer modifier (#2531)

* Remove _isConstructor() check in initializer modifier

* add changelog entry
Francisco Giordano 4 anos atrás
pai
commit
0059b17dfc
2 arquivos alterados com 2 adições e 6 exclusões
  1. 1 0
      CHANGELOG.md
  2. 1 6
      contracts/proxy/Initializable.sol

+ 1 - 0
CHANGELOG.md

@@ -9,6 +9,7 @@
  * `EnumerableMap`: change implementation to optimize for `key → value` lookups instead of enumeration. ([#2518](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2518))
  * `GSN`: Deprecate GSNv1 support in favor of upcomming support for GSNv2. ([#2521](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2521))
  * `ERC165`: Remove uses of storage in the base ERC165 implementation. ERC165 based contracts now use storage-less virtual functions. Old behaviour remains available in the `ERC165Storage` extension. ([#2505](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2505))
+ * `Initializable`: Make initializer check stricter during construction. ([#2531](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2531))
 
 ## 3.4.0 (2021-02-02)
 

+ 1 - 6
contracts/proxy/Initializable.sol

@@ -33,7 +33,7 @@ abstract contract Initializable {
      * @dev Modifier to protect an initializer function from being invoked twice.
      */
     modifier initializer() {
-        require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized");
+        require(_initializing || !_initialized, "Initializable: contract is already initialized");
 
         bool isTopLevelCall = !_initializing;
         if (isTopLevelCall) {
@@ -47,9 +47,4 @@ abstract contract Initializable {
             _initializing = false;
         }
     }
-
-    /// @dev Returns true if and only if the function is running in the constructor
-    function _isConstructor() private view returns (bool) {
-        return !Address.isContract(address(this));
-    }
 }