Skip to content
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

The function get_storage_slot in read_storage.py cannot accurately determine the slot where variables in the structure are located. #2524

Open
Subway2023 opened this issue Aug 7, 2024 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@Subway2023
Copy link

Subway2023 commented Aug 7, 2024

Describe the issue:

If the first variable x in the structure has a size of m bits (m < 256) and the second variable y has a size of n bits (n > 256 - m), then variables x and y cannot be stored in the same slot. However, the get_storage_slot function mistakenly assumes that both are stored in the same slot.

Code example to reproduce the issue:

srs = SlitherReadStorage([c], 20)
srs.get_all_storage_variables()
srs.get_storage_layout()
print("srs._slot_info",srs._slot_info)
contract C {
    struct S {
        uint64 x;
        uint256 y;
    }
    S s;
}

Version:

0.10.3

Relevant log output:

srs._slot_info {'s': SlotInfo(name='s', type_string='C.S', slot=0, size=512, offset=0, value=None, elems={'x': SlotInfo(name='s.x', type_string='uint64', slot=0, size=64, offset=0, value=None, elems={}), 'y': SlotInfo(name='s.y', type_string='uint256', slot=0, size=256, offset=64, value=None, elems={})})}

It shows that the slot of y is 0, which is an error.

@Subway2023 Subway2023 added the bug-candidate Bugs reports that are not yet confirmed label Aug 7, 2024
@0xalpharush
Copy link
Contributor

This should probably check if offset + size is greater than 256

@0xalpharush 0xalpharush added bug Something isn't working good first issue Good for newcomers and removed bug-candidate Bugs reports that are not yet confirmed labels Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants