Changing a variables scope with UUPS

Is there a safe way to change the scope of a variable, without affecting the memory layout in an unsafe way?

For example, say I wanted to make the ERC721's _balances and _owners variables internal rather than private, so that an upgrade can make a more efficient batchMint.

If I try this directly by just re-declaring the variable in the child class as internal, OpenZeppelin's "assertStorageUpgradeSafe" throws "Deleted . Keep variable even if unused".

In my case, I'm not trying to delete it, just open up its accessibility

Hello @Carson_Roscoe

There is no way to change the scope of a variable from a child contract. Declaring a variable with the same name in a child contract will not overlap, and removing it from the parent is will change the layout.

You could modify the parent contract, change the scope there, and then use that in a child contract.

You could also use overriding to try alter the contract without accessing the core storage, but that is generally more difficult to pull of. This is a PR that stated this work, but is not yes ready

1 Like