1

Initializable.sol provides an initializer modifier and a _disableInitializers() internal function. I need help in understanding why a _disableInitializers() might be needed if we already have a modifier which prevents the initializer function from being re-invoked.

Does this mean that the initializer function can be re-invoked in subsequent upgrades in the contract and this internal function prevents that?

Furthermore, the contract also provides a reinitializer(uint8 version) modifier. Is this supposed to be used if we are trying to initialize an upgrade contract on the older contract?

2 Answers 2

5

So I searched about it and tried these out.

And it basically is something like reinitializer(1) = initializer. You need to use reinitializer() in subsequent upgrades. _disableInitializer() just max out the version so it's not possible to again invoke any initializer.

I have summarised my findings in this blog post: https://abhik.hashnode.dev/6-nuances-of-using-upgradeable-smart-contracts

0
1

_disableInitializers() is called inside the constructor. This is done so that in the context of the logic contract the initializer is locked. Therefore any attacker will not able to call the initalizer() function in the state of the logic contract and perform any malicious activity. Note that the proxy contract state will still be able to call this function, this is because the constructor does not effect the state of the proxy contract. Hope this helps.

2
  • But if initializer modifier is used on the initializer function, that itself prevents execution of the said function post deployment. So what the use of having another _disableInitializers() if the initializer function cannot be re-executed post deployment with the modifier? Commented Jul 8, 2022 at 20:18
  • initializer modifier can be used one time, and then subsequent attempts will revert Commented Jun 1, 2023 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.