Merge pull request #229 from crytic/dev-exception

Improve Exception handling
pull/222/head
Feist Josselin 6 years ago committed by GitHub
commit 7752999de6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      slither/__main__.py
  2. 7
      slither/all_exceptions.py
  3. 3
      slither/core/exceptions.py
  4. 8
      slither/core/expressions/assignment_operation.py
  5. 8
      slither/core/expressions/binary_operation.py
  6. 11
      slither/core/expressions/unary_operation.py
  7. 3
      slither/exceptions.py
  8. 19
      slither/slither.py
  9. 7
      slither/slithir/convert.py
  10. 3
      slither/slithir/exceptions.py
  11. 7
      slither/slithir/operations/binary.py
  12. 9
      slither/slithir/operations/unary.py
  13. 4
      slither/slithir/utils/ssa.py
  14. 4
      slither/solc_parsing/declarations/contract.py
  15. 10
      slither/solc_parsing/declarations/function.py
  16. 7
      slither/solc_parsing/exceptions.py
  17. 12
      slither/solc_parsing/expressions/expression_parsing.py
  18. 14
      slither/solc_parsing/slitherSolc.py
  19. 10
      slither/solc_parsing/solidity_types/type_parsing.py
  20. 11
      slither/solc_parsing/variables/variable_declaration.py
  21. 10
      slither/visitors/expression/expression.py
  22. 6
      slither/visitors/slithir/expression_to_slithir.py

@ -24,6 +24,7 @@ from slither.utils.command_line import (output_detectors, output_results_to_mark
output_detectors_json, output_printers, output_detectors_json, output_printers,
output_to_markdown, output_wiki) output_to_markdown, output_wiki)
from crytic_compile import is_supported from crytic_compile import is_supported
from slither.exceptions import SlitherException
logging.basicConfig() logging.basicConfig()
logger = logging.getLogger("Slither") logger = logging.getLogger("Slither")
@ -551,6 +552,12 @@ def main_impl(all_detector_classes, all_printer_classes):
return return
exit(results) exit(results)
except SlitherException as e:
logging.error(red('Error:'))
logging.error(red(e))
logging.error('Please report an issue to https://github.com/crytic/slither/issues')
sys.exit(-1)
except Exception: except Exception:
logging.error('Error in %s' % args.filename) logging.error('Error in %s' % args.filename)
logging.error(traceback.format_exc()) logging.error(traceback.format_exc())

@ -0,0 +1,7 @@
"""
This module import all slither exceptions
"""
from slither.slithir.exceptions import SlithIRError
from slither.solc_parsing.exceptions import ParsingError, ParsingContractNotFound, ParsingNameReuse
from slither.core.exceptions import SlitherCoreError
from slither.exceptions import SlitherException

@ -0,0 +1,3 @@
from slither.exceptions import SlitherException
class SlitherCoreError(SlitherException): pass

@ -1,7 +1,7 @@
import logging import logging
from slither.core.expressions.expression_typed import ExpressionTyped from slither.core.expressions.expression_typed import ExpressionTyped
from slither.core.expressions.expression import Expression from slither.core.expressions.expression import Expression
from slither.core.exceptions import SlitherCoreError
logger = logging.getLogger("AssignmentOperation") logger = logging.getLogger("AssignmentOperation")
@ -43,8 +43,7 @@ class AssignmentOperationType:
if operation_type == '%=': if operation_type == '%=':
return AssignmentOperationType.ASSIGN_MODULO return AssignmentOperationType.ASSIGN_MODULO
logger.error('get_type: Unknown operation type {})'.format(operation_type)) raise SlitherCoreError('get_type: Unknown operation type {})'.format(operation_type))
exit(-1)
@staticmethod @staticmethod
def str(operation_type): def str(operation_type):
@ -71,8 +70,7 @@ class AssignmentOperationType:
if operation_type == AssignmentOperationType.ASSIGN_MODULO: if operation_type == AssignmentOperationType.ASSIGN_MODULO:
return '%=' return '%='
logger.error('str: Unknown operation type {})'.format(operation_type)) raise SlitherCoreError('str: Unknown operation type {})'.format(operation_type))
exit(-1)
class AssignmentOperation(ExpressionTyped): class AssignmentOperation(ExpressionTyped):

@ -1,7 +1,7 @@
import logging import logging
from slither.core.expressions.expression_typed import ExpressionTyped from slither.core.expressions.expression_typed import ExpressionTyped
from slither.core.expressions.expression import Expression from slither.core.expressions.expression import Expression
from slither.core.exceptions import SlitherCoreError
logger = logging.getLogger("BinaryOperation") logger = logging.getLogger("BinaryOperation")
@ -67,8 +67,7 @@ class BinaryOperationType:
if operation_type == '||': if operation_type == '||':
return BinaryOperationType.OROR return BinaryOperationType.OROR
logger.error('get_type: Unknown operation type {})'.format(operation_type)) raise SlitherCoreError('get_type: Unknown operation type {})'.format(operation_type))
exit(-1)
@staticmethod @staticmethod
def str(operation_type): def str(operation_type):
@ -110,8 +109,7 @@ class BinaryOperationType:
return '&&' return '&&'
if operation_type == BinaryOperationType.OROR: if operation_type == BinaryOperationType.OROR:
return '||' return '||'
logger.error('str: Unknown operation type {})'.format(operation_type)) raise SlitherCoreError('str: Unknown operation type {})'.format(operation_type))
exit(-1)
class BinaryOperation(ExpressionTyped): class BinaryOperation(ExpressionTyped):

@ -1,7 +1,7 @@
import logging import logging
from slither.core.expressions.expression_typed import ExpressionTyped from slither.core.expressions.expression_typed import ExpressionTyped
from slither.core.expressions.expression import Expression from slither.core.expressions.expression import Expression
from slither.core.solidity_types.type import Type from slither.core.exceptions import SlitherCoreError
logger = logging.getLogger("UnaryOperation") logger = logging.getLogger("UnaryOperation")
@ -38,8 +38,7 @@ class UnaryOperationType:
return UnaryOperationType.PLUSPLUS_POST return UnaryOperationType.PLUSPLUS_POST
if operation_type == '--': if operation_type == '--':
return UnaryOperationType.MINUSMINUS_POST return UnaryOperationType.MINUSMINUS_POST
logger.error('get_type: Unknown operation type {}'.format(operation_type)) raise SlitherCoreError('get_type: Unknown operation type {}'.format(operation_type))
exit(-1)
@staticmethod @staticmethod
def str(operation_type): def str(operation_type):
@ -58,8 +57,7 @@ class UnaryOperationType:
if operation_type in [UnaryOperationType.MINUSMINUS_PRE, UnaryOperationType.MINUSMINUS_POST]: if operation_type in [UnaryOperationType.MINUSMINUS_PRE, UnaryOperationType.MINUSMINUS_POST]:
return '--' return '--'
logger.error('str: Unknown operation type {}'.format(operation_type)) raise SlitherCoreError('str: Unknown operation type {}'.format(operation_type))
exit(-1)
@staticmethod @staticmethod
def is_prefix(operation_type): def is_prefix(operation_type):
@ -74,8 +72,7 @@ class UnaryOperationType:
elif operation_type in [UnaryOperationType.PLUSPLUS_POST, UnaryOperationType.MINUSMINUS_POST]: elif operation_type in [UnaryOperationType.PLUSPLUS_POST, UnaryOperationType.MINUSMINUS_POST]:
return False return False
logger.error('is_prefix: Unknown operation type {}'.format(operation_type)) raise SlitherCoreError('is_prefix: Unknown operation type {}'.format(operation_type))
exit(-1)
class UnaryOperation(ExpressionTyped): class UnaryOperation(ExpressionTyped):

@ -0,0 +1,3 @@
class SlitherException(Exception): pass
class SlitherError(SlitherException): pass

@ -11,7 +11,7 @@ from crytic_compile import CryticCompile, InvalidCompilation
from slither.detectors.abstract_detector import AbstractDetector, DetectorClassification from slither.detectors.abstract_detector import AbstractDetector, DetectorClassification
from slither.printers.abstract_printer import AbstractPrinter from slither.printers.abstract_printer import AbstractPrinter
from .solc_parsing.slitherSolc import SlitherSolc from .solc_parsing.slitherSolc import SlitherSolc
from .utils.colors import red from .exceptions import SlitherError
logger = logging.getLogger("Slither") logger = logging.getLogger("Slither")
logging.basicConfig() logging.basicConfig()
@ -56,11 +56,8 @@ class Slither(SlitherSolc):
crytic_compile = CryticCompile(contract, **kwargs) crytic_compile = CryticCompile(contract, **kwargs)
self._crytic_compile = crytic_compile self._crytic_compile = crytic_compile
except InvalidCompilation as e: except InvalidCompilation as e:
logger.error('Invalid compilation') raise SlitherError('Invalid compilation: '+e)
logger.error(e)
exit(-1)
for path, ast in crytic_compile.asts.items(): for path, ast in crytic_compile.asts.items():
self._parse_contracts_from_loaded_json(ast, path) self._parse_contracts_from_loaded_json(ast, path)
self._add_source_code(path) self._add_source_code(path)
@ -78,14 +75,12 @@ class Slither(SlitherSolc):
def _init_from_raw_json(self, filename): def _init_from_raw_json(self, filename):
if not os.path.isfile(filename): if not os.path.isfile(filename):
logger.error('{} does not exist (are you in the correct directory?)'.format(filename)) raise SlitherError('{} does not exist (are you in the correct directory?)'.format(filename))
exit(-1)
assert filename.endswith('json') assert filename.endswith('json')
with open(filename, encoding='utf8') as astFile: with open(filename, encoding='utf8') as astFile:
stdout = astFile.read() stdout = astFile.read()
if not stdout: if not stdout:
logger.info('Empty AST file: %s', filename) raise SlitherError('Empty AST file: %s', filename)
sys.exit(-1)
contracts_json = stdout.split('\n=') contracts_json = stdout.split('\n=')
super(Slither, self).__init__(filename) super(Slither, self).__init__(filename)
@ -173,14 +168,12 @@ class Slither(SlitherSolc):
def _run_solc(self, filename, solc, disable_solc_warnings, solc_arguments, ast_format): def _run_solc(self, filename, solc, disable_solc_warnings, solc_arguments, ast_format):
if not os.path.isfile(filename): if not os.path.isfile(filename):
logger.error('{} does not exist (are you in the correct directory?)'.format(filename)) raise SlitherError('{} does not exist (are you in the correct directory?)'.format(filename))
exit(-1)
assert filename.endswith('json') assert filename.endswith('json')
with open(filename, encoding='utf8') as astFile: with open(filename, encoding='utf8') as astFile:
stdout = astFile.read() stdout = astFile.read()
if not stdout: if not stdout:
logger.info('Empty AST file: %s', filename) raise SlitherError('Empty AST file: %s', filename)
sys.exit(-1)
stdout = stdout.split('\n=') stdout = stdout.split('\n=')
return stdout return stdout

@ -33,6 +33,7 @@ from slither.slithir.variables import (Constant, ReferenceVariable,
from slither.visitors.slithir.expression_to_slithir import ExpressionToSlithIR from slither.visitors.slithir.expression_to_slithir import ExpressionToSlithIR
from slither.utils.function import get_function_id from slither.utils.function import get_function_id
from slither.utils.type import export_nested_types_from_variable from slither.utils.type import export_nested_types_from_variable
from slither.slithir.exceptions import SlithIRError
logger = logging.getLogger('ConvertToIR') logger = logging.getLogger('ConvertToIR')
@ -457,8 +458,7 @@ def propagate_types(ir, node):
# temporary operation; they will be removed # temporary operation; they will be removed
pass pass
else: else:
logger.error('Not handling {} during type propgation'.format(type(ir))) raise SlithIRError('Not handling {} during type propgation'.format(type(ir)))
exit(-1)
def extract_tmp_call(ins, contract): def extract_tmp_call(ins, contract):
assert isinstance(ins, TmpCall) assert isinstance(ins, TmpCall)
@ -577,8 +577,7 @@ def convert_to_low_level(ir):
new_ir.arguments = ir.arguments new_ir.arguments = ir.arguments
new_ir.lvalue.set_type(ElementaryType('bool')) new_ir.lvalue.set_type(ElementaryType('bool'))
return new_ir return new_ir
logger.error('Incorrect conversion to low level {}'.format(ir)) raise SlithIRError('Incorrect conversion to low level {}'.format(ir))
exit(-1)
def convert_to_push(ir, node): def convert_to_push(ir, node):
""" """

@ -0,0 +1,3 @@
from slither.exceptions import SlitherException
class SlithIRError(SlitherException): pass

@ -4,6 +4,7 @@ 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_lvalue, is_valid_rvalue
from slither.core.solidity_types import ElementaryType from slither.core.solidity_types import ElementaryType
from slither.slithir.variables import ReferenceVariable from slither.slithir.variables import ReferenceVariable
from slither.slithir.exceptions import SlithIRError
logger = logging.getLogger("BinaryOperationIR") logger = logging.getLogger("BinaryOperationIR")
@ -80,8 +81,7 @@ class BinaryType(object):
if operation_type == '||': if operation_type == '||':
return BinaryType.OROR return BinaryType.OROR
logger.error('get_type: Unknown operation type {})'.format(operation_type)) raise SlithIRError('get_type: Unknown operation type {})'.format(operation_type))
exit(-1)
@staticmethod @staticmethod
def str(operation_type): def str(operation_type):
@ -123,8 +123,7 @@ class BinaryType(object):
return '&&' return '&&'
if operation_type == BinaryType.OROR: if operation_type == BinaryType.OROR:
return '||' return '||'
logger.error('str: Unknown operation type {})'.format(operation_type)) raise SlithIRError('str: Unknown operation type {})'.format(operation_type))
exit(-1)
class Binary(OperationWithLValue): class Binary(OperationWithLValue):

@ -1,8 +1,7 @@
import logging import logging
from slither.slithir.operations.lvalue import OperationWithLValue 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_lvalue, is_valid_rvalue
from slither.slithir.exceptions import SlithIRError
logger = logging.getLogger("BinaryOperationIR") logger = logging.getLogger("BinaryOperationIR")
@ -17,8 +16,7 @@ class UnaryType:
return UnaryType.BANG return UnaryType.BANG
if operation_type == '~': if operation_type == '~':
return UnaryType.TILD return UnaryType.TILD
logger.error('get_type: Unknown operation type {}'.format(operation_type)) raise SlithIRError('get_type: Unknown operation type {}'.format(operation_type))
exit(-1)
@staticmethod @staticmethod
def str(operation_type): def str(operation_type):
@ -27,8 +25,7 @@ class UnaryType:
if operation_type == UnaryType.TILD: if operation_type == UnaryType.TILD:
return '~' return '~'
logger.error('str: Unknown operation type {}'.format(operation_type)) raise SlithIRError('str: Unknown operation type {}'.format(operation_type))
exit(-1)
class Unary(OperationWithLValue): class Unary(OperationWithLValue):

@ -22,6 +22,7 @@ from slither.slithir.variables import (Constant, LocalIRVariable,
ReferenceVariable, ReferenceVariableSSA, ReferenceVariable, ReferenceVariableSSA,
StateIRVariable, TemporaryVariable, StateIRVariable, TemporaryVariable,
TemporaryVariableSSA, TupleVariable, TupleVariableSSA) TemporaryVariableSSA, TupleVariable, TupleVariableSSA)
from slither.slithir.exceptions import SlithIRError
logger = logging.getLogger('SSA_Conversion') logger = logging.getLogger('SSA_Conversion')
@ -662,7 +663,6 @@ def copy_ir(ir, *instances):
return Length(value, lvalue) return Length(value, lvalue)
logger.error('Impossible ir copy on {} ({})'.format(ir, type(ir))) raise SlithIRError('Impossible ir copy on {} ({})'.format(ir, type(ir)))
exit(-1)
# endregion # endregion

@ -9,6 +9,7 @@ from slither.solc_parsing.declarations.modifier import ModifierSolc
from slither.solc_parsing.declarations.structure import StructureSolc from slither.solc_parsing.declarations.structure import StructureSolc
from slither.solc_parsing.solidity_types.type_parsing import parse_type from slither.solc_parsing.solidity_types.type_parsing import parse_type
from slither.solc_parsing.variables.state_variable import StateVariableSolc from slither.solc_parsing.variables.state_variable import StateVariableSolc
from slither.solc_parsing.exceptions import ParsingError
logger = logging.getLogger("ContractSolcParsing") logger = logging.getLogger("ContractSolcParsing")
@ -186,8 +187,7 @@ class ContractSolc04(Contract):
elif item[self.get_key()] == 'UsingForDirective': elif item[self.get_key()] == 'UsingForDirective':
self._usingForNotParsed.append(item) self._usingForNotParsed.append(item)
else: else:
logger.error('Unknown contract item: '+item[self.get_key()]) raise ParsingError('Unknown contract item: '+item[self.get_key()])
exit(-1)
return return
def _parse_struct(self, struct): def _parse_struct(self, struct):

@ -26,6 +26,7 @@ from slither.utils.expression_manipulations import SplitTernaryExpression
from slither.utils.utils import unroll from slither.utils.utils import unroll
from slither.visitors.expression.export_values import ExportValues from slither.visitors.expression.export_values import ExportValues
from slither.visitors.expression.has_conditional import HasConditional from slither.visitors.expression.has_conditional import HasConditional
from slither.solc_parsing.exceptions import ParsingError
logger = logging.getLogger("FunctionSolc") logger = logging.getLogger("FunctionSolc")
@ -725,8 +726,7 @@ class FunctionSolc(Function):
link_nodes(node, new_node) link_nodes(node, new_node)
node = new_node node = new_node
else: else:
logger.error('Statement not parsed %s'%name) raise ParsingError('Statement not parsed %s'%name)
exit(-1)
return node return node
@ -814,8 +814,7 @@ class FunctionSolc(Function):
end_node = self._find_end_loop(node, [], 0) end_node = self._find_end_loop(node, [], 0)
if not end_node: if not end_node:
logger.error('Break in no-loop context {}'.format(node)) raise ParsingError('Break in no-loop context {}'.format(node))
exit(-1)
for son in node.sons: for son in node.sons:
son.remove_father(node) son.remove_father(node)
@ -826,8 +825,7 @@ class FunctionSolc(Function):
start_node = self._find_start_loop(node, []) start_node = self._find_start_loop(node, [])
if not start_node: if not start_node:
logger.error('Continue in no-loop context {}'.format(node.nodeId())) raise ParsingError('Continue in no-loop context {}'.format(node.nodeId()))
exit(-1)
for son in node.sons: for son in node.sons:
son.remove_father(node) son.remove_father(node)

@ -0,0 +1,7 @@
from slither.exceptions import SlitherException
class ParsingError(SlitherException): pass
class ParsingNameReuse(SlitherException): pass
class ParsingContractNotFound(SlitherException): pass

@ -35,7 +35,7 @@ from slither.core.solidity_types import (ArrayType, ElementaryType,
FunctionType, MappingType) FunctionType, MappingType)
from slither.solc_parsing.solidity_types.type_parsing import (UnknownType, from slither.solc_parsing.solidity_types.type_parsing import (UnknownType,
parse_type) parse_type)
from slither.solc_parsing.exceptions import ParsingError
logger = logging.getLogger("ExpressionParsing") logger = logging.getLogger("ExpressionParsing")
@ -78,8 +78,7 @@ def find_variable(var_name, caller_context, referenced_declaration=None):
function = caller_context function = caller_context
contract = function.contract contract = function.contract
else: else:
logger.error('Incorrect caller context') raise ParsingError('Incorrect caller context')
exit(-1)
if function: if function:
# We look for variable declared with the referencedDeclaration attr # We look for variable declared with the referencedDeclaration attr
@ -627,8 +626,7 @@ def parse_expression(expression, caller_context):
elif type_name[caller_context.get_key()] == 'FunctionTypeName': elif type_name[caller_context.get_key()] == 'FunctionTypeName':
array_type = parse_type(type_name, caller_context) array_type = parse_type(type_name, caller_context)
else: else:
logger.error('Incorrect type array {}'.format(type_name)) raise ParsingError('Incorrect type array {}'.format(type_name))
exit(-1)
array = NewArray(depth, array_type) array = NewArray(depth, array_type)
return array return array
@ -664,5 +662,5 @@ def parse_expression(expression, caller_context):
call = CallExpression(called, arguments, 'Modifier') call = CallExpression(called, arguments, 'Modifier')
return call return call
logger.error('Expression not parsed %s'%name) raise ParsingError('Expression not parsed %s'%name)
exit(-1)

@ -14,6 +14,7 @@ from slither.core.declarations.import_directive import Import
from slither.analyses.data_dependency.data_dependency import compute_dependency from slither.analyses.data_dependency.data_dependency import compute_dependency
from slither.utils.colors import red from slither.utils.colors import red
from .exceptions import ParsingNameReuse, ParsingContractNotFound
class SlitherSolc(Slither): class SlitherSolc(Slither):
@ -182,8 +183,7 @@ class SlitherSolc(Slither):
info += '\n{} is defined in:'.format(contract.name) info += '\n{} is defined in:'.format(contract.name)
info += '\n- {}\n- {}'.format(contract.source_mapping_str, info += '\n- {}\n- {}'.format(contract.source_mapping_str,
self._contracts[contract.name].source_mapping_str) self._contracts[contract.name].source_mapping_str)
logger.error(info) raise ParsingNameReuse(info)
exit(-1)
else: else:
self._contracts_by_id[contract.id] = contract self._contracts_by_id[contract.id] = contract
self._contracts[contract.name] = contract self._contracts[contract.name] = contract
@ -217,11 +217,11 @@ class SlitherSolc(Slither):
father_constructors.append(self._contracts_by_id[i]) father_constructors.append(self._contracts_by_id[i])
except KeyError: except KeyError:
logger.error(red('A contract was not found, it is likely that your codebase contains muliple contracts with the same name')) txt = 'A contract was not found, it is likely that your codebase contains muliple contracts with the same name'
logger.error(red('Truffle does not handle this case during compilation')) txt += 'Truffle does not handle this case during compilation'
logger.error(red('Please read https://github.com/trailofbits/slither/wiki#keyerror-or-nonetype-error')) txt += 'Please read https://github.com/trailofbits/slither/wiki#keyerror-or-nonetype-error'
logger.error(red('And update your code to remove the duplicate')) txt += 'And update your code to remove the duplicate'
exit(-1) raise ParsingContractNotFound(txt)
contract.setInheritance(ancestors, fathers, father_constructors) contract.setInheritance(ancestors, fathers, father_constructors)
contracts_to_be_analyzed = self.contracts contracts_to_be_analyzed = self.contracts

@ -13,6 +13,7 @@ from slither.core.declarations.function import Function
from slither.core.expressions.literal import Literal from slither.core.expressions.literal import Literal
from slither.solc_parsing.exceptions import ParsingError
import re import re
logger = logging.getLogger('TypeParsing') logger = logging.getLogger('TypeParsing')
@ -118,8 +119,7 @@ def _find_from_type_name(name, contract, contracts, structures, enums):
return MappingType(from_type, to_type) return MappingType(from_type, to_type)
if not var_type: if not var_type:
logger.error('Type not found '+str(name)) raise ParsingError('Type not found '+str(name))
exit(-1)
return UserDefinedType(var_type) return UserDefinedType(var_type)
@ -134,8 +134,7 @@ def parse_type(t, caller_context):
elif isinstance(caller_context, Function): elif isinstance(caller_context, Function):
contract = caller_context.contract contract = caller_context.contract
else: else:
logger.error('Incorrect caller context') raise ParsingError('Incorrect caller context')
exit(-1)
is_compact_ast = caller_context.is_compact_ast is_compact_ast = caller_context.is_compact_ast
@ -223,5 +222,4 @@ def parse_type(t, caller_context):
return FunctionType(params_vars, return_values_vars) return FunctionType(params_vars, return_values_vars)
logger.error('Type name not found '+str(t)) raise ParsingError('Type name not found '+str(t))
exit(-1)

@ -6,7 +6,7 @@ from slither.core.variables.variable import Variable
from slither.solc_parsing.solidity_types.type_parsing import parse_type, UnknownType from slither.solc_parsing.solidity_types.type_parsing import parse_type, UnknownType
from slither.core.solidity_types.elementary_type import ElementaryType, NonElementaryType from slither.core.solidity_types.elementary_type import ElementaryType, NonElementaryType
from slither.solc_parsing.exceptions import ParsingError
logger = logging.getLogger("VariableDeclarationSolcParsing") logger = logging.getLogger("VariableDeclarationSolcParsing")
class MultipleVariablesDeclaration(Exception): class MultipleVariablesDeclaration(Exception):
@ -51,8 +51,7 @@ class VariableDeclarationSolc(Variable):
elif nodeType == 'VariableDeclaration': elif nodeType == 'VariableDeclaration':
self._init_from_declaration(var, var['value']) self._init_from_declaration(var, var['value'])
else: else:
logger.error('Incorrect variable declaration type {}'.format(nodeType)) raise ParsingError('Incorrect variable declaration type {}'.format(nodeType))
exit(-1)
else: else:
nodeType = var['name'] nodeType = var['name']
@ -65,15 +64,13 @@ class VariableDeclarationSolc(Variable):
elif len(var['children']) > 2: elif len(var['children']) > 2:
raise MultipleVariablesDeclaration raise MultipleVariablesDeclaration
else: else:
logger.error('Variable declaration without children?'+var) raise ParsingError('Variable declaration without children?'+var)
exit(-1)
declaration = var['children'][0] declaration = var['children'][0]
self._init_from_declaration(declaration, init) self._init_from_declaration(declaration, init)
elif nodeType == 'VariableDeclaration': elif nodeType == 'VariableDeclaration':
self._init_from_declaration(var, None) self._init_from_declaration(var, None)
else: else:
logger.error('Incorrect variable declaration type {}'.format(nodeType)) raise ParsingError('Incorrect variable declaration type {}'.format(nodeType))
exit(-1)
@property @property
def initialized(self): def initialized(self):

@ -15,6 +15,7 @@ from slither.core.expressions.new_elementary_type import NewElementaryType
from slither.core.expressions.tuple_expression import TupleExpression from slither.core.expressions.tuple_expression import TupleExpression
from slither.core.expressions.type_conversion import TypeConversion from slither.core.expressions.type_conversion import TypeConversion
from slither.core.expressions.unary_operation import UnaryOperation from slither.core.expressions.unary_operation import UnaryOperation
from slither.exceptions import SlitherError
logger = logging.getLogger("ExpressionVisitor") logger = logging.getLogger("ExpressionVisitor")
@ -86,8 +87,7 @@ class ExpressionVisitor:
pass pass
else: else:
logger.error('Expression not handled: {}'.format(expression)) raise SlitherError('Expression not handled: {}'.format(expression))
exit(-1)
self._post_visit(expression) self._post_visit(expression)
@ -200,8 +200,7 @@ class ExpressionVisitor:
pass pass
else: else:
logger.error('Expression not handled: {}'.format(expression)) raise SlitherError('Expression not handled: {}'.format(expression))
exit(-1)
# pre_expression_name # pre_expression_name
@ -302,8 +301,7 @@ class ExpressionVisitor:
pass pass
else: else:
logger.error('Expression not handled: {}'.format(expression)) raise SlitherError('Expression not handled: {}'.format(expression))
exit(-1)
# post_expression_name # post_expression_name

@ -17,8 +17,7 @@ from slither.slithir.variables import (Constant, ReferenceVariable,
TemporaryVariable, TupleVariable) TemporaryVariable, TupleVariable)
from slither.visitors.expression.expression import ExpressionVisitor from slither.visitors.expression.expression import ExpressionVisitor
#from slither.slithir.variables.state_variable import StateIRVariable from slither.slithir.exceptions import SlithIRError
#from slither.slithir.variables.local_variable import LocalIRVariable
logger = logging.getLogger("VISTIOR:ExpressionToSlithIR") logger = logging.getLogger("VISTIOR:ExpressionToSlithIR")
@ -57,8 +56,7 @@ def convert_assignment(left, right, t, return_type):
elif t == AssignmentOperationType.ASSIGN_MODULO: elif t == AssignmentOperationType.ASSIGN_MODULO:
return Binary(left, left, right, BinaryType.MODULO) return Binary(left, left, right, BinaryType.MODULO)
logger.error('Missing type during assignment conversion') raise SlithIRError('Missing type during assignment conversion')
exit(-1)
class ExpressionToSlithIR(ExpressionVisitor): class ExpressionToSlithIR(ExpressionVisitor):

Loading…
Cancel
Save