Upgrading + calling initialization data

Hi Team,

I am using OZ's UpgradableProxies.. UUPS one..

proxy => logic and logic contains initialize function that when proxy gets deployed, it immediatelly calls initialize ! as for the security measures, initialize function on the logic is protected by initializer that comes from OZ's Initializable

Now, let's say I want to update the contract. It at first glance, seems so easy. one writes another logic contract(v2), deploys it and then calls proxy's upgradeTo and passes this. But Imagine that v2 also needs initialization. There're 2 choices.

  1. v2 logic's creator writes initialize2 function in it and when it's time to upgrade, he calls upgradeToAndCall on the proxy with the new logic address and initialize2's calldata. Question 1: If I add initializer modifier to this initialize2 function, upgradeToAndCall won't still be able to call it as v1's initialize already set that boolean as true. Any ideas ?
  2. Or user updates v1's initialize function's body in the v2(possibly changing arguments as well). Now, Problem I am looking at is this initialize won't be able to be called, because it's protected by initializer and when proxy first called it for v1, it set the boolean as true ! Question 2: how can the same initialize function be called while upgrading contracts only ? i understand that other than upgrading, it should be protected to not be called, but question relies only for upgrading.

I'd appreciate both cases/scenarios explanation as this is very critical to be solved.

Thank you.

@novaknole Please make sure to post in #support so we don't miss your question. I've moved your post.

Recent versions of OpenZeppelin Contracts include a new reinitializer modifier that is designed specifically for the scenario you're describing. Check out the documentation for Initializable to learn more!

Thanks a lot @frangio

I have seen it ! but can it be applied on the initialize function ? Seem like I can't allow users to bring initializeV2 function or any other ones. The name of the function should always be update and they might just forget to include reinitializer on it. This makes me believe that this solution mightn't work.

I went ahead and brought my parameter on the very specific slot and it's boolean. It only gets changed when the update happen(I also override the OZ's function 'upgradeToAndCall` in order to also add my logic that changes this boolean).

So without this, i think i got no choice with only reinitializer because this should be inforced(as in uers might forget to include modifers at all by themselves).

Thoughts ?

Sorry I'm not sure I understand the situation. Who are the users you are talking about? Please provide some Solidity code snippets as they might help.