-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for __gap
#8
Comments
Hey @ZeroEkkusu! I made some changes in the script and got output something like this. Old Contract: // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
contract Counter {
uint256 public a;
uint256 public b;
uint256[48] public __gap;
} New Contract: // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
contract Counter {
uint256 public a;
uint256 public b;
uint256 public c;
uint256 public d;
uint256 public e;
uint256 public f;
uint256[44] public __gap;
} Old Report:
New Report:
🔻 is a new symbol I added to show that this variable is filled in the storage that was reserved by the One problem is __gap is not printing in the Old report and if I try to it is throwing an error, so I will need your help there. let offset = item.offset.toString().padEnd(5, " ");
^
TypeError: Cannot read properties of undefined (reading 'toString') |
Maybe you can push to a branch on your fork so we can take a look? |
Yes I have pushed my changed to my forked repo. Here's a link to the repo: |
Thanks; let me get on this tomorrow moring. |
One thing I realized is that I have used an array for storing gaps but there can be only one __gap variable so ignore the array logic in the code because that can be changed for a single variable instance. |
It may also be useful if we create a draft PR for easier reviewing. Also, I'll be able to push something if needed that way.
There can be more than one Let's say we have contracts So, your approach with an array was correct. |
Oh, okay. So what do you think of my approach? Also any ideas about solving the errors I am facing? If you say I'll push my changes and create a draft PR. |
i think we're on the right path:
yep, feel free to open a draft PR! there's an edge case where a variable can start before a gap and 'spill' into it:
but if we change the struct to:
the layout now looks like this:
for this, i think we need to make another helper function we'll figure out what to do with it later. |
Opened a draft PR: #16 |
__gap
s 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:
Gaps are often used when developing upgradeable smart contracts. See OpenZeppelin's documentation.
Let's say we update X to look like this:
(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
andalignedOverlayedVisualized
JSONs to think about it.Keep in mind that there can be multiple
__gap
s 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
and24-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.The text was updated successfully, but these errors were encountered: