From 87acb738412d1462ec7192b5fb33f6ffc4e84cd0 Mon Sep 17 00:00:00 2001 From: Josselin Date: Mon, 22 Oct 2018 19:01:55 +0100 Subject: [PATCH] SlithIR: add points_to property to ReferenceVariable --- slither/slithir/convert.py | 11 +++++++++++ slither/slithir/variables/reference.py | 24 +++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/slither/slithir/convert.py b/slither/slithir/convert.py index da72b560e..03834b84c 100644 --- a/slither/slithir/convert.py +++ b/slither/slithir/convert.py @@ -511,10 +511,21 @@ def apply_ir_heuristics(irs, node): # irs = replace_calls(irs) irs = remove_unused(irs) + find_references_origin(irs) + reset_variable_number(irs) return irs +def find_references_origin(irs): + """ + Make lvalue of each Index, Member operation + points to the left variable + """ + for ir in irs: + if isinstance(ir, (Index, Member)): + ir.lvalue.points_to = ir.variable_left + def reset_variable_number(result): """ Reset the number associated to slithIR variables diff --git a/slither/slithir/variables/reference.py b/slither/slithir/variables/reference.py index 18f33733e..bd93f9f1f 100644 --- a/slither/slithir/variables/reference.py +++ b/slither/slithir/variables/reference.py @@ -1,6 +1,8 @@ -from slither.core.variables.variable import Variable from slither.core.children.child_node import ChildNode +from slither.core.declarations import Contract, Enum, SolidityVariableComposed +from slither.core.variables.variable import Variable + class ReferenceVariable(ChildNode, Variable): @@ -10,6 +12,7 @@ class ReferenceVariable(ChildNode, Variable): super(ReferenceVariable, self).__init__() self._index = ReferenceVariable.COUNTER ReferenceVariable.COUNTER += 1 + self._points_to = None @property def index(self): @@ -19,6 +22,25 @@ class ReferenceVariable(ChildNode, Variable): def index(self, idx): self._index = idx + @property + def points_to(self): + """ + Return the variable pointer by the reference + It is the left member of a Index or Member operator + """ + return self._points_to + + @points_to.setter + def points_to(self, points_to): + # Can only be a rvalue of + # Member or Index operator + from slither.slithir.utils.utils import is_valid_lvalue + assert is_valid_lvalue(points_to) \ + or points_to == SolidityVariableComposed('msg.data') \ + or isinstance(points_to, (Contract, Enum)) + + self._points_to = points_to + @property def name(self): return 'REF_{}'.format(self.index)