Merge pull request #411 from crytic/dev-cleanup-irs

Clean up IRs classes
pull/412/head
Feist Josselin 5 years ago committed by GitHub
commit 4a331b8c09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      scripts/travis_test_dapp.sh
  2. 1
      slither/core/cfg/node.py
  3. 12
      slither/core/declarations/function.py
  4. 3
      slither/core/source_mapping/source_mapping.py
  5. 5
      slither/slithir/operations/assignment.py
  6. 6
      slither/slithir/operations/balance.py
  7. 6
      slither/slithir/operations/binary.py
  8. 4
      slither/slithir/operations/call.py
  9. 3
      slither/slithir/operations/condition.py
  10. 4
      slither/slithir/operations/delete.py
  11. 2
      slither/slithir/operations/event_call.py
  12. 3
      slither/slithir/operations/high_level_call.py
  13. 6
      slither/slithir/operations/index.py
  14. 10
      slither/slithir/operations/init_array.py
  15. 5
      slither/slithir/operations/internal_call.py
  16. 1
      slither/slithir/operations/internal_dynamic_call.py
  17. 6
      slither/slithir/operations/length.py
  18. 7
      slither/slithir/operations/library_call.py
  19. 4
      slither/slithir/operations/low_level_call.py
  20. 1
      slither/slithir/operations/lvalue.py
  21. 11
      slither/slithir/operations/member.py
  22. 3
      slither/slithir/operations/new_array.py
  23. 6
      slither/slithir/operations/new_contract.py
  24. 6
      slither/slithir/operations/new_elementary_type.py
  25. 3
      slither/slithir/operations/new_structure.py
  26. 3
      slither/slithir/operations/nop.py
  27. 2
      slither/slithir/operations/operation.py
  28. 3
      slither/slithir/operations/phi.py
  29. 8
      slither/slithir/operations/phi_callback.py
  30. 4
      slither/slithir/operations/push.py
  31. 3
      slither/slithir/operations/return_operation.py
  32. 13
      slither/slithir/operations/send.py
  33. 1
      slither/slithir/operations/solidity_call.py
  34. 3
      slither/slithir/operations/transfer.py
  35. 7
      slither/slithir/operations/type_conversion.py
  36. 6
      slither/slithir/operations/unary.py
  37. 3
      slither/slithir/operations/unpack.py
  38. 3
      slither/slithir/variables/temporary_ssa.py

@ -20,7 +20,7 @@ dapp init
slither .
if [ $? -eq 22 ]
if [ $? -eq 23 ]
then
exit 0
fi

@ -647,6 +647,7 @@ class Node(SourceMapping, ChildFunction):
'''
Use to place phi operation
'''
ir.set_node(self)
self._irs_ssa.append(ir)
def slithir_generation(self):

@ -107,6 +107,7 @@ class Function(ChildContract, ChildInheritance, SourceMapping):
self._expressions = None
self._slithir_operations = None
self._slithir_ssa_operations = None
self._all_expressions = None
self._all_slithir_operations = None
@ -694,6 +695,17 @@ class Function(ChildContract, ChildInheritance, SourceMapping):
self._slithir_operations = operations
return self._slithir_operations
@property
def slithir_ssa_operations(self):
"""
list(Operation): List of the slithir operations (SSA)
"""
if self._slithir_ssa_operations is None:
operations = [n.irs_ssa for n in self.nodes]
operations = [item for sublist in operations for item in sublist if item]
self._slithir_ssa_operations = operations
return self._slithir_ssa_operations
# endregion
###################################################################################
###################################################################################

@ -1,7 +1,8 @@
import re
import os
from slither.core.context.context import Context
class SourceMapping(Context):
def __init__(self):

@ -1,10 +1,9 @@
import logging
from slither.slithir.operations.lvalue import OperationWithLValue
from slither.core.variables.variable import Variable
from slither.slithir.variables import TupleVariable, ReferenceVariable
from slither.core.declarations.function import Function
from slither.slithir.operations.lvalue import OperationWithLValue
from slither.slithir.utils.utils import is_valid_lvalue, is_valid_rvalue
from slither.slithir.variables import TupleVariable, ReferenceVariable
logger = logging.getLogger("AssignmentOperationIR")

@ -1,9 +1,7 @@
import logging
from slither.core.solidity_types import ElementaryType
from slither.slithir.operations.lvalue import OperationWithLValue
from slither.core.declarations import Function
from slither.core.variables.variable import Variable
from slither.slithir.utils.utils import is_valid_lvalue, is_valid_rvalue
from slither.core.solidity_types.elementary_type import ElementaryType
class Balance(OperationWithLValue):

@ -1,10 +1,10 @@
import logging
from slither.core.solidity_types import ElementaryType
from slither.slithir.exceptions import SlithIRError
from slither.slithir.operations.lvalue import OperationWithLValue
from slither.core.variables.variable import Variable
from slither.slithir.utils.utils import is_valid_lvalue, is_valid_rvalue
from slither.core.solidity_types import ElementaryType
from slither.slithir.variables import ReferenceVariable
from slither.slithir.exceptions import SlithIRError
logger = logging.getLogger("BinaryOperationIR")

@ -1,6 +1,6 @@
from slither.slithir.operations.operation import Operation
class Call(Operation):
def __init__(self):
@ -27,4 +27,4 @@ class Call(Operation):
Must be called after slithIR analysis pass
:return: bool
'''
return False
return False

@ -1,11 +1,14 @@
from slither.slithir.operations.operation import Operation
from slither.slithir.utils.utils import is_valid_rvalue
class Condition(Operation):
"""
Condition
Only present as last operation in conditional node
"""
def __init__(self, value):
assert is_valid_rvalue(value)
super(Condition, self).__init__()

@ -1,8 +1,8 @@
import logging
from slither.slithir.operations.lvalue import OperationWithLValue
from slither.core.variables.variable import Variable
from slither.slithir.utils.utils import is_valid_lvalue
class Delete(OperationWithLValue):
"""
Delete has a lvalue, as it has for effect to change the value

@ -1,6 +1,6 @@
from slither.slithir.operations.call import Call
from slither.core.variables.variable import Variable
class EventCall(Call):
def __init__(self, name):

@ -7,6 +7,7 @@ from slither.core.declarations.function import Function
from slither.slithir.utils.utils import is_valid_lvalue
from slither.slithir.variables.constant import Constant
class HighLevelCall(Call, OperationWithLValue):
"""
High level message call
@ -22,7 +23,7 @@ class HighLevelCall(Call, OperationWithLValue):
self._nbr_arguments = nbr_arguments
self._type_call = type_call
self._lvalue = result
self._callid = None # only used if gas/value != 0
self._callid = None # only used if gas/value != 0
self._function_instance = None
self._call_value = None

@ -1,9 +1,7 @@
from slither.slithir.operations.lvalue import OperationWithLValue
from slither.core.variables.variable import Variable
from slither.core.declarations import SolidityVariableComposed
from slither.slithir.variables.reference import ReferenceVariable
from slither.slithir.operations.lvalue import OperationWithLValue
from slither.slithir.utils.utils import is_valid_lvalue, is_valid_rvalue
from slither.slithir.variables.reference import ReferenceVariable
class Index(OperationWithLValue):

@ -1,22 +1,25 @@
import logging
from slither.slithir.operations.lvalue import OperationWithLValue
from slither.core.variables.variable import Variable
from slither.slithir.utils.utils import is_valid_lvalue, is_valid_rvalue
from slither.slithir.utils.utils import is_valid_rvalue
class InitArray(OperationWithLValue):
def __init__(self, init_values, lvalue):
# init_values can be an array of n dimension
# reduce was removed in py3
super().__init__()
def reduce(xs):
result = True
for i in xs:
result = result and i
return result
def check(elem):
if isinstance(elem, (list,)):
return reduce(elem)
return is_valid_rvalue(elem)
assert check(init_values)
self._init_values = init_values
self._lvalue = lvalue
@ -35,5 +38,6 @@ class InitArray(OperationWithLValue):
if isinstance(elem, (list,)):
return str([convert(x) for x in elem])
return str(elem)
init_values = convert(self.init_values)
return "{}({}) = {}".format(self.lvalue, self.lvalue.type, init_values)

@ -2,7 +2,7 @@ from slither.core.declarations import Modifier
from slither.core.declarations.function import Function
from slither.slithir.operations.call import Call
from slither.slithir.operations.lvalue import OperationWithLValue
from slither.slithir.variables import Constant
class InternalCall(Call, OperationWithLValue):
@ -15,7 +15,7 @@ class InternalCall(Call, OperationWithLValue):
else:
self._function = None
self._function_name, self._contract_name = function
#self._contract = contract
# self._contract = contract
self._nbr_arguments = nbr_arguments
self._type_call = type_call
self._lvalue = result
@ -71,4 +71,3 @@ class InternalCall(Call, OperationWithLValue):
return txt.format(lvalue,
self.function.canonical_name,
','.join(args))

@ -1,4 +1,3 @@
from slither.core.declarations.function import Function
from slither.core.solidity_types import FunctionType
from slither.core.variables.variable import Variable
from slither.slithir.operations.call import Call

@ -1,9 +1,7 @@
import logging
from slither.core.solidity_types import ElementaryType
from slither.slithir.operations.lvalue import OperationWithLValue
from slither.core.declarations import Function
from slither.core.variables.variable import Variable
from slither.slithir.utils.utils import is_valid_lvalue, is_valid_rvalue
from slither.core.solidity_types.elementary_type import ElementaryType
class Length(OperationWithLValue):

@ -1,13 +1,15 @@
from slither.slithir.operations.high_level_call import HighLevelCall
from slither.core.declarations.contract import Contract
class LibraryCall(HighLevelCall):
"""
High level message call
"""
# Development function, to be removed once the code is stable
def _check_destination(self, destination):
assert isinstance(destination, (Contract))
assert isinstance(destination, Contract)
def can_reenter(self, callstack=None):
'''
@ -40,6 +42,3 @@ class LibraryCall(HighLevelCall):
self.function_name,
[str(x) for x in arguments],
gas)

@ -5,6 +5,7 @@ from slither.core.declarations.solidity_variables import SolidityVariable
from slither.slithir.variables.constant import Constant
class LowLevelCall(Call, OperationWithLValue):
"""
High level message call
@ -19,7 +20,7 @@ class LowLevelCall(Call, OperationWithLValue):
self._nbr_arguments = nbr_arguments
self._type_call = type_call
self._lvalue = result
self._callid = None # only used if gas/value != 0
self._callid = None # only used if gas/value != 0
self._call_value = None
self._call_gas = None
@ -102,4 +103,3 @@ class LowLevelCall(Call, OperationWithLValue):
[str(x) for x in arguments],
value,
gas)

@ -1,5 +1,6 @@
from slither.slithir.operations.operation import Operation
class OperationWithLValue(Operation):
'''
Operation with a lvalue

@ -1,13 +1,10 @@
from slither.core.expressions.expression import Expression
from slither.core.expressions.expression_typed import ExpressionTyped
from slither.core.solidity_types.type import Type
from slither.core.declarations import Contract
from slither.core.declarations.enum import Enum
from slither.slithir.operations.lvalue import OperationWithLValue
from slither.slithir.utils.utils import is_valid_lvalue, is_valid_rvalue
from slither.slithir.variables.reference import ReferenceVariable
from slither.slithir.utils.utils import is_valid_rvalue
from slither.slithir.variables.constant import Constant
from slither.slithir.variables.reference import ReferenceVariable
from slither.core.declarations.contract import Contract
from slither.core.declarations.enum import Enum
class Member(OperationWithLValue):

@ -2,6 +2,7 @@ from slither.slithir.operations.lvalue import OperationWithLValue
from slither.slithir.operations.call import Call
from slither.core.solidity_types.type import Type
class NewArray(Call, OperationWithLValue):
def __init__(self, depth, array_type, lvalue):
@ -26,4 +27,4 @@ class NewArray(Call, OperationWithLValue):
def __str__(self):
args = [str(a) for a in self.arguments]
return '{} = new {}{}({})'.format(self.lvalue, self.array_type, '[]'*self.depth, ','.join(args))
return '{} = new {}{}({})'.format(self.lvalue, self.array_type, '[]' * self.depth, ','.join(args))

@ -1,6 +1,5 @@
from slither.core.declarations.contract import Contract
from slither.slithir.operations import Call, OperationWithLValue
from slither.slithir.utils.utils import is_valid_lvalue, is_valid_rvalue
from slither.slithir.utils.utils import is_valid_lvalue
from slither.slithir.variables.constant import Constant
@ -13,8 +12,9 @@ class NewContract(Call, OperationWithLValue):
self._contract_name = contract_name
# todo create analyze to add the contract instance
self._lvalue = lvalue
self._callid = None # only used if gas/value != 0
self._callid = None # only used if gas/value != 0
self._call_value = None
@property
def call_value(self):
return self._call_value

@ -1,8 +1,8 @@
from slither.slithir.operations.lvalue import OperationWithLValue
from slither.slithir.operations.call import Call
from slither.core.solidity_types.elementary_type import ElementaryType
from slither.slithir.operations.call import Call
from slither.slithir.operations.lvalue import OperationWithLValue
from slither.slithir.utils.utils import is_valid_lvalue
from slither.slithir.utils.utils import is_valid_lvalue, is_valid_rvalue
class NewElementaryType(Call, OperationWithLValue):

@ -5,6 +5,7 @@ from slither.slithir.utils.utils import is_valid_lvalue
from slither.core.declarations.structure import Structure
class NewStructure(Call, OperationWithLValue):
def __init__(self, structure, lvalue):
@ -22,7 +23,7 @@ class NewStructure(Call, OperationWithLValue):
@property
def structure(self):
return self._structure
@property
def structure_name(self):
return self.structure.name

@ -1,5 +1,6 @@
from .operation import Operation
class Nop(Operation):
@property
@ -11,4 +12,4 @@ class Nop(Operation):
return []
def __str__(self):
return "NOP"
return "NOP"

@ -4,6 +4,7 @@ from slither.core.children.child_expression import ChildExpression
from slither.core.children.child_node import ChildNode
from slither.utils.utils import unroll
class AbstractOperation(abc.ABC):
@property
@ -22,6 +23,7 @@ class AbstractOperation(abc.ABC):
"""
pass
class Operation(Context, ChildExpression, ChildNode, AbstractOperation):
@property

@ -1,7 +1,7 @@
from slither.slithir.operations.lvalue import OperationWithLValue
from slither.slithir.utils.utils import is_valid_lvalue
class Phi(OperationWithLValue):
def __init__(self, left_variable, nodes):
@ -32,5 +32,6 @@ class Phi(OperationWithLValue):
@property
def nodes(self):
return self._nodes
def __str__(self):
return '{}({}) := \u03D5({})'.format(self.lvalue, self.lvalue.type, [str(v) for v in self._rvalues])

@ -1,11 +1,7 @@
import logging
from slither.core.variables.variable import Variable
from slither.slithir.variables import TupleVariable
from slither.core.declarations.function import Function
from slither.slithir.utils.utils import is_valid_lvalue, is_valid_rvalue
from slither.slithir.utils.utils import is_valid_lvalue
from .phi import Phi
class PhiCallback(Phi):
def __init__(self, left_variable, nodes, call_ir, rvalue):

@ -1,9 +1,7 @@
import logging
from slither.slithir.operations.lvalue import OperationWithLValue
from slither.core.declarations import Function
from slither.core.variables.variable import Variable
from slither.slithir.utils.utils import is_valid_lvalue, is_valid_rvalue
class Push(OperationWithLValue):
def __init__(self, array, value):

@ -2,11 +2,14 @@ from slither.slithir.operations.operation import Operation
from slither.slithir.variables.tuple import TupleVariable
from slither.slithir.utils.utils import is_valid_rvalue
class Return(Operation):
"""
Return
Only present as last operation in RETURN node
"""
def __init__(self, values):
# Note: Can return None
# ex: return call()

@ -1,10 +1,9 @@
from slither.core.declarations.solidity_variables import SolidityVariable
from slither.core.variables.variable import Variable
from slither.slithir.operations.call import Call
from slither.slithir.operations.lvalue import OperationWithLValue
from slither.core.variables.variable import Variable
from slither.core.declarations.solidity_variables import SolidityVariable
from slither.slithir.utils.utils import is_valid_lvalue
from slither.slithir.variables.constant import Constant
class Send(Call, OperationWithLValue):
@ -32,9 +31,7 @@ class Send(Call, OperationWithLValue):
def destination(self):
return self._destination
def __str__(self):
value = 'value:{}'.format(self.call_value)
return str(self.lvalue) +' = SEND dest:{} {}'.format(self.destination, value)
#
return str(self.lvalue) + ' = SEND dest:{} {}'.format(self.destination, value)
#

@ -1,7 +1,6 @@
from slither.core.declarations.solidity_variables import SolidityFunction
from slither.slithir.operations.call import Call
from slither.slithir.operations.lvalue import OperationWithLValue
from slither.core.variables.variable import Variable
class SolidityCall(Call, OperationWithLValue):

@ -2,6 +2,7 @@ from slither.slithir.operations.call import Call
from slither.core.variables.variable import Variable
from slither.core.declarations.solidity_variables import SolidityVariable
class Transfer(Call):
def __init__(self, destination, value):
@ -29,5 +30,3 @@ class Transfer(Call):
def __str__(self):
value = 'value:{}'.format(self.call_value)
return 'Transfer dest:{} {}'.format(self.destination, value)

@ -1,13 +1,12 @@
from slither.slithir.operations.lvalue import OperationWithLValue
from slither.core.variables.variable import Variable
from slither.core.solidity_types.type import Type
from slither.slithir.operations.lvalue import OperationWithLValue
from slither.slithir.utils.utils import is_valid_lvalue, is_valid_rvalue
class TypeConversion(OperationWithLValue):
def __init__(self, result, variable, variable_type):
super().__init__()
assert is_valid_rvalue(variable)
assert is_valid_lvalue(result)
assert isinstance(variable_type, Type)

@ -5,9 +5,10 @@ from slither.slithir.exceptions import SlithIRError
logger = logging.getLogger("BinaryOperationIR")
class UnaryType:
BANG = 0 # !
TILD = 1 # ~
BANG = 0 # !
TILD = 1 # ~
@staticmethod
def get_type(operation_type, isprefix):
@ -27,6 +28,7 @@ class UnaryType:
raise SlithIRError('str: Unknown operation type {}'.format(operation_type))
class Unary(OperationWithLValue):
def __init__(self, result, variable, operation_type):

@ -1,8 +1,7 @@
import logging
from slither.slithir.operations.lvalue import OperationWithLValue
from slither.slithir.utils.utils import is_valid_lvalue
from slither.slithir.variables.tuple import TupleVariable
from slither.slithir.utils.utils import is_valid_lvalue, is_valid_rvalue
class Unpack(OperationWithLValue):

@ -4,7 +4,7 @@
as the TemporaryVariable are in SSA form in both version
'''
from .temporary import TemporaryVariable
from .variable import SlithIRVariable
class TemporaryVariableSSA(TemporaryVariable):
@ -13,7 +13,6 @@ class TemporaryVariableSSA(TemporaryVariable):
self._non_ssa_version = temporary
@property
def non_ssa_version(self):
return self._non_ssa_version

Loading…
Cancel
Save