From 25d1c6e61e8fb6b320dca2bcec36e98fbf59503e Mon Sep 17 00:00:00 2001 From: alpharush <0xalpharush@protonmail.com> Date: Fri, 8 Sep 2023 17:55:04 -0500 Subject: [PATCH] also support reference id for legacy AST --- slither/solc_parsing/expressions/expression_parsing.py | 9 +++++---- slither/solc_parsing/expressions/find_variable.py | 6 ++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/slither/solc_parsing/expressions/expression_parsing.py b/slither/solc_parsing/expressions/expression_parsing.py index a0bce044c2..c192b4efee 100644 --- a/slither/solc_parsing/expressions/expression_parsing.py +++ b/slither/solc_parsing/expressions/expression_parsing.py @@ -486,13 +486,18 @@ def parse_expression(expression: Dict, caller_context: CallerContextExpression) t = None + referenced_declaration = None if caller_context.is_compact_ast: value = expression["name"] t = expression["typeDescriptions"]["typeString"] + if "referencedDeclaration" in expression: + referenced_declaration = expression["referencedDeclaration"] else: value = expression["attributes"]["value"] if "type" in expression["attributes"]: t = expression["attributes"]["type"] + if "referencedDeclaration" in expression["attributes"]: + referenced_declaration = expression["attributes"]["referencedDeclaration"] if t: found = re.findall(r"[struct|enum|function|modifier] \(([\[\] ()a-zA-Z0-9\.,_]*)\)", t) @@ -501,10 +506,6 @@ def parse_expression(expression: Dict, caller_context: CallerContextExpression) value = value + "(" + found[0] + ")" value = filter_name(value) - if "referencedDeclaration" in expression: - referenced_declaration = expression["referencedDeclaration"] - else: - referenced_declaration = None var, was_created = find_variable(value, caller_context, referenced_declaration) if was_created: var.set_offset(src, caller_context.compilation_unit) diff --git a/slither/solc_parsing/expressions/find_variable.py b/slither/solc_parsing/expressions/find_variable.py index 6255ee51ff..b7e28a8912 100644 --- a/slither/solc_parsing/expressions/find_variable.py +++ b/slither/solc_parsing/expressions/find_variable.py @@ -63,10 +63,8 @@ def _find_variable_from_ref_declaration( if referenced_declaration is None: return None # We look for variable declared with the referencedDeclaration attribute - if function_parser is not None: - func_variables_renamed = function_parser.variables_renamed - if referenced_declaration in func_variables_renamed: - return func_variables_renamed[referenced_declaration].underlying_variable + if function_parser is not None and referenced_declaration in function_parser.variables_renamed: + return function_parser.variables_renamed[referenced_declaration].underlying_variable if ( contract_declarer is not None