0

If i use UUPS upgradeable pattern and i define a couple of constants, enums and structs at the contract level, will those values still be available after an upgrade?

I have 3 contracts and all 3 are upgradable. In contract 1 i have a couple of constants, enum and struct which are used in both contract 2 and 3.

I noticed that the contract size is way smaller if i define these at contract level and use those as it is, instead of the generated public getters. However i am not sure if these values still going to be available after an upgrade on any of my contracts.

Contract 1:

uint256 constant CONSTANT_ONE = 1;
uint256 constant CONSTANT_TWO = 2;

enum Tiers {
    Hey,
    Howdy,
    Hello
}

struct MyStruct {
    uint256 myUint256;   
}

contract Contrcat1 is Initializable, ERC1155Upgradeable, AccessControlUpgradeable, UUPSUpgradeable {

 // constants enum and struct used here

}

Contract 2

import "./Contract1.sol";

contract Contract2 is Initializable, AccessControlUpgradeable, UUPSUpgradeable {

// use the constants, enum and struct here from Contract 1

}

Contract 3

import "./Contract1.sol";

contract Contract3 is Initializable, AccessControlUpgradeable, UUPSUpgradeable {

// use the constants, enum and struct here from Contract 1

}

So my question is if these file level definitions are compatible with upgrades or not?

Thank you in advance

2 Answers 2

0

Interesting question. As far as i know, in UUPS, logic of upgrading is in the implementation and the state is in the proxy. So your constants state is in the proxy, therefore even if you upgrade contract 1, contract 2 and contract 3 will get the state fron the proxy. My response is relying on my understanding, i did not test that. Btw, you should declare all 3 contracts as upgradable.

0

No, when utilizing the UUPS upgradeable pattern, any definitions made at the file level, such as constants, enums, and structs within a contract, will not endure across upgrades.

When performing an upgrade using the UUPS pattern, the existing contract instance gets replaced by a new one. The new contract instance possesses its own storage arrangement, and the state variables from the previous contract instance do not carry over automatically.

Consequently, if you have defined constants, enums, and structs at the contract level and rely on their values in other contracts, you must ensure that you appropriately manage these definitions during the upgrade procedure.

One approach to managing this is to store the necessary values within storage variables within the contract, rather than depending on file-level definitions. This way, the values will persist during the upgrade, allowing you to access them from the upgraded contract.

Alternatively, you have the option to store these shared values in a separate storage contract or utilize an external data source to retrieve them within your upgraded contracts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.