openzeppelin-contracts icon indicating copy to clipboard operation
openzeppelin-contracts copied to clipboard

Consider simpler initializer modifier

Open frangio opened this issue 2 years ago • 1 comments

The current version of the initializer modifier includes some logic for backwards compatibility that was added in #3450, which was in fact a simplification of the backwards compatibility code introduced in #3344.

We should consider further simplifications that break backwards compatibility for 5.0.

Haven't thought about this yet but it would probably come down to making initializer exactly equivalent to reinitializer(1). This means that instead of:

https://github.com/OpenZeppelin/openzeppelin-contracts/blob/d59306bd06a241083841c2e4a39db08e1f3722cc/contracts/proxy/utils/Initializable.sol#L85-L88

the code should look more like:

https://github.com/OpenZeppelin/openzeppelin-contracts/blob/d59306bd06a241083841c2e4a39db08e1f3722cc/contracts/proxy/utils/Initializable.sol#L119

frangio avatar Jan 11 '23 22:01 frangio

Note: In https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3344 it is explained that the isConstructor exception was added back (after removal in 4.0) in order to use the initializer modifier to disable the initialization of implementation contracts with the following pattern:

contract A is Initializable {
    constructor() initializer { /* ... */ }
}

contract B is A {
    constructor() initializer { /* ... */ }
}

This is no longer a requirement since the introduction of _disableInitializers.

frangio avatar Feb 23 '23 01:02 frangio

@frangio is this open for a PR or just a suggestion citing Consider?

balajipachai avatar Jun 09 '23 08:06 balajipachai

Consider means undecided.

frangio avatar Jun 09 '23 21:06 frangio

Okay 👍

balajipachai avatar Jun 10 '23 02:06 balajipachai