Feat/eip7201 forge inspect storage layout
for eip7201 storage
#11624
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
It would be really nice to have a way to inspect the storage layout of eip7201 contract suites, regardless of whether the slots are declared in the top-level contract, a children or a library. So I made a tag system that can be added to your NatSpec comments, and fills in the blanks with AST build artifacts.
The solution is delivered in the form of a new flag,
forge inspect storage-layout **--eip7201**
Solution
While it's not completely automated, it is now possible to inspect eip7201 storage, even if it was through the use of libraries and other proxy patterns.
It requires a good knowledge of the storage schemas to begin with, as it requires to flag in the source code pertinent bits. I expect the rough edges to smoothen with time, as I put more elbow grease into this little pet project.
Available Natspec flag are as follows:
@custom:storage-bucket <GETTER_NAME>
: to be put just before a contract's constructor that uses eip7201 storage, for each slot used@custom:storage-bucket-transient <GETER_NAME>
: same, but for transient storage slots@custom:storage-bucket-slot (opt.) <?SLOT_ID>
: to be put just before a storage slot's declaration.@custom:storage-bucket-transient-slot (opt.) <SLOT_ID?>
: same, but for transient storage@custom:storage-bucket-struct <NAMESPACE>:<STRUCT_NAME>
: to put above all declared structs@custom:storage-bucket-enum <NAMESPACE>:<ENUM_NAME>
: for enum declarations@custom:storage-bucket-usertype <NAMESPACE>:<USERTYPE_NAME>
: for user type declarations@custom:storage-bucket-type ${@Custom:storage-bucket} <"keyvalue" / "singleton">
: tags the eip7201 storage's getter with the right name and type (schemaless getter, key/value pair; arrays are not supported yet)@custom:storage-bucket-value <GETTER_RETURN_VALUE>
PR Checklist