Hm, I think for 1 & 2, you didn't get me.. @ericglau
- For 1, I meant if user chooses to add gap in the beginning of the contract before the variables. In that case, I repeat my question.
Note that in this solution, you mention, problem is inheritting contract should be reducing slot gap size depending on its parent(if new variable gets added in parent, you have to go to inheritting contract and reduce the gap). Correct ? If so, This increases complexity x
times. Now, not only you care about the gap for the current contract that you're updating, you should go, find all contracts that inherits from it and reduce their gap sizes. This is madness.
Imagine the following:
contract Voting_V1 is OZ_contract1 {
uint num1;
}
// Let's say I directly added variables in `Voting_V1` Now, If I need to update and follow code copy approach and inherit from another contract:
contract Voting_V2 is OZ_contract1, 3rdContract {
uint num1;
uint[49] _gap;
}
// inheritance: Voting_V2, 3rdContract, OZ_contract1
As shown, inheritance chain is messed up because 3rdContract
overwrote num1
's slot. So unless I had had gaps
in the beginning of the Voting_V1
, I am stuck(Let's just I only want to use gaps and not split storage in its own contract - if tha'ts so, please look at my question again just a couple of lines above)
- This one which I'm gonna again repeat here is something OZ's gaps in the end of each contract really doesn't solve it. Note that example only uses OZ's contracts + my implementation contract that doesn't have state variables to show you exacty what I mean.
contract OZ_contract1 {
uint k;
uint[49] _gap;
}
contracts OZ_contract1 is OZ_contract2 {
uint z;
uint[49] _gap;
}
contract MyContract is OZ_contract1 {
// no variable....
}
// 50-100 0-50(slots)
// Chain MyContract => OZ_contract1 => OZ_contract2
// Lets say OZ updated `OZ_contract1` such as
contracts OZ_contract1 is OZ_contract2, OZ_contract3 {
uint z;
uint[49] _gap;
}
// 100-150 50-100 0-50(slots)
// Chain MyContract => OZ_contract1 => OZ_contract3 => OZ_contract2
Look, OZ updated their own contract by which I mean, they updated OZ_contract1
to inherit from another OZ contract. (I need to compile my code again and update MyContract
again for this - not always, but this could be needed/required). Look at the new inheritance chain in the comments. It messed it up the slots. So, OZ having gaps in the end of their contract(which I showed you by example) didn't help in that case. what's wrong with my example ?
I hope you realize what I mean ! Thanks again.