Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify calls to convert_type_of_high_and_internal_level_call #1577

Merged
merged 1 commit into from
Jan 10, 2023
Merged
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
20 changes: 17 additions & 3 deletions slither/slithir/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,8 @@ def propagate_types(ir, node: "Node"): # pylint: disable=too-many-locals
# UserdefinedType
t_type = t.type
if isinstance(t_type, Contract):
contract = node.file_scope.get_contract_from_name(t_type.name)
return convert_type_of_high_and_internal_level_call(ir, contract)
# the target contract of the IR is the t_type (the destination of the call)
return convert_type_of_high_and_internal_level_call(ir, t_type)

# Convert HighLevelCall to LowLevelCall
if (isinstance(t, ElementaryType) and t.name == "address") or (
Expand All @@ -557,6 +557,7 @@ def propagate_types(ir, node: "Node"): # pylint: disable=too-many-locals
# Cannot be a top level function with this.
assert isinstance(node_function, FunctionContract)
if ir.destination.name == "this":
# the target contract is the contract itself
return convert_type_of_high_and_internal_level_call(
ir, node_function.contract
)
Expand Down Expand Up @@ -591,6 +592,7 @@ def propagate_types(ir, node: "Node"): # pylint: disable=too-many-locals
function_contract = (
func.contract if isinstance(func, FunctionContract) else None
)
# the target contract might be None if its a top level function
convert_type_of_high_and_internal_level_call(ir, function_contract)
return_type = ir.function.return_type
if return_type:
Expand Down Expand Up @@ -1512,7 +1514,19 @@ def _convert_to_structure_to_list(return_type: Type) -> List[Type]:
return [return_type.type]


def convert_type_of_high_and_internal_level_call(ir: Operation, contract: Optional[Contract]):
def convert_type_of_high_and_internal_level_call(
ir: Operation, contract: Optional[Contract]
) -> Optional[Operation]:
"""
Convert the IR type based on heuristic

Args:
ir: target
contract: optional contract. This should be the target of the IR. It will be used to look up potential functions

Returns:
Potential new IR
"""
func = None
if isinstance(ir, InternalCall):
candidates: List[Function]
Expand Down