From beb6dd925fb360a45b6077861c49bfad5610da79 Mon Sep 17 00:00:00 2001 From: Simone Date: Mon, 26 May 2025 19:25:45 +0200 Subject: [PATCH 1/2] Fix crash when casting an address and accessing its members --- slither/visitors/expression/constants_folding.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/slither/visitors/expression/constants_folding.py b/slither/visitors/expression/constants_folding.py index 65574df67a..a576b044ab 100644 --- a/slither/visitors/expression/constants_folding.py +++ b/slither/visitors/expression/constants_folding.py @@ -356,6 +356,14 @@ def _post_member_access(self, expression: expressions.MemberAccess) -> None: ): # User defined type .wrap call handled in _post_call_expression return + elif ( + isinstance(expression.expression, TypeConversion) + and expression.expression.type == ElementaryType("address") + and expression.member_name in ["balance", "code", "codehash"] + ): + # We need to raise NotConstant for these case here otherwise expression.expression.value would crash in the following condition + # because TypeConversion does not have a value. See https://github.com/crytic/slither/issues/2717 + raise NotConstant elif ( isinstance(expression.expression.value, Contract) and expression.member_name in expression.expression.value.variables_as_dict From 666e61b9ff9a75134115b2d6b02c6543fac8b3ef Mon Sep 17 00:00:00 2001 From: Simone Date: Mon, 26 May 2025 19:26:46 +0200 Subject: [PATCH 2/2] Fix crash when casting a string to byte* --- slither/visitors/expression/constants_folding.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/slither/visitors/expression/constants_folding.py b/slither/visitors/expression/constants_folding.py index a576b044ab..27c4e7501f 100644 --- a/slither/visitors/expression/constants_folding.py +++ b/slither/visitors/expression/constants_folding.py @@ -450,6 +450,8 @@ def _post_type_conversion(self, expression: expressions.TypeConversion) -> None: value = int.from_bytes(expr.value, "big") elif str(expression.type).startswith("byte") and isinstance(expr.value, int): value = int.to_bytes(expr.value, 32, "big") + elif str(expression.type).startswith("byte") and isinstance(expr.value, str): + value = expr.value else: value = convert_string_to_fraction(expr.converted_value) set_val(expression, value)