OpenZeppelin / OpenZeppelin/openzeppelin-upgrades

gap resizing using solc v0.5.x

Open
#753 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
658
Forks
286
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the V1/V2 example with solc 0.5.8, using deployTransparentProxy, forceImport, validateImplementation, and validateUpgrade as shown. Compare the result with solc versions newer than 0.7.6, then inspect the storage-layout validation path responsible for the inserted b and resized __gap errors. Done means the behavior is corrected or clearly documented with regression coverage for the demonstrated versions.

Written by the indexing model from the issue text.

Assessment

Tech stack
solidity
Domain
blockchain
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.