OpenZeppelin / openzeppelin-upgrades

Plugins for Hardhat and Foundry to deploy and manage upgradeable contracts on Ethereum.
MIT License
630 stars 271 forks source link

Can't add variables with change of storage gap with hardhat #785

Open jachung91 opened 1 year ago

jachung91 commented 1 year ago

I am using

hardhat v2.14.0 solidity v0.8.9

Simple code is like

original code

contract BoxV1 is Initializable{ uint256 private value; uint256[48] private __gapUint256;}

upgrading code

contract BoxV2 is Initializable{ uint256 private value; uint256 private amount; uint256[47] private __gapUint256;}

but i get error when I use upgrades.upgradeProxy with hardhat.

Error is

Error: New storage layout is incompatible contracts/BoxV2.sol:8: Inserted amount New variables should be placed after all existing inherited variables contracts/BoxV2.sol:9: Upgraded __gapUint256 to an incompatible type

As i read docs at https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable#storage-gaps I think i did anything wrong. Any one can help?

ericglau commented 1 year ago

Hi @jachung91 , the gap name needs to be exactly __gap or start with __gap_ (with the extra underscore after it). In your example, can you use a gap name like __gap_uint256?