Skip to content

Commit

Permalink
Added:
Browse files Browse the repository at this point in the history
        - node.ssa_variables_* properties
        - variable.non_ssa_version for StateVariableIR/LocalVariableIR
Fixed:
        - Incorrect SSA conversion on Return IR
        - is_storage property on StateVariableIR/LocalVariableIR
  • Loading branch information
montyly committed Feb 4, 2019
1 parent 0ff9305 commit 59af388
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
44 changes: 44 additions & 0 deletions slither/core/cfg/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion slither/slithir/utils/ssa.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions slither/slithir/variables/local_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,21 @@ def __init__(self, local_variable):

# initiate LocalVariable
self._location = self.location
self._is_storage = self.is_storage

self._index = 0

# Additional field
# 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
Expand All @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions slither/slithir/variables/state_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

0 comments on commit 59af388

Please sign in to comment.