Defining structs like 'Snapshots' is not yet supported when deploying ERC20SnapshotUpgradeable

Hi all,

We are trying to write a deploy script using hardhat upgrades plugin and we see this error

@openzeppelin/contracts-upgradeable/token/ERC20/ERC20SnapshotUpgradeable.sol:52 Defining structs like 'Snapshots' is not yet supported. If you have manually checked for storage layout compatibility, you can skip this check with the 'unsafeAllowCustomTypes' flag
https://zpl.in/upgrades/error-007

How can we manually check for for this and make sure we maintain storage layout between upgrades?

The contract:

Thanks!

1 Like

In this case, since the struct is a part of @openzeppelin/contracts-upgradeable, we're the ones that will make sure to maintain storage compatibility.

We mention this briefly in Using with Upgrades:

a separate package called @openzeppelin/contracts-upgradeable [...] we check for storage incompatibilities across minor versions.

This is something we could consider though, we can ignore the error if it originates in our own package.

You will need to add the unsafeAllowCustomTypes flag for now. Keep in mind this will also silence errors from other structs that you add and that you will have to check.

In that case you would have to make sure to follow all the rules for changing state variables that are explained in Writing Upgradeable Contracts, with an additional rule that I just realized isn't in the document that I will add now. I don't think you will need it for now so I won't explain it for now.

1 Like

Here’s two issues I opened about this in case you want to subscribe.

2 Likes

Thanks for the answer.

I would suggest having an AllowCustomTypeInContracts whitelist in the plugin instead of all or nothing. It would make easier to not screw up in the future in other contracts.

1 Like

Hi @ethicraul,

Thanks for the suggestion. :pray:

I added this to https://github.com/OpenZeppelin/openzeppelin-upgrades/issues/248#issuecomment-739639999

1 Like

Hi @ethicraul,

We have found an error in Upgrades Plugins for Truffle and Hardhat. Users of the flag unsafeAllowCustomTypes should update their dependencies to the latest version.

See post for more details: Problem in Upgrades Plugins for users of unsafeAllowCustomTypes.

1 Like

Thanks, that was close :sweat_smile:

1 Like

@ethicraul The latest release of the Upgrades plugin supports structs, and the unsafe flag is no longer needed. I hope you can try it out. Take a look at the announcement for more details!

2 Likes