I have been looking at how to make my contracts upgradeable and looking through the Zeppelin docs and source code to try to wrap my head around this.
One thing I cannot work out is:
- How do new logic contracts share data (when they have no reference to one another and are deployed in different transactions)?
- From a security perspective what stops some bad actor from implementing a new logic contract and hijacking my data (it seems like Zeppelin deals with this with the
ifAdmin
modifier)?
- From a security perspective what stops some bad actor from implementing a new logic contract and hijacking my data (it seems like Zeppelin deals with this with the
For example, say I have contract MyLogicV1.sol
:
contract MyLogicV1 {
uint256 public foo;
// ...
}
I now have v2 which has to ensure its data is ordered the same and only appends new data after existing data:
contract MyLogicV2 is MyLogicv1 {
uint256 public foo;
uint256 public bar;
// ...
}
In the above MyLogicv1 will have a different address to the first MyLogicV2 deployed so the data will be different.
The test examples provided in the Zeppelin SDK do not really shed any light as they are all deployed in the same test meaning the contracts have references to one another. Realistically v1 is deployed and gets an address, v2 will be deployed some arbitrary amount of time later likely in a completely different transaction with no reference to the original contract.
To sum up how is v2 which is an upgrade on v1 see v1's data and how is this secured?