Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
Added a storage gap at the end of Initializable's storage layout. (#215)
Browse files Browse the repository at this point in the history
* Added a storage gap at the end of Initializable's storage layout.

* Fixed storage layout test.
  • Loading branch information
nventuro authored and mergify[bot] committed Oct 10, 2018
1 parent b3d098d commit 12d4292
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 6 additions & 3 deletions packages/lib/contracts/Initializable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pragma solidity ^0.4.24;
* invoked. This applies both to deploying an Initializable contract, as well
* as extending an Initializable contract via inheritance.
* WARNING: When used with inheritance, manual care must be taken to not invoke
* a parent initializer twice, or ensure that all initializers are idempotent,
* a parent initializer twice, or ensure that all initializers are idempotent,
* because this is not dealt with automatically as with constructors.
*/
contract Initializable {
Expand Down Expand Up @@ -42,7 +42,7 @@ contract Initializable {

/// @dev Returns true if and only if the function is running in the constructor
function isConstructor() private view returns (bool) {
// extcodesize checks the size of the code stored in an address, and
// extcodesize checks the size of the code stored in an address, and
// address returns the current address. Since the code is still not
// deployed when running a constructor, any checks on its code size will
// yield zero, making it an effective way to detect if a contract is
Expand All @@ -51,4 +51,7 @@ contract Initializable {
assembly { cs := extcodesize(address) }
return cs == 0;
}
}

// Reserved storage space to allow for layout changes in the future.
uint256[50] private ______gap;
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,12 @@ contract('AdminUpgradeabilityProxy', ([_, admin, anotherAccount]) => {
})

it('uses the storage of the proxy', async function () {
// fetch the x value of Migratable at position 0 of the storage
const storedValue = await Proxy.at(this.proxyAddress).getStorageAt(1);
// storage layout should look as follows:
// - 0: Initializable storage
// - 1-50: Initailizable reserved storage (50 slots)
// - 51: initializerRan
// - 52: x
const storedValue = await Proxy.at(this.proxyAddress).getStorageAt(52);
storedValue.should.be.bignumber.eq(42);
})
})
Expand Down

0 comments on commit 12d4292

Please sign in to comment.