Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions slither/visitors/expression/constants_folding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -442,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)