From 87319a6bffdf855837cf83ac12bff69e12e93ce4 Mon Sep 17 00:00:00 2001 From: Josselin Date: Mon, 17 Dec 2018 19:29:42 +0000 Subject: [PATCH] Add phi origin for state variable at function entry point --- slither/slithir/operations/high_level_call.py | 2 +- slither/slithir/utils/ssa.py | 8 +++++++- slither/solc_parsing/declarations/function.py | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/slither/slithir/operations/high_level_call.py b/slither/slithir/operations/high_level_call.py index 7b497fcd1..e4a6a5c5a 100644 --- a/slither/slithir/operations/high_level_call.py +++ b/slither/slithir/operations/high_level_call.py @@ -69,7 +69,7 @@ class HighLevelCall(Call, OperationWithLValue): return ret all_read = [self.destination, self.call_gas, self.call_value] + unroll(self.arguments) # remove None - return [x for x in all_read if x] + return [x for x in all_read if x] + [self.destination] @property def destination(self): diff --git a/slither/slithir/utils/ssa.py b/slither/slithir/utils/ssa.py index 009541129..9731754a3 100644 --- a/slither/slithir/utils/ssa.py +++ b/slither/slithir/utils/ssa.py @@ -54,8 +54,13 @@ def add_ssa_ir(function, all_state_variables_instances): for v in function.parameters+function.returns: if v.name: init_definition[v.name] = (v, function.entry_point) - add_phi_origins(function.entry_point, init_definition, dict()) + for (_, variable_instance) in all_state_variables_instances.items(): + if is_used_later(function.entry_point, variable_instance, []): + # rvalues are fixed in solc_parsing.declaration.function + function.entry_point.add_ssa_ir(Phi(StateIRVariable(variable_instance), set())) + + add_phi_origins(function.entry_point, init_definition, dict()) for node in function.nodes: @@ -200,6 +205,7 @@ def generate_ssa_irs(node, local_variables_instances, all_local_variables_instan all_state_variables_instances[variable.canonical_name] = new_var state_variables_instances[variable.canonical_name] = new_var phi_ir = PhiCallback(new_var, {node}, new_ir, variable) + # rvalues are fixed in solc_parsing.declaration.function node.add_ssa_ir(phi_ir) diff --git a/slither/solc_parsing/declarations/function.py b/slither/solc_parsing/declarations/function.py index 156729cb6..9f0977ea2 100644 --- a/slither/solc_parsing/declarations/function.py +++ b/slither/solc_parsing/declarations/function.py @@ -875,7 +875,7 @@ class FunctionSolc(Function): def fix_phi_callback(self, last_state_variables_instances): for node in self.nodes: for ir in node.irs_ssa: - if isinstance(ir, PhiCallback): + if isinstance(ir, PhiCallback) or node == self.entry_point: additional = last_state_variables_instances[ir.lvalue.canonical_name] ir.rvalues = list(set(additional + ir.rvalues))