# What does \`\_disableInitializers();\` function mean?

**URL:** <https://forum.openzeppelin.com/t/what-does-disableinitializers-function-mean/28730>\
**Category:** Upgrades\
**Created:** [May 15, 2022, 6:47pm UTC](https://forum.openzeppelin.com/t/what-does-disableinitializers-function-mean/28730 "2022-05-15T18:47:12Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![migbash](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/migbash/32/14730_2.png) [@migbash](https://forum.openzeppelin.com/u/migbash)\
**Post date:** [May 15, 2022, 6:47pm UTC](https://forum.openzeppelin.com/t/what-does-disableinitializers-function-mean/28730/1 "2022-05-15T18:47:12Z")

</div>

I couldn't find anywhere the meaning of the use of the `_disableInitializers();` for the `upgradeability` aspect of an `ERC-20` token creation...

 ![image](https://us1.discourse-cdn.com/flex022/uploads/zeppelin/original/2X/7/723335c7f4c604a0196f919d0407ad51136c4cb2.png)

what does it mean ?

Also, why does the `OpenZeppelin` Documentation says to do the following instead ? :

 ![image](https://us1.discourse-cdn.com/flex022/uploads/zeppelin/original/2X/e/e2163214d90ed0295591ff759914058cb22f737f.png)

I am confused on what is meant to be done to get the `upgradability working`

#### 💻 Environment

`wizard` OpenZeppelin Interfac

---

<div class="post-metadata">

**Author:** ![ericglau](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/ericglau/32/15149_2.png) [@ericglau](https://forum.openzeppelin.com/u/ericglau)\
**Post date:** [May 16, 2022, 4:56pm UTC](https://forum.openzeppelin.com/t/what-does-disableinitializers-function-mean/28730/2 "2022-05-16T16:56:03Z")

</div>

Hi @migbash,

[`_disableInitializers()`](https://docs.openzeppelin.com/contracts/4.x/api/proxy#Initializable-_disableInitializers--) was added in Contracts v4.6.0 as part of the reinitializers support. The Caution note in [`Initializer`](https://docs.openzeppelin.com/contracts/4.x/api/proxy#Initializable) provides more details on why this is needed.

By putting it in the constructor, this prevents initialization of the **implementation** contract itself, as extra protection [to prevent an attacker from initializing it](https://forum.openzeppelin.com/t/uupsupgradeable-vulnerability-post-mortem/15680).

Thank you for mentioning the difference with the upgrades documentation. The `contructor() initializer {}` usage was recommended for previous version of Contracts. I've opened an [issue](https://github.com/OpenZeppelin/openzeppelin-upgrades/issues/574) to update the upgrades documentation to refer to `_disableInitializers()`.

---

<div class="post-metadata">

**Author:** ![QiLOL](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/qilol/32/19655_2.png) [@QiLOL](https://forum.openzeppelin.com/u/QiLOL)\
**Post date:** [November 3, 2023, 5:24am UTC](https://forum.openzeppelin.com/t/what-does-disableinitializers-function-mean/28730/3 "2023-11-03T05:24:32Z")

</div>

Hello @ericglau , just curious if we can still use `constructor() initializer{}` to prevent the implementation contract initialization issue after 4.6.0?

---

<div class="post-metadata">

**Author:** ![ericglau](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/ericglau/32/15149_2.png) [@ericglau](https://forum.openzeppelin.com/u/ericglau)\
**Post date:** [November 3, 2023, 12:41pm UTC](https://forum.openzeppelin.com/t/what-does-disableinitializers-function-mean/28730/4 "2023-11-03T12:41:16Z")

</div>

@QiLOL It is recommended to use `_disableInitializers()` so that the implementation cannot be initialized to any version.

If you use `constructor() initializer{}`, you can see that the [`initializer` modifier](https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/v4.9.3/contracts/proxy/utils/Initializable.sol#L84) only sets the `_initialized` version to 1, meaning that it could still be possible for the implementation to be reinitialized to a higher version number (if the implementation had a way to do so).

---

<div class="post-metadata">

**Author:** ![QiLOL](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/qilol/32/19655_2.png) [@QiLOL](https://forum.openzeppelin.com/u/QiLOL)\
**Post date:** [November 3, 2023, 2:26pm UTC](https://forum.openzeppelin.com/t/what-does-disableinitializers-function-mean/28730/5 "2023-11-03T14:26:52Z")

</div>

@ericglau I see, thank you!

---

<div class="post-metadata">

**Author:** ![tibas](https://avatars.discourse-cdn.com/v4/letter/t/3ec8ea/32.png) [@tibas](https://forum.openzeppelin.com/u/tibas)\
**Post date:** [November 6, 2023, 7:54am UTC](https://forum.openzeppelin.com/t/what-does-disableinitializers-function-mean/28730/6 "2023-11-06T07:54:03Z")

</div>

@ericglau could you please elaborate on your answer?

Can a logic contract contain both \_disableInitializer constructor and initialize function?

What will be the impact of this?

Because from the Openzeppelin doc, constructor shouldn't be used anymore if the initialize function is in use.

---

<div class="post-metadata">

**Author:** ![ericglau](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/ericglau/32/15149_2.png) [@ericglau](https://forum.openzeppelin.com/u/ericglau)\
**Post date:** [November 6, 2023, 1:49pm UTC](https://forum.openzeppelin.com/t/what-does-disableinitializers-function-mean/28730/7 "2023-11-06T13:49:25Z")

</div>

@tibas To summarize, the implementation contract (logic contract) should look similar to the first post. It makes sense to have a both \_disableInitializer constructor and initialize function. The constructor is to disable the **implementation** contract from being initialized, while the initializer function is to allow the **proxy** to be initialized.

---

<div class="post-metadata">

**Author:** ![tibas](https://avatars.discourse-cdn.com/v4/letter/t/3ec8ea/32.png) [@tibas](https://forum.openzeppelin.com/u/tibas)\
**Post date:** [November 6, 2023, 2:21pm UTC](https://forum.openzeppelin.com/t/what-does-disableinitializers-function-mean/28730/8 "2023-11-06T14:21:10Z")

</div>

Thank you for the explanation, @ericglau.

---

<div class="post-metadata">

**Author:** ![ska123](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/ska123/32/19289_2.png) [@ska123](https://forum.openzeppelin.com/u/ska123)\
**Post date:** [November 6, 2023, 9:56pm UTC](https://forum.openzeppelin.com/t/what-does-disableinitializers-function-mean/28730/9 "2023-11-06T21:56:20Z")

</div>

Hello, If we are updating the implementation contract (i.e. using `implementationV1.upgradeTo(address(implementationV2))`) is it still true that we need both the constructor with \_disableInitializer AND the initialize function?

I'm little confused here because when running proxy.upgradeTo() function like above, it does not run the initialize function in the V2 implementation (when \_disableInitializer is present in the constructor).

---

<div class="post-metadata">

**Author:** ![ericglau](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/ericglau/32/15149_2.png) [@ericglau](https://forum.openzeppelin.com/u/ericglau)\
**Post date:** [November 6, 2023, 10:09pm UTC](https://forum.openzeppelin.com/t/what-does-disableinitializers-function-mean/28730/10 "2023-11-06T22:09:47Z")

</div>

@ska123 If the implementationV2 is only meant to be used for an upgrade (meaning you will not be deploying a new proxy with V2 directly), then you are right that you don't need an initializer in V2. You may want to have a reinitializer though to act as a migration function (if your contract needs it), and call that using `upgradeToAndCall()` so it is called atomically with the upgrade.

---

<div class="post-metadata">

**Author:** ![ska123](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/ska123/32/19289_2.png) [@ska123](https://forum.openzeppelin.com/u/ska123)\
**Post date:** [November 6, 2023, 10:24pm UTC](https://forum.openzeppelin.com/t/what-does-disableinitializers-function-mean/28730/11 "2023-11-06T22:24:56Z")

</div>

Ah ok, perfect. Thank you!

---

<div class="post-metadata">

**Author:** ![ericglau](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/ericglau/32/15149_2.png) [@ericglau](https://forum.openzeppelin.com/u/ericglau)\
**Post date:** [November 7, 2023, 11:15pm UTC](https://forum.openzeppelin.com/t/what-does-disableinitializers-function-mean/28730/13 "2023-11-07T23:15:45Z")

</div>

@ska123 I don't understand your question. Can you provide more detail on what you are trying to achieve and some minimal code examples?

---

<div class="post-metadata">

**Author:** ![eeshenggoh](https://avatars.discourse-cdn.com/v4/letter/e/8dc957/32.png) [@eeshenggoh](https://forum.openzeppelin.com/u/eeshenggoh)\
**Post date:** [December 29, 2023, 12:29pm UTC](https://forum.openzeppelin.com/t/what-does-disableinitializers-function-mean/28730/14 "2023-12-29T12:29:12Z")

</div>

> [@ericglau](#):
>
> [`_disableInitializers()`](https://docs.openzeppelin.com/contracts/4.x/api/proxy#Initializable-_disableInitializers--)

Are we only supposed to add the \_disableInitializers for UUPS Upgradable Implementations??

```auto
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
    _disableInitializers();
}

```

---

<div class="post-metadata">

**Author:** ![ericglau](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/ericglau/32/15149_2.png) [@ericglau](https://forum.openzeppelin.com/u/ericglau)\
**Post date:** [January 8, 2024, 3:18pm UTC](https://forum.openzeppelin.com/t/what-does-disableinitializers-function-mean/28730/15 "2024-01-08T15:18:33Z")

</div>

> [@eeshenggoh](#):
>
> Are we only supposed to add the \_disableInitializers for UUPS Upgradable Implementations??
> 
> ```auto
> /// @custom:oz-upgrades-unsafe-allow constructor
> constructor() {
> _disableInitializers();
> }
> 
> ```

It is recommended to add that for implementations regardless of what type of proxy they are used with.

---

<div class="post-metadata">

**Author:** ![eeshenggoh](https://avatars.discourse-cdn.com/v4/letter/e/8dc957/32.png) [@eeshenggoh](https://forum.openzeppelin.com/u/eeshenggoh)\
**Post date:** [January 9, 2024, 1:30am UTC](https://forum.openzeppelin.com/t/what-does-disableinitializers-function-mean/28730/16 "2024-01-09T01:30:42Z")

</div>

Can you explain why do we need them for proxies that are not UUPS? Most contracts only include `_disableIntiialziers()` if the implementation only interacts with UUPS.

---

<div class="post-metadata">

**Author:** ![ericglau](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/ericglau/32/15149_2.png) [@ericglau](https://forum.openzeppelin.com/u/ericglau)\
**Post date:** [January 9, 2024, 3:13pm UTC](https://forum.openzeppelin.com/t/what-does-disableinitializers-function-mean/28730/17 "2024-01-09T15:13:58Z")

</div>

It isn't strictly needed, but it is _recommended_ as a best practice.

The original motivation for disabling initializers was to have an extra layer of security related to [UUPSUpgradeable Vulnerability Post-mortem](https://forum.openzeppelin.com/t/uupsupgradeable-vulnerability-post-mortem/15680).

But doing this also has the benefit of preventing users from using the implementation directly, and helps prevent others from overtaking the implementation in general (there is more risk for UUPS since UUPS has the upgrade logic in the implementation so you really don't want someone to overtake it, but in general the risk depends on your code).

---

<div class="post-metadata">

**Author:** ![viki\_viki](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/viki_viki/32/21164_2.png) [@viki\_viki](https://forum.openzeppelin.com/u/viki_viki)\
**Post date:** [June 29, 2024, 12:57pm UTC](https://forum.openzeppelin.com/t/what-does-disableinitializers-function-mean/28730/18 "2024-06-29T12:57:24Z")

</div>

Hey ericglau,

is there any examples on how to use **\_disableInitializers** on proxies other than UUPS ?

---

<div class="post-metadata">

**Author:** ![ericglau](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/ericglau/32/15149_2.png) [@ericglau](https://forum.openzeppelin.com/u/ericglau)\
**Post date:** [July 2, 2024, 5:31pm UTC](https://forum.openzeppelin.com/t/what-does-disableinitializers-function-mean/28730/19 "2024-07-02T17:31:54Z")

</div>

@viki_viki The recommended way is to use it in the implementation contract as described above, regardless of the kind of proxy.

See [https://wizard.openzeppelin.com/](https://wizard.openzeppelin.com/) and enable Upgradeability for some examples.

---

<div class="post-metadata">

**Author:** ![Mylifechangefast.eth](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/mylifechangefast.eth/32/18973_2.png) [@Mylifechangefast.eth](https://forum.openzeppelin.com/u/Mylifechangefast.eth)\
**Post date:** [November 1, 2024, 10:10am UTC](https://forum.openzeppelin.com/t/what-does-disableinitializers-function-mean/28730/20 "2024-11-01T10:10:45Z")

</div>

I'm working on an upgradeable Solidity contract and I'm encountering an issue with reinitialization. I've used `_disableInitializers()` in my constructor to prevent accidental reinitialization, but I'm still seeing my `initialize()` function being called multiple times during contract upgrades. I've also defined an `initializeV2()` function with the initializer modifier. Can you please explain why `initialize()` is being called multiple times and how I can prevent this?

@ericglau

---

<div class="post-metadata">

**Author:** ![Skyge](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/skyge/32/343_2.png) [@Skyge](https://forum.openzeppelin.com/u/Skyge)\
**Post date:** [November 2, 2024, 7:33am UTC](https://forum.openzeppelin.com/t/what-does-disableinitializers-function-mean/28730/21 "2024-11-02T07:33:52Z")

</div>

> [@Mylifechangefast.eth](#):
>
> I've used `_disableInitializers()` in my constructor to prevent accidental reinitialization,

I think the modifier `_disableInitializers ` is used to avoid leaving an implementation contract uninitialized, such as:

```auto
constructor() {
   _disableInitializers();
}

```

so then your implementation contract can not be initialized, that is you can not call a function which has a modifier `initializer` in the implementation contract, such as

```auto
function initialize() public initializer() {
    xxx;
}

```

When you upgrade your contract, you can use the modifier `reinitializer(version)`, such as

```auto
function migrateToV2() public reinitializer(2) {
  xxx;

```

[Next page](https://forum.openzeppelin.com/t/what-does-disableinitializers-function-mean/28730.md?page=2)
