Skip to content

Commit

Permalink
Merge pull request #1938 from webthethird/upgradeability-util-bug-fix
Browse files Browse the repository at this point in the history
Improved `is_function_modified` in upgradeability util
  • Loading branch information
montyly authored Jun 22, 2023
2 parents f9d2573 + 14700e7 commit 23d3175
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions slither/utils/upgradeability.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ def is_function_modified(f1: Function, f2: Function) -> bool:
visited.extend([node_f1, node_f2])
queue_f1.extend(son for son in node_f1.sons if son not in visited)
queue_f2.extend(son for son in node_f2.sons if son not in visited)
if len(node_f1.irs) != len(node_f2.irs):
return True
for i, ir in enumerate(node_f1.irs):
if encode_ir_for_compare(ir) != encode_ir_for_compare(node_f2.irs[i]):
return True
Expand Down Expand Up @@ -273,13 +275,13 @@ def encode_ir_for_compare(ir: Operation) -> str:
if isinstance(ir, Assignment):
return f"({encode_var_for_compare(ir.lvalue)}):=({encode_var_for_compare(ir.rvalue)})"
if isinstance(ir, Index):
return f"index({ntype(ir.index_type)})"
return f"index({ntype(ir.variable_right.type)})"
if isinstance(ir, Member):
return "member" # .format(ntype(ir._type))
if isinstance(ir, Length):
return "length"
if isinstance(ir, Binary):
return f"binary({str(ir.variable_left)}{str(ir.type)}{str(ir.variable_right)})"
return f"binary({encode_var_for_compare(ir.variable_left)}{ir.type}{encode_var_for_compare(ir.variable_right)})"
if isinstance(ir, Unary):
return f"unary({str(ir.type)})"
if isinstance(ir, Condition):
Expand Down Expand Up @@ -330,7 +332,7 @@ def encode_var_for_compare(var: Variable) -> str:

# variables
if isinstance(var, Constant):
return f"constant({ntype(var.type)})"
return f"constant({ntype(var.type)},{var.value})"
if isinstance(var, SolidityVariableComposed):
return f"solidity_variable_composed({var.name})"
if isinstance(var, SolidityVariable):
Expand All @@ -340,9 +342,16 @@ def encode_var_for_compare(var: Variable) -> str:
if isinstance(var, ReferenceVariable):
return f"reference({ntype(var.type)})"
if isinstance(var, LocalVariable):
return f"local_solc_variable({var.location})"
return f"local_solc_variable({ntype(var.type)},{var.location})"
if isinstance(var, StateVariable):
return f"state_solc_variable({ntype(var.type)})"
if not (var.is_constant or var.is_immutable):
try:
slot, _ = var.contract.compilation_unit.storage_layout_of(var.contract, var)
except KeyError:
slot = var.name
else:
slot = var.name
return f"state_solc_variable({ntype(var.type)},{slot})"
if isinstance(var, LocalVariableInitFromTuple):
return "local_variable_init_tuple"
if isinstance(var, TupleVariable):
Expand Down

0 comments on commit 23d3175

Please sign in to comment.