From 59af3887a4fda502d88bd0b447fc86a87fcfc012 Mon Sep 17 00:00:00 2001 From: Josselin Date: Mon, 4 Feb 2019 17:38:39 -0500 Subject: [PATCH] Added: - node.ssa_variables_* properties - variable.non_ssa_version for StateVariableIR/LocalVariableIR Fixed: - Incorrect SSA conversion on Return IR - is_storage property on StateVariableIR/LocalVariableIR --- slither/core/cfg/node.py | 44 +++++++++++++++++++++ slither/slithir/utils/ssa.py | 2 +- slither/slithir/variables/local_variable.py | 12 ++++++ slither/slithir/variables/state_variable.py | 10 +++++ 4 files changed, 67 insertions(+), 1 deletion(-) diff --git a/slither/core/cfg/node.py b/slither/core/cfg/node.py index 88c5f7882a..8c718032f2 100644 --- a/slither/core/cfg/node.py +++ b/slither/core/cfg/node.py @@ -270,6 +270,29 @@ def solidity_variables_read(self): """ return list(self._solidity_vars_read) + @property + def ssa_variables_read(self): + """ + list(Variable): Variables read (local/state/solidity) + """ + return list(self._ssa_vars_read) + + @property + def ssa_state_variables_read(self): + """ + list(StateVariable): State variables read + """ + return list(self._ssa_state_vars_read) + + @property + def ssa_local_variables_read(self): + """ + list(LocalVariable): Local variables read + """ + return list(self._ssa_local_vars_read) + + + @property def variables_read_as_expression(self): return self._expression_vars_read @@ -299,6 +322,27 @@ def local_variables_written(self): """ return list(self._local_vars_written) + @property + def ssa_variables_written(self): + """ + list(Variable): Variables written (local/state/solidity) + """ + return list(self._ssa_vars_written) + + @property + def ssa_state_variables_written(self): + """ + list(StateVariable): State variables written + """ + return list(self._ssa_state_vars_written) + + @property + def ssa_local_variables_written(self): + """ + list(LocalVariable): Local variables written + """ + return list(self._ssa_local_vars_written) + @property def variables_written_as_expression(self): return self._expression_vars_written diff --git a/slither/slithir/utils/ssa.py b/slither/slithir/utils/ssa.py index 84fad4dd8d..ff9bd91296 100644 --- a/slither/slithir/utils/ssa.py +++ b/slither/slithir/utils/ssa.py @@ -543,7 +543,7 @@ def traversal(values): lvalue = get_variable(ir, lambda x: ir.lvalue) return Push(array, lvalue) elif isinstance(ir, Return): - value = get_variable(ir, lambda x: ir.values) + value = [get_variable(x, lambda y: y) for x in ir.values] return Return(value) elif isinstance(ir, Send): destination = get_variable(ir, lambda x: ir.destination) diff --git a/slither/slithir/variables/local_variable.py b/slither/slithir/variables/local_variable.py index d3beb0af31..f9f5ad1375 100644 --- a/slither/slithir/variables/local_variable.py +++ b/slither/slithir/variables/local_variable.py @@ -24,6 +24,7 @@ def __init__(self, local_variable): # initiate LocalVariable self._location = self.location + self._is_storage = self.is_storage self._index = 0 @@ -31,6 +32,13 @@ def __init__(self, local_variable): # points to state variables self._refers_to = set() + # keep un-ssa version + if isinstance(local_variable, LocalIRVariable): + self._non_ssa_version = local_variable.non_ssa_version + else: + self._non_ssa_version = local_variable + self._non_ssa_version = local_variable + @property def index(self): return self._index @@ -49,6 +57,10 @@ def refers_to(self): def refers_to(self, variables): self._refers_to = variables + @property + def non_ssa_version(self): + return self._non_ssa_version + def add_refers_to(self, variable): # It is a temporaryVariable if its the return of a new .. # ex: string[] memory dynargs = new string[](1); diff --git a/slither/slithir/variables/state_variable.py b/slither/slithir/variables/state_variable.py index 1d013bc36c..ecefe98c7b 100644 --- a/slither/slithir/variables/state_variable.py +++ b/slither/slithir/variables/state_variable.py @@ -23,6 +23,12 @@ def __init__(self, state_variable): self._index = 0 + # keep un-ssa version + if isinstance(state_variable, StateIRVariable): + self._non_ssa_version = state_variable.non_ssa_version + else: + self._non_ssa_version = state_variable + @property def index(self): return self._index @@ -31,6 +37,10 @@ def index(self): def index(self, idx): self._index = idx + @property + def non_ssa_version(self): + return self._non_ssa_version + @property def ssa_name(self): return '{}_{}'.format(self._name, self.index)