diff --git a/slither/core/slither_core.py b/slither/core/slither_core.py index 2747416fd..8106930ef 100644 --- a/slither/core/slither_core.py +++ b/slither/core/slither_core.py @@ -77,6 +77,8 @@ class Slither(Context): @property def solc_version(self): """str: Solidity version.""" + if self.crytic_compile: + return self.crytic_compile.compiler_version.version return self._solc_version @property diff --git a/slither/solc_parsing/declarations/contract.py b/slither/solc_parsing/declarations/contract.py index eb6021966..d36e9150a 100644 --- a/slither/solc_parsing/declarations/contract.py +++ b/slither/solc_parsing/declarations/contract.py @@ -20,7 +20,7 @@ class ContractSolc04(Contract): def __init__(self, slitherSolc, data): - assert slitherSolc.solc_version.startswith('0.4') + #assert slitherSolc.solc_version.startswith('0.4') super(ContractSolc04, self).__init__() self.set_slither(slitherSolc) diff --git a/slither/solc_parsing/slitherSolc.py b/slither/solc_parsing/slitherSolc.py index 70e276f19..8a695ae6a 100644 --- a/slither/solc_parsing/slitherSolc.py +++ b/slither/solc_parsing/slitherSolc.py @@ -104,30 +104,27 @@ class SlitherSolc(Slither): return for contract_data in data_loaded[self.get_children()]: - # if self.solc_version == '0.3': - # assert contract_data[self.get_key()] == 'Contract' - # contract = ContractSolc03(self, contract_data) - if self.solc_version == '0.4': - assert contract_data[self.get_key()] in ['ContractDefinition', 'PragmaDirective', 'ImportDirective'] - if contract_data[self.get_key()] == 'ContractDefinition': - contract = ContractSolc04(self, contract_data) - if 'src' in contract_data: - contract.set_offset(contract_data['src'], self) - self._contractsNotParsed.append(contract) - elif contract_data[self.get_key()] == 'PragmaDirective': - if self._is_compact_ast: - pragma = Pragma(contract_data['literals']) - else: - pragma = Pragma(contract_data['attributes']["literals"]) - pragma.set_offset(contract_data['src'], self) - self._pragma_directives.append(pragma) - elif contract_data[self.get_key()] == 'ImportDirective': - if self.is_compact_ast: - import_directive = Import(contract_data["absolutePath"]) - else: - import_directive = Import(contract_data['attributes']["absolutePath"]) - import_directive.set_offset(contract_data['src'], self) - self._import_directives.append(import_directive) + + assert contract_data[self.get_key()] in ['ContractDefinition', 'PragmaDirective', 'ImportDirective'] + if contract_data[self.get_key()] == 'ContractDefinition': + contract = ContractSolc04(self, contract_data) + if 'src' in contract_data: + contract.set_offset(contract_data['src'], self) + self._contractsNotParsed.append(contract) + elif contract_data[self.get_key()] == 'PragmaDirective': + if self._is_compact_ast: + pragma = Pragma(contract_data['literals']) + else: + pragma = Pragma(contract_data['attributes']["literals"]) + pragma.set_offset(contract_data['src'], self) + self._pragma_directives.append(pragma) + elif contract_data[self.get_key()] == 'ImportDirective': + if self.is_compact_ast: + import_directive = Import(contract_data["absolutePath"]) + else: + import_directive = Import(contract_data['attributes']["absolutePath"]) + import_directive.set_offset(contract_data['src'], self) + self._import_directives.append(import_directive) def _parse_source_unit(self, data, filename): diff --git a/slither/visitors/expression/constants_folding.py b/slither/visitors/expression/constants_folding.py index 60568881b..372a383b5 100644 --- a/slither/visitors/expression/constants_folding.py +++ b/slither/visitors/expression/constants_folding.py @@ -99,6 +99,13 @@ class ConstantFolding(ExpressionVisitor): raise NotConstant def _post_tuple_expression(self, expression): + if expression.expressions: + if len(expression.expressions) == 1: + cf = ConstantFolding(expression.expressions[0], self._type) + expr = cf.result() + assert isinstance(expr, Literal) + set_val(expression, int(expr.value)) + return raise NotConstant def _post_type_conversion(self, expression):