From ee82e1016420d80b68195988fc4a31f164bfd9d8 Mon Sep 17 00:00:00 2001 From: alpharush <0xalpharush@protonmail.com> Date: Wed, 6 Jul 2022 17:29:16 -0500 Subject: [PATCH] fix argument propagation for .unwrap --- slither/slithir/convert.py | 14 +++++++++++--- .../{argument.sol => argument-0.8.9.sol} | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) rename tests/ast-parsing/user_defined_value_type/{argument.sol => argument-0.8.9.sol} (86%) diff --git a/slither/slithir/convert.py b/slither/slithir/convert.py index 35fc8e11a..ef5cacc16 100644 --- a/slither/slithir/convert.py +++ b/slither/slithir/convert.py @@ -400,6 +400,13 @@ def propagate_type_and_convert_call(result, node): ins = new_ins result[idx] = ins + # If there's two consecutive type conversions, keep only the last + # ARG_CALL x call_data = [x] + # TMP_4 = CONVERT x to Fix call_data = [] + # TMP_5 = CONVERT TMP_4 to uint192 call_data = [TMP_5] + if isinstance(ins, TypeConversion) and ins.variable in call_data: + call_data.remove(ins.variable) + if isinstance(ins, Argument): # In case of dupplicate arguments we overwrite the value # This can happen because of addr.call.value(1).value(2) @@ -429,10 +436,10 @@ def propagate_type_and_convert_call(result, node): continue new_ins = propagate_types(ins, node) - # Validate that type was propagated - if isinstance(new_ins, OperationWithLValue): - assert new_ins.lvalue.type if new_ins: + # Validate that type was propagated + if isinstance(new_ins, OperationWithLValue): + assert new_ins.lvalue.type if isinstance(new_ins, (list,)): for new_ins_ in new_ins: new_ins_.set_node(ins.node) @@ -1682,6 +1689,7 @@ def convert_constant_types(irs): # TODO: add POP instruction break types = [p.type for p in func.parameters] + assert len(types) == len(ir.arguments) for idx, arg in enumerate(ir.arguments): t = types[idx] if isinstance(t, ElementaryType): diff --git a/tests/ast-parsing/user_defined_value_type/argument.sol b/tests/ast-parsing/user_defined_value_type/argument-0.8.9.sol similarity index 86% rename from tests/ast-parsing/user_defined_value_type/argument.sol rename to tests/ast-parsing/user_defined_value_type/argument-0.8.9.sol index 7bdc7d560..55fe237e1 100644 --- a/tests/ast-parsing/user_defined_value_type/argument.sol +++ b/tests/ast-parsing/user_defined_value_type/argument-0.8.9.sol @@ -11,7 +11,7 @@ contract FixLib { uint256 y = uint192(Fix.unwrap(x)); return div(y, 1e18); } - function broken(Fix x) external pure returns (uint256) { + function test(Fix x) external pure returns (uint256) { return div(uint192(Fix.unwrap(x)), 1e18); } }