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

Consider local vars with storage location as storage vars #2241

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
77 changes: 65 additions & 12 deletions slither/core/cfg/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,14 +928,32 @@ def _find_read_write_call(self) -> None: # pylint: disable=too-many-statements
self._library_calls.append((ir.destination, ir.function))

self._vars_read = list(set(self._vars_read))
self._state_vars_read = [v for v in self._vars_read if isinstance(v, StateVariable)]
self._local_vars_read = [v for v in self._vars_read if isinstance(v, LocalVariable)]
self._state_vars_read = [
v
for v in self._vars_read
if isinstance(v, StateVariable)
or isinstance(v, LocalVariable)
and v.location == "storage"
]
self._local_vars_read = [
v for v in self._vars_read if isinstance(v, LocalVariable) and v.location != "storage"
]
self._solidity_vars_read = [
v_ for v_ in self._vars_read if isinstance(v_, SolidityVariable)
]
self._vars_written = list(set(self._vars_written))
self._state_vars_written = [v for v in self._vars_written if isinstance(v, StateVariable)]
self._local_vars_written = [v for v in self._vars_written if isinstance(v, LocalVariable)]
self._state_vars_written = [
v
for v in self._vars_written
if isinstance(v, StateVariable)
or isinstance(v, LocalVariable)
and v.location == "storage"
]
self._local_vars_written = [
v
for v in self._vars_written
if isinstance(v, LocalVariable) and v.location != "storage"
]
self._internal_calls = list(set(self._internal_calls))
self._solidity_calls = list(set(self._solidity_calls))
self._high_level_calls = list(set(self._high_level_calls))
Expand Down Expand Up @@ -993,26 +1011,61 @@ def update_read_write_using_ssa(self) -> None:
continue
self._ssa_vars_written.append(var)
self._ssa_vars_read = list(set(self._ssa_vars_read))
self._ssa_state_vars_read = [v for v in self._ssa_vars_read if isinstance(v, StateVariable)]
self._ssa_local_vars_read = [v for v in self._ssa_vars_read if isinstance(v, LocalVariable)]
self._ssa_state_vars_read = [
v
for v in self._ssa_vars_read
if isinstance(v, StateVariable)
or isinstance(v, LocalVariable)
and v.location == "storage"
]
self._ssa_local_vars_read = [
v
for v in self._ssa_vars_read
if isinstance(v, LocalVariable) and v.location != "storage"
]
self._ssa_vars_written = list(set(self._ssa_vars_written))
self._ssa_state_vars_written = [
v for v in self._ssa_vars_written if v and isinstance(v, StateIRVariable)
v
for v in self._ssa_vars_written
if v
and isinstance(v, StateIRVariable)
or isinstance(v, LocalIRVariable)
and v.location == "storage"
]
self._ssa_local_vars_written = [
v for v in self._ssa_vars_written if v and isinstance(v, LocalIRVariable)
v
for v in self._ssa_vars_written
if v and isinstance(v, LocalIRVariable) and v.location != "storage"
]

vars_read = [self._convert_ssa(x) for x in self._ssa_vars_read]
vars_written = [self._convert_ssa(x) for x in self._ssa_vars_written]

self._vars_read += [v_ for v_ in vars_read if v_ and v_ not in self._vars_read]
self._state_vars_read = [v for v in self._vars_read if isinstance(v, StateVariable)]
self._local_vars_read = [v for v in self._vars_read if isinstance(v, LocalVariable)]
self._state_vars_read = [
v
for v in self._vars_read
if isinstance(v, StateVariable)
or isinstance(v, LocalVariable)
and v.location == "storage"
]
self._local_vars_read = [
v for v in self._vars_read if isinstance(v, LocalVariable) and v.location != "storage"
]

self._vars_written += [v_ for v_ in vars_written if v_ and v_ not in self._vars_written]
self._state_vars_written = [v for v in self._vars_written if isinstance(v, StateVariable)]
self._local_vars_written = [v for v in self._vars_written if isinstance(v, LocalVariable)]
self._state_vars_written = [
v
for v in self._vars_written
if isinstance(v, StateVariable)
or isinstance(v, LocalVariable)
and v.location == "storage"
]
self._local_vars_written = [
v
for v in self._vars_written
if isinstance(v, LocalVariable) and v.location != "storage"
]

# endregion
###################################################################################
Expand Down
Loading