Is my implementation contract initializable?
With regards to initializing the implementation contract, within my initialize function, I have these functions and modifiers:
function initialize(
address _contractOwner
) external initializer {
__Ownable_init();
_initializeEIP712();
...
}
// supposed to be called once while initializing.
// one of the contracts that inherits this contract follows proxy pattern
// so it is not possible to do this in a constructor
function _initializeEIP712() internal initializer {
_setDomainSeperator();
}
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
Since there is _initializeEIP712() which also includes an initialize modifier, I cannot call initialize on an already deployed implementation contract. Would that mean that my implementation contract is protected and a malicious actor will be unable to initialize the implementation contract?
Additional context: I tried initializing the implementation contract (currently initialized==0), but I receive an error message of 'Initializable: contract is already initialized' when I try to initialize the implementation contract (for security purposes). I believe that it is due to having _initializeEIP712(); within the initialize function.
From my understanding this is the reason why the implementation contract above will not be initializable.
-
The first initialize will have
(isTopLevelCall && _initialized < 1)
as true since it is a top level call and initialized is 0. -
And the second initialize within
_initializeEIP712()
will return the error "Initializable: contract is already initialized" because it is not true for both cases (since the implementation contract is deployed and isContract(address(this)) will return true.
Note: The proxy can be deployed and initialized using hardhat upgrades.deployProxy()
just that the implementation contract cannot be initialized.
Some kind inputs from the experts here will be helpful. Thanks.