Bad storage gap resize with Truffle

Hi @frangio, and @aquiladev, I got the same issue with truffle upgrades.
Added a new variable as address type, getting this issue. if the plugin does not support it, how can I do it manually?
New variables should be placed after all existing inherited variables
Upgraded __gap to an incompatible type

  • Bad storage gap resize from 46 to 45
    Size decrease must match with corresponding variable inserts

@skyclean906 Can you provide an example of how your variables are defined in the old and new versions of your contract? The error indicates that the gap array size was not adjusted correctly in the new version.

Hi @ericglau, Thanks for your quick help.
// Old version

    ....
    uint256[46] private __gap;

// New version

    ....
    address public royaltyRegister;        
    uint256[45] private __gap;

but I'm also getting the error.

New variables should be placed after all existing inherited variables

And the error

Upgraded `__gap` to an incompatible type
* Bad storage gap resize from 46 to 45
Size decrease must match with corresponding variable inserts

I couldn't find a mistake based on this link.

Also, I added a new function, it can affect something?

Is there any suggestion message after the error? For example, something like Set __gap array to size <number>

Can you please provide the following info?

  1. The complete output of running your script, including all of the error message texts.
  2. A minimum reproducible example, containing the old and new implementation contracts (or at least example contracts with all of the storage variables).
  3. The installed version of @openzeppelin/truffle-upgrades
  4. The installed version of @openzeppelin/upgrades-core by running:
npm list @openzeppelin/upgrades-core


Hi @ericglau , the command result is here.

And here is error detail.
Please help me to check. Thanks!

We can't see any errors in what you've shared so far, and we can't reproduce it locally either. The following storage upgrade works correctly as expected:

contract V1 {
    uint256[46] private __gap;
}

contract V2 {
    address public royaltyRegister;
    uint256[45] private __gap;
}

Can you please share more of the Solidity code? In particular, are there any storage variables before royaltyRegister?

Hi @frangio , @ericglau
I uploaded the full code of two version files.
https://drive.google.com/drive/folders/1yhKuQuSHzvkENvYh0uQFdAje2m_rKFwe?usp=sharing

These are not the contracts you are having issues with. It would not be labelled abstract.

Please share the entire codebase. If you can't do so, please put together a minimal reproduction example that you can fully share and that we can use to reproduce the issue.

Hi @frangio , @ericglau , I pushed the full code here for the issue. some info added on readme file.

please help to check. Thank you!

Ok, sorry we didn't mention this earlier, but you seem to be using Truffle. Gap resizing is only available on Hardhat for technical reasons (Truffle doesn't give us enough information to confidently assess that layouts are compatible). Opened GitHub issue https://github.com/OpenZeppelin/openzeppelin-upgrades/issues/709 to track this.

A post was split to a new topic: Bad storage gap resize when adding inherited contract