feat: resolve nested struct members in slither-read-storage - #3075
Open
subashmokshya wants to merge 1 commit into
Open
feat: resolve nested struct members in slither-read-storage#3075subashmokshya wants to merge 1 commit into
subashmokshya wants to merge 1 commit into
Conversation
A struct member that is itself a struct only received a slot for the nested struct's starting location; its own members were never resolved, so their slots, sizes, and packing offsets were unavailable. Recurse into nested struct members, computing each member's slot relative to the nested struct's base slot per Solidity's storage layout rules. This handles arbitrary nesting depth. Fixes crytic#2077 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
slither-read-storagedid not fully resolve structs nested inside other structs. A nested-struct member (e.g.outer.middle) received aSlotInfofor the nested struct's starting slot, but its own members (outer.middle.inner,outer.middle.inner.a, ...) were never resolved — theirelemswere left empty, so their slots, sizes, and packing offsets were unavailable.This PR makes
_all_struct_slotsrecurse into any member that is itself a struct, resolving that member's sub-members relative to the nested struct's base slot, per Solidity's storage-layout rules (a nested struct occupies consecutive slots starting at the parent member's slot). Recursion is depth-agnostic, so arbitrarily deep nesting works.Root cause
_all_struct_slotsiterated only the top-level struct'selems_ordered. When a member's type was itself aStructure, the code computed the member's start slot but never descended into it. The new_all_nested_struct_slotshelper reuses the existing_find_struct_var_slotslot arithmetic to resolve each sub-member against the nested struct's base slot, then recurses on any sub-member that is also a struct.Changes
slither/tools/read_storage/read_storage.py: recurse into nested struct members in_all_struct_slots; add_all_nested_struct_slotshelper.tests/unit/tools/read_storage/test_nested_struct.py: new test covering two-level nesting (Outer→Middle→Inner), asserting exact slots for every member, packing offsets for the doubly-nested elementary members, and fully-qualified dotted names.Test evidence
The new test fails on
master(nestedelemsempty) and passes with this change.ruff checkandruff format --checkare clean on both files.Fixes #2077
🤖 Generated with Claude Code