-
Notifications
You must be signed in to change notification settings - Fork 7
Add support for __gap #8
Description
__gaps can be processed after the layouts are overlayed and aligned.
Edit: See 'Update' at the end for easier approach! 👇
How to do this:
Let's say that we have a contract X.
This is its storage layout:
x1
x2
__gap [10]
Gaps are often used when developing upgradeable smart contracts. See OpenZeppelin's documentation.
Let's say we update X to look like this:
x1
x2
x3
x4
__gap [8]
(assuming x3 and x4 occupy one slot each)
We added two new variables (x3 and x4), and correctly shrink the gap by two (10 => 8).
However, if we run Storage Delta, these variables will be marked!
We need to identify that these variables are in the storage space previously reserved by the gap, and de-escalate the findings.
I recommend taking a look at alignedOldVisualized and alignedOverlayedVisualized JSONs to think about it.
Keep in mind that there can be multiple __gaps in a contract (regex: /^__gap/).
Additionally, we need to make sure gaps have been shrunk by the right amount.
Update
There may be a straightforward way to solve this.
We won't be changing layout JSONs at all.
First, we determine 'gap spaces' from the old layout JSON.
For example, let's say there are gap spaces at positions 10-14 and 24-26.
Thats's 2 gap spaces of sizes 4 and 2. We record this for future reference.
The first rule is to de-escalate findings for variables in a gap space.
For example, 🏴 becomes 🌱, and so on.
This can be done by always asking, "Is the variable in a gap space?" before we write to the report, and de-escalating if so.
The second rule is that we print an empty line to the old report for each variable that has been de-escalated.
This way our reports will remain aligned.
The third rule is to make sure that the gap space is either filled completely, or contains a gap at the end, correctly shrunk based its current position and its old position.
Gaps can be of any type, so we should use size to perform the check.