-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: handle TypeAlias in read_storage for custom value types #2911
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
base: master
Are you sure you want to change the base?
Conversation
|
Hi maintainers, could you please approve the CI workflow runs for this PR? As a first-time contributor, the workflows require maintainer approval. Thank you! |
e705382 to
a62d36c
Compare
dguido
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review: fix: handle TypeAlias in read_storage for custom value types
Reviewing: PR #2911 (fix/read-storage-type-alias branch)
Files changed: slither/tools/read_storage/read_storage.py
Summary
This PR fixes an UnboundLocalError when slither-read-storage encounters user-defined value types (e.g., type MyUint64 is uint64) inside structs. The fix correctly imports TypeAlias and unwraps it to its underlying ElementaryType in two key locations.
Analysis
The fix is correct and addresses the root cause. The changes:
-
Import
TypeAlias- Required to check for the type. -
Handle
TypeAliasinget_storage_slot(lines 245-248 in the new code) - Handles top-level storage variables that areTypeAliasdirectly. -
Unwrap
TypeAliasin_find_struct_var_slot(lines 596-598 in the new code) - This is the critical fix. The original code only handledElementaryType, causingsizeto remain uninitialized when iterating over struct members that areTypeAlias.
Why the fix works:
TypeAlias.underlying_typereturns the wrappedElementaryType(e.g.,uint64)- After unwrapping, the existing
ElementaryTypehandling code correctly computessizefromvar_type.size
Issues Found
No critical or important issues (confidence >= 80).
The implementation is correct and follows patterns already established in the codebase.
Minor Observations (below reporting threshold)
-
Formatting-only changes - The PR includes several formatting changes (multi-line argument formatting) that appear to be from ruff. These are fine but inflate the diff.
-
Test coverage - The PR lacks a dedicated test case for
TypeAliashandling. The existing test contracts (StorageLayout.sol) don't use user-defined value types. Consider adding a test in a follow-up PR to prevent regression. -
Other
TypeAliaslocations - The_find_array_slotand_find_mapping_slotmethods might also encounterTypeAliastypes in nested structures. However, these paths eventually call_find_struct_var_slot, which now handles unwrapping correctly. The current fix should cover these cases transitively.
Verdict
Approve. The fix is minimal, correct, and directly addresses the reported issue (#2522). The code follows existing patterns in the file.
Suggestion for maintainers: Consider adding a test case with user-defined value types to the read-storage test suite to prevent regression.
Apply PR crytic#2911 changes to fix slither-read-storage failing on user-defined value types (TypeAlias) like `type MyUint64 is uint64` inside structs. - Import TypeAlias from slither.core.solidity_types - Handle TypeAlias at top-level storage variable type check in get_storage_slot - Unwrap TypeAlias to its underlying ElementaryType in _find_struct_var_slot Fixes crytic#2522 Co-Authored-By: ep0chzer0 <[email protected]> Co-Authored-By: Claude Opus 4.5 <[email protected]>
a62d36c to
d850341
Compare
Bulk PR Review SummaryResearch Findings
Test Status
Code Review Issues Found/FixedNo functional issues found. The fix is minimal, correct, and directly addresses the root cause. Formatting changes: The PR includes ruff-driven formatting changes (multi-line argument wrapping) which are acceptable but inflate the diff from +37/-6 to appear larger. Test coverage gap: As noted by @dguido's earlier review, the PR lacks a dedicated test case for Changes Made
Merge ReadinessReady to merge - The fix is correct, minimal, follows existing patterns in the codebase, and all tests pass. The only suggestion is to add test coverage in a follow-up PR to prevent regression. |
5c20955 to
fc69bf6
Compare
Adds support for user-defined value types (TypeAlias) in slither-read-storage. Previously, custom types like `type MyUint64 is uint64` inside structs would cause an UnboundLocalError because the code only handled ElementaryType. Changes: - Import TypeAlias from slither.core.solidity_types - Handle TypeAlias at top-level storage variable type check - Unwrap TypeAlias to its underlying ElementaryType in _find_struct_var_slot Fixes crytic#2522
fc69bf6 to
289d13d
Compare
Summary
Fixes slither-read-storage failing on user-defined value types (TypeAlias) like
type MyUint64 is uint64inside structs.Problem
When a struct contains custom types,
read_storagefails with:This happens because
_find_struct_var_slotonly handlesElementaryType, notTypeAlias.Solution
TypeAliasfromslither.core.solidity_typesTypeAliasat the top-level storage variable type check inget_storage_slotTypeAliasto its underlyingElementaryTypein_find_struct_var_slotTest Case (from issue)
This now works correctly instead of raising an error.
Fixes #2522
🤖 Generated with Claude Code