August 2019
Intermediate to advanced
486 pages
13h 52m
English
You should avoid adding a new state variable in a contract that is being used as a base contract for another contract. In the following code, a new state variable, uint256 c, is added in the A contract. This would affect the storage slot layout when a contract is upgraded:
//Bad Practicecontract A { uint256 a; uint256 c; //New state variable added}contract B { uint256 b;}contract MyContract is A, B { //...}
Hence, you should avoid adding new state variables in any base contracts. The way to solve this issue is to initially add some reserved state variables in base contracts, so that, in future, when there is a need, these reserved state variables can be used for upgraded contracts.