From 9e7ff8fd1db397fb7b96f5ae4b28d0935958a9a8 Mon Sep 17 00:00:00 2001 From: alpharush <0xalpharush@protonmail.com> Date: Tue, 24 Jan 2023 17:35:35 -0600 Subject: [PATCH] support duplicated func name for diff types in global using for --- slither/slithir/convert.py | 9 +++------ .../declarations/using_for_top_level.py | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/slither/slithir/convert.py b/slither/slithir/convert.py index 87a6b075b..f6feefb46 100644 --- a/slither/slithir/convert.py +++ b/slither/slithir/convert.py @@ -525,9 +525,7 @@ def _convert_type_contract(ir: Member) -> Assignment: raise SlithIRError(f"type({contract.name}).{ir.variable_right} is unknown") -def propagate_types( - ir: slither.slithir.operations.operation.Operation, node: "Node" -): # pylint: disable=too-many-locals +def propagate_types(ir: Operation, node: "Node"): # pylint: disable=too-many-locals # propagate the type node_function = node.function using_for = ( @@ -1425,9 +1423,8 @@ def look_for_library_or_top_level( for destination in using_for[t]: if isinstance(destination, FunctionTopLevel) and destination.name == ir.function_name: arguments = [ir.destination] + ir.arguments - if ( - len(destination.parameters) == len(arguments) - and _find_function_from_parameter(arguments, [destination], True) is not None + if len(destination.parameters) == len(arguments) and _find_function_from_parameter( + arguments, [destination], True ): internalcall = InternalCall(destination, ir.nbr_arguments, ir.lvalue, ir.type_call) internalcall.set_expression(ir.expression) diff --git a/slither/solc_parsing/declarations/using_for_top_level.py b/slither/solc_parsing/declarations/using_for_top_level.py index b16fadc40..d0598a734 100644 --- a/slither/solc_parsing/declarations/using_for_top_level.py +++ b/slither/solc_parsing/declarations/using_for_top_level.py @@ -49,7 +49,7 @@ class UsingForTopLevelSolc(CallerContextExpression): # pylint: disable=too-few- type_name = parse_type(self._type_name, self) self._using_for.using_for[type_name] = [] - if self._library_name is not None: + if self._library_name: library_name = parse_type(self._library_name, self) self._using_for.using_for[type_name].append(library_name) self._propagate_global(type_name) @@ -91,7 +91,12 @@ class UsingForTopLevelSolc(CallerContextExpression): # pylint: disable=too-few- self, function_name: str, type_name: Union[TypeAliasTopLevel, UserDefinedType] ) -> None: for tl_function in self.compilation_unit.functions_top_level: - if tl_function.name == function_name: + # The library function is bound to the first parameter's type + if ( + tl_function.name == function_name + and tl_function.parameters + and type_name == tl_function.parameters[0].type + ): self._using_for.using_for[type_name].append(tl_function) self._propagate_global(type_name) break @@ -108,7 +113,12 @@ class UsingForTopLevelSolc(CallerContextExpression): # pylint: disable=too-few- break if c.name == library_name: for cf in c.functions: - if cf.name == function_name: + # The library function is bound to the first parameter's type + if ( + cf.name == function_name + and cf.parameters + and type_name == cf.parameters[0].type + ): self._using_for.using_for[type_name].append(cf) self._propagate_global(type_name) found = True