Proxy contracts and storage variables

Hi everyone.

I’m working with some contracts that needs to use Transparent Proxies in order to upgrade them. I read a few tutorials but i still have some doubts.

1-¿How can i be sure that the new contract will not broke Proxy’s storage?¿It’s really necesary for the New-Logic-contract to inherit the Old-Logic-contract for this to work or it’s enough with maintaining the exact same variables in the new one?
2- ¿Is there any condition on adding new variables in the New-Logic-Contract that could break the old storage?

Thanks.

Hey Alexander! Thanks for joining the forum!

I’m afraid I don’t know the answer to your question, so hopefully @spalladino can help you :slight_smile:

1 Like

Thanks @IvanTheGreatDev, and welcome @AlexanderPoschenried!

It is not mandatory to extend from the original logic contract. If you make sure to keep the same variables on the same order, you are good to go. You can read here for more info.

If you add new variables inbetween existing ones, then you will probably break the old storage. You should only be adding new variables at the end of the storage.

Keep in mind that this rule applies to the storage as a whole: if you are extending from another contract, your storage is the base contract storage plus your child contract storage.

For instance, in the following example, your storage will actually be a,b,c,d. This means you can only add new variables after d.

contract Base { uint a; uint b; }
contract Child is Base { uint c; uint d; }

Still, if you are using the zos CLI for uploading your contracts, it will perform an automatic check to make sure that the two storage layouts are compatible. And it is also a good practice to test your upgrade locally before running it on production.

Hope this helps!

2 Likes

Thanks Santiago!!

I suspected that the main thing was to maintain variables order, but i wanted to make sure.

Still, if you are using the zos CLI for uploading your contracts, it will perform an automatic check to make sure that the two storage layouts are compatible.

I didn’t know this. Another point to start using Zos.

Thanks again.