OpenZeppelin / OpenZeppelin/openzeppelin-upgrades
gap resizing using solc v0.5.x
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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