Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions slither/tools/read_storage/read_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
from web3.middleware import ExtraDataToPOAMiddleware

from slither.core.declarations import Contract, Structure
from slither.core.solidity_types import ArrayType, ElementaryType, MappingType, UserDefinedType
from slither.core.solidity_types import (
ArrayType,
ElementaryType,
MappingType,
UserDefinedType,
TypeAliasTopLevel,
)
from slither.core.solidity_types.type import Type
from slither.core.cfg.node import NodeType
from slither.core.variables.state_variable import StateVariable
Expand Down Expand Up @@ -581,8 +587,12 @@ def _find_struct_var_slot(
size = 0
for var in elems:
var_type = var.type
if isinstance(var_type, ElementaryType):
size = var_type.size
is_type_alias = isinstance(var_type, TypeAliasTopLevel)
if isinstance(var_type, ElementaryType) or is_type_alias:
if is_type_alias:
size, _ = var_type.storage_size
else:
size = var_type.size
if size > (256 - offset):
slot += 1
offset = 0
Expand Down
8 changes: 8 additions & 0 deletions tests/tools/read-storage/test_data/typealiastest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type MyUint64 is uint64;
contract C {
struct S {
MyUint64 y;
MyUint64 z;
}
S s;
}
15 changes: 14 additions & 1 deletion tests/tools/read-storage/test_read_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ def deploy_contract(w3, ganache, contract_bin, contract_abi) -> Contract:
# pylint: disable=too-many-locals
@pytest.mark.parametrize(
"test_contract, storage_file",
[("StorageLayout", "storage_layout"), ("UnstructuredStorageLayout", "unstructured_storage")],
[
("StorageLayout", "storage_layout"),
("UnstructuredStorageLayout", "unstructured_storage"),
],
)
@pytest.mark.usefixtures("web3", "ganache")
def test_read_storage(test_contract, storage_file, web3, ganache, solc_binary_path) -> None:
Expand Down Expand Up @@ -90,3 +93,13 @@ def test_read_storage(test_contract, storage_file, web3, ganache, solc_binary_pa
f.write(str(change.t2))

assert not diff


def test_type_alias(solc_binary_path) -> None:
"""verify support for TypeAliasTop"""
solc_path = solc_binary_path(version="0.8.10")
slither = Slither(Path(TEST_DATA_DIR, "typealiastest.sol").as_posix())
c = slither.get_contract_from_name("C")
srs = SlitherReadStorage(c, 20)
srs.get_all_storage_variables()
srs.get_storage_layout()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this perform some assertion?

Copy link

@qci-cabrera qci-cabrera Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for sure. I think when I was looking into this, it was just a skill issue, and I just wanted the test to run as some initial signal that was the changes I made didn't immediately break something.

I'd need to re-look at this, but absolutely, there needs to be some kind of assert to truly be meaningful.