I'm trying to understand why no one can call initialize function in a UUPS implementation contract directly. So this fucntion has an initializer modifier that look like this
modifier initializer() {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
// Cache values to avoid duplicated sloads
bool isTopLevelCall = !$._initializing;
uint64 initialized = $._initialized;
// Allowed calls:
// - initialSetup: the contract is not in the initializing state and no previous version was
// initialized
// - construction: the contract is initialized at version 1 (no reininitialization) and the
// current contract is just being deployed
bool initialSetup = initialized == 0 && isTopLevelCall;
bool construction = initialized == 1 && address(this).code.length == 0;
if (!initialSetup && !construction) {
revert InvalidInitialization();
}
$._initialized = 1;
if (isTopLevelCall) {
$._initializing = true;
}
_;
if (isTopLevelCall) {
$._initializing = false;
emit Initialized(1);
}
}
When I try calling the function directly I get the InvalidInitialization() error. Ok... let's look at the code and try to understand why...
InitializableStorage storage $ = _getInitializableStorage();
returns a struct with uint64 and a boolean which should be 0 and false by default right?
so the next 2 lines
bool isTopLevelCall = !$._initializing;
uint64 initialized = $._initialized;
should be true and 0
but they are not judging by the revert error.... Could you explain please, it seems like I'm missing the point that I don't know about or sth. Thanks