Constructor() initializer {} Inclusion

I am developing an Upgradeable ERC721 Smart Contract (with a TransparentUpgradeableProxy), starting with a template generated by the Contracts Wizard found at the following link.

My Contract was build using Solidity Version ^0.8.0. I have noticed that the template, which currently uses Version 0.8.2 adds the following line of code immediately below the contract creation:

constructor() initializer {}

I had initially generated my template on the site referenced above a little while ago. I hadn't noticed this line of code at the time. Was this added recently? If I include the line, I obtain an error while compiling, stating that my Contract is not upgradeable safe since it contains a Constructor. What is the exact purpose of this line (I thought that the Contract was initialised with the subsequent function)? Finally, I have noticed that the OpenZeppelin Upgradeable Contracts are still using Solidity Version 0.8.0, while the Wizard generates the code with pragma solidity ^0.8.2;. Should I use this version of Solidity or can I continue to use version 0.8.0 to compile my Contract?

Thank you. J


It has to do with a recent potential vulnerability found in UUPS style upgrades. If you had used the Wizard before a few weeks ago, it probably didn't appear, as this vulnerability was found recently. Happy to answer more specific questions, but reading here for an explanation will probably do the issue more justice.

1 Like

Thank you @0xLostArchitect

It's necessary to also include the comment above that says /// @custom:oz-upgrades-unsafe-allow constructor.

1 Like