From 8135a237048085f9e914f8071270e7ca804f3f05 Mon Sep 17 00:00:00 2001 From: Simone Date: Wed, 22 Feb 2023 18:53:22 +0100 Subject: [PATCH 1/3] improve TypeAlias support for echidna --- slither/printers/guidance/echidna.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/slither/printers/guidance/echidna.py b/slither/printers/guidance/echidna.py index 0df47e965..0ee8a0901 100644 --- a/slither/printers/guidance/echidna.py +++ b/slither/printers/guidance/echidna.py @@ -28,6 +28,7 @@ from slither.slithir.operations import ( InternalCall, TypeConversion, ) +from slither.core.solidity_types import TypeAlias, Type from slither.slithir.operations.binary import Binary from slither.slithir.variables import Constant from slither.visitors.expression.constants_folding import ConstantFolding @@ -184,7 +185,11 @@ def _extract_constants_from_irs( # pylint: disable=too-many-branches,too-many-n all_cst_used.append(ConstantValue(str(cst.value), str(type_))) if isinstance(ir, TypeConversion): if isinstance(ir.variable, Constant): - all_cst_used.append(ConstantValue(str(ir.variable.value), str(ir.type))) + if isinstance(ir.type, TypeAlias): + value_type = ir.type.type + else: + value_type = ir.type + all_cst_used.append(ConstantValue(str(ir.variable.value), str(value_type))) continue if ( isinstance(ir, Member) From 56aaa4da4d2c71c199cc43c640754285943bd87a Mon Sep 17 00:00:00 2001 From: Simone Date: Wed, 22 Feb 2023 18:53:48 +0100 Subject: [PATCH 2/3] Fix TypeAlias in solidity signature --- slither/utils/type.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/slither/utils/type.py b/slither/utils/type.py index 5c7fcee34..a6688b13e 100644 --- a/slither/utils/type.py +++ b/slither/utils/type.py @@ -1,7 +1,7 @@ import math from typing import List, Union, Set -from slither.core.solidity_types import ArrayType, MappingType, ElementaryType, UserDefinedType +from slither.core.solidity_types import ArrayType, MappingType, ElementaryType, UserDefinedType, TypeAlias from slither.core.solidity_types.type import Type from slither.core.variables.variable import Variable @@ -88,6 +88,9 @@ def convert_type_for_solidity_signature(t: Type, seen: Set[Type]) -> Union[Type, for x in underlying_type.elems_ordered ] return types + + if isinstance(t, TypeAlias): + return t.type return t From 8c58abe6ad3a7259a84adb448b0411927f73cf22 Mon Sep 17 00:00:00 2001 From: Feist Josselin Date: Fri, 10 Mar 2023 11:18:51 +0100 Subject: [PATCH 3/3] Fix linters --- slither/printers/guidance/echidna.py | 4 ++-- slither/utils/type.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/slither/printers/guidance/echidna.py b/slither/printers/guidance/echidna.py index 0ee8a0901..b160dd0e6 100644 --- a/slither/printers/guidance/echidna.py +++ b/slither/printers/guidance/echidna.py @@ -12,6 +12,7 @@ from slither.core.declarations.solidity_variables import ( ) from slither.core.expressions import NewContract from slither.core.slither_core import SlitherCore +from slither.core.solidity_types import TypeAlias from slither.core.variables.state_variable import StateVariable from slither.core.variables.variable import Variable from slither.printers.abstract_printer import AbstractPrinter @@ -28,11 +29,10 @@ from slither.slithir.operations import ( InternalCall, TypeConversion, ) -from slither.core.solidity_types import TypeAlias, Type from slither.slithir.operations.binary import Binary from slither.slithir.variables import Constant -from slither.visitors.expression.constants_folding import ConstantFolding from slither.utils.output import Output +from slither.visitors.expression.constants_folding import ConstantFolding def _get_name(f: Union[Function, Variable]) -> str: diff --git a/slither/utils/type.py b/slither/utils/type.py index a6688b13e..1674999aa 100644 --- a/slither/utils/type.py +++ b/slither/utils/type.py @@ -1,7 +1,13 @@ import math from typing import List, Union, Set -from slither.core.solidity_types import ArrayType, MappingType, ElementaryType, UserDefinedType, TypeAlias +from slither.core.solidity_types import ( + ArrayType, + MappingType, + ElementaryType, + UserDefinedType, + TypeAlias, +) from slither.core.solidity_types.type import Type from slither.core.variables.variable import Variable @@ -88,7 +94,7 @@ def convert_type_for_solidity_signature(t: Type, seen: Set[Type]) -> Union[Type, for x in underlying_type.elems_ordered ] return types - + if isinstance(t, TypeAlias): return t.type