From 0059b17dfc1e2226ca1a1c3b5e7a56817c32d47d Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Thu, 18 Feb 2021 20:53:00 -0300 Subject: [PATCH] Remove _isConstructor() check in initializer modifier (#2531) * Remove _isConstructor() check in initializer modifier * add changelog entry --- CHANGELOG.md | 1 + contracts/proxy/Initializable.sol | 7 +------ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92e20f3ad06..5e121b33df6 100644 --- a/CHANGELOG.md +++ b/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) diff --git a/contracts/proxy/Initializable.sol b/contracts/proxy/Initializable.sol index 3f0e3c9b95b..05c3b4f7034 100644 --- a/contracts/proxy/Initializable.sol +++ b/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)); - } }