From 4f61aa1bbda6d0064733264884c659f0a93aeff2 Mon Sep 17 00:00:00 2001 From: Simone Date: Wed, 22 Nov 2023 18:42:29 +0100 Subject: [PATCH] Consider local vars with storage location as storage vars --- slither/core/cfg/node.py | 77 +++++++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 12 deletions(-) diff --git a/slither/core/cfg/node.py b/slither/core/cfg/node.py index 9b53b0db92..ad19defb05 100644 --- a/slither/core/cfg/node.py +++ b/slither/core/cfg/node.py @@ -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)) @@ -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 ###################################################################################