Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gap resizing using solc v0.5.x #753

Open
fruiz08 opened this issue Mar 1, 2023 · 1 comment
Open

gap resizing using solc v0.5.x #753

fruiz08 opened this issue Mar 1, 2023 · 1 comment

Comments

@fruiz08
Copy link

fruiz08 commented Mar 1, 2023

Related to #698

pragma solidity 0.5.8;

contract V1 {
    address public a;

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}
pragma solidity 0.5.8;

contract V2 {
    address public a;
    address public b;
    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

Test:

       const v1 = await deployTransparentProxy("V1", deployer, V1__factory);
       const V1 =  await ethers.getContractFactory("V1");
       const V2 =  await ethers.getContractFactory("V2");
        // forces the import of an existing proxy to be used with this plugin
        await upgrades.forceImport(v1.address, V1);
        // validates an implementation
        await upgrades.validateImplementation(V2);
        // compares the current implementation to the new implementation to check for storage layout compatibility errors
        await upgrades.validateUpgrade(v1.address, V2);

Error:
`Error: New storage layout is incompatible

contracts/V2.sol:5: Inserted b

New variables should be placed after all existing inherited variables

contracts/V2.sol:11: Upgraded __gap to an incompatible type

  • Bad storage gap resize from 50 to 49
    Size decrease must match with corresponding variable inserts`

For newer solc versions, at leat > v0.7.6, works fine

@frangio
Copy link
Contributor

frangio commented Mar 3, 2023

It is not expectd to work with 0.5.8. This feature requires the storageLayout compiler output, which was introduced in 0.5.13. If you need 0.5, that version might work. But note that both v1 and v2 should be compiled using that compiler version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants