Skip to content

Commit

Permalink
fix: external calls
Browse files Browse the repository at this point in the history
  • Loading branch information
devtooligan committed Jul 7, 2023
1 parent 251dee0 commit 6843d03
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion slither/utils/martin.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ def update_abstractness(self) -> float:
abstract_contract_count += 1
self.abstractness = float(abstract_contract_count / len(self.contracts))

# pylint: disable=too-many-branches
def update_coupling(self) -> Dict:
dependencies = {}
for contract in self.contracts:
external_calls = []
for func in contract.functions:
high_level_calls = [
ir
Expand All @@ -116,7 +118,29 @@ def update_coupling(self) -> Dict:
if isinstance(ir, HighLevelCall)
]
# convert irs to string with target function and contract name
external_calls = [h.destination.type.type.name for h in high_level_calls]
# Get the target contract name for each high level call
new_external_calls = []
for high_level_call in high_level_calls:
if isinstance(high_level_call.destination, Contract):
new_external_call = high_level_call.destination.name
elif isinstance(high_level_call.destination, str):
new_external_call = high_level_call.destination
elif not hasattr(high_level_call.destination, "type"):
continue
elif isinstance(high_level_call.destination.type, Contract):
new_external_call = high_level_call.destination.type.name
elif isinstance(high_level_call.destination.type, str):
new_external_call = high_level_call.destination.type
elif not hasattr(high_level_call.destination.type, "type"):
continue
elif isinstance(high_level_call.destination.type.type, Contract):
new_external_call = high_level_call.destination.type.type.name
elif isinstance(high_level_call.destination.type.type, str):
new_external_call = high_level_call.destination.type.type
else:
continue
new_external_calls.append(new_external_call)
external_calls.extend(new_external_calls)
dependencies[contract.name] = set(external_calls)
dependents = {}
for contract, deps in dependencies.items():
Expand Down

0 comments on commit 6843d03

Please sign in to comment.