Storage layout compatibility error with contracts-upgradeable 3.2.2 -> 4.5.1

Hi,
Probably there are similar issues, but I couldn't find the exact same problem.

We have an upgradeable contract deployed with the package @openzeppelin/contracts-upgradeable 3.2.2 and we wanted to upgrade it but updating the package to 4.5.1.

We did not make changes in parent contracts, the changes are only in Box contract to be upgraded.

But it throws this error when we execute the upgrade

$ npx hardhat run scripts/upgrades/upgrade-box.js 
Upgrading Box...
Error: New storage layout is incompatible

@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol:36: Inserted `__gap`
  > New variables should be placed after all existing inherited variables

@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol:61: Inserted `_roles`
  > New variables should be placed after all existing inherited variables

@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol:235: Inserted `__gap`
  > New variables should be placed after all existing inherited variables

@openzeppelin/contracts-upgradeable/access/AccessControlEnumerableUpgradeable.sol:22: Replaced `_roles` with `_roleMembers` of incompatible type

ERC20Upgradeable: Deleted `_decimals`
  > Keep the variable even if unused

@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol:394: Upgraded `__gap` to an incompatible type
  - Bad array resize from 44 to 45
    Size cannot increase here

As you can see, all the incompatibility errors are from the package.
Are we doing something wrong or there's no compatibility between these packages?

Thanks in advance.

:computer: Environment

Hardhat

As seen in the readme for the upgradeable contracts:

There will be storage incompatibilities across major versions of this package, which makes it unsafe to upgrade a deployed contract from one major version to another, for example from 3.4.0 to 4.0.0.

1 Like

Hi!
You're right, I didn't check the readme file.
Thank you!!