Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Error: Define an initializer function and use it to call the initializers of parent contracts #1125

Open
vladimir-trifonov opened this issue Feb 11, 2025 · 6 comments

Comments

@vladimir-trifonov
Copy link

I get

      test/contracts/xxxV2.sol:20: Missing initializer
          Define an initializer function and use it to call the initializers of parent contracts
          https://zpl.in/upgrades/error-001

when I try to upgrade from v1 to v2 of the smart contract. This error happens when

npx @openzeppelin/upgrades-core@^1.42.0 validate out/build-info --contract test/contracts/xxxV2.sol:xxxV2 --requireReference

is executed.
I didn't have this error with @openzeppelin/upgrades-core v1.41.0.

My v2 initializer:

function initializeV2() public reinitializer(2) {}
@viraj124
Copy link

hey @vladimir-trifonov I am getting a similar issue #1124, do you remember which version of the @openzeppelin/hardhat-upgrades package did @openzeppelin/upgrades-core v1.41.0 pointed too ?

@vladimir-trifonov
Copy link
Author

vladimir-trifonov commented Feb 11, 2025

hey @vladimir-trifonov I am getting a similar issue #1124, do you remember which version of the @openzeppelin/hardhat-upgrades package did @openzeppelin/upgrades-core v1.41.0 pointed too ?

I was having the same issue as you before, but I removed the

function initialize

in the upgraded contract, because either way, I don't need it.

But this current issue is breaking the upgrade altogether.
But you're right, there is some issue with those initializers going on.

@viraj124
Copy link

hmm I had initialize defined before and it was working fine but for some reason now it doesn't since last week or so which is super weird

@ericglau
Copy link
Member

We added checks to detect issues in parent initializer calls in @openzeppelin/upgrades-core@1.42.0. In your scenario, since you are upgrading and if you don't need an initializer in your upgraded contract, you can skip the missing-initializer check.

From Foundry:

Options memory opts;
opts.unsafeAllow = "missing-initializer";
Upgrades.upgradeProxy(proxy, "MyContractV2.sol", data, opts);

From Hardhat:

await upgrades.upgradeProxy(proxyAddress, MyContractV2, {
  unsafeAllow: ['missing-initializer'],
});

We may consider fixing the plugin to skip this by default when upgrading.

@vladimir-trifonov
Copy link
Author

I saw this missing-initializer check, but I didn't want to use it since I have initializer in my upgraded contract e.g.:

function initializeV2() public reinitializer(2) {
 ...
}

@ericglau
Copy link
Member

The plugin currently doesn't validate reinitializers, but we may add #1122 to allow you to specify that your initializeV2 function is the initializer that should be validated.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants