From 2023f9997da63710eeab86bc72af054927c5513e Mon Sep 17 00:00:00 2001 From: Josselin Date: Mon, 29 Mar 2021 14:18:22 +0200 Subject: [PATCH 1/2] Improve parsing of Solidity 0.8 --- .../expressions/expression_parsing.py | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/slither/solc_parsing/expressions/expression_parsing.py b/slither/solc_parsing/expressions/expression_parsing.py index 4a3f5109ff..67d7755d52 100644 --- a/slither/solc_parsing/expressions/expression_parsing.py +++ b/slither/solc_parsing/expressions/expression_parsing.py @@ -892,7 +892,16 @@ def parse_expression(expression: Dict, caller_context: CallerContext) -> "Expres assert type_name[caller_context.get_key()] == "UserDefinedTypeName" if is_compact_ast: - contract_name = type_name["name"] + + # Changed introduced in Solidity 0.8 + # see https://github.com/crytic/slither/issues/794 + + # TODO explore more the changes introduced in 0.8 and the usage of pathNode/IdentifierPath + if "name" not in type_name: + assert 'pathNode' in type_name and 'name' in type_name['pathNode'] + contract_name = type_name['pathNode']['name'] + else: + contract_name = type_name["name"] else: contract_name = type_name["attributes"]["name"] new = NewContract(contract_name) @@ -924,4 +933,23 @@ def parse_expression(expression: Dict, caller_context: CallerContext) -> "Expres base = parse_expression(expression["baseExpression"], caller_context) return base + # Introduced with solc 0.8 + if name == "IdentifierPath": + + if caller_context.is_compact_ast: + value = expression["name"] + + if "referencedDeclaration" in expression: + referenced_declaration = expression["referencedDeclaration"] + else: + referenced_declaration = None + + var = find_variable(value, caller_context, referenced_declaration) + + identifier = Identifier(var) + identifier.set_offset(src, caller_context.slither) + return identifier + + raise ParsingError('IdentifierPath not currently supported for the legacy ast') + raise ParsingError("Expression not parsed %s" % name) From d40adea7f121d4b03248b85efc504c73ffd18376 Mon Sep 17 00:00:00 2001 From: Josselin Date: Mon, 29 Mar 2021 14:22:23 +0200 Subject: [PATCH 2/2] black --- slither/solc_parsing/expressions/expression_parsing.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/slither/solc_parsing/expressions/expression_parsing.py b/slither/solc_parsing/expressions/expression_parsing.py index 67d7755d52..480bdc9379 100644 --- a/slither/solc_parsing/expressions/expression_parsing.py +++ b/slither/solc_parsing/expressions/expression_parsing.py @@ -898,8 +898,8 @@ def parse_expression(expression: Dict, caller_context: CallerContext) -> "Expres # TODO explore more the changes introduced in 0.8 and the usage of pathNode/IdentifierPath if "name" not in type_name: - assert 'pathNode' in type_name and 'name' in type_name['pathNode'] - contract_name = type_name['pathNode']['name'] + assert "pathNode" in type_name and "name" in type_name["pathNode"] + contract_name = type_name["pathNode"]["name"] else: contract_name = type_name["name"] else: @@ -950,6 +950,6 @@ def parse_expression(expression: Dict, caller_context: CallerContext) -> "Expres identifier.set_offset(src, caller_context.slither) return identifier - raise ParsingError('IdentifierPath not currently supported for the legacy ast') + raise ParsingError("IdentifierPath not currently supported for the legacy ast") raise ParsingError("Expression not parsed %s" % name)