From 42ed0db443ed443fc75afb44e38c4723ee81f937 Mon Sep 17 00:00:00 2001 From: alpharush <0xalpharush@protonmail.com> Date: Wed, 29 Mar 2023 22:38:09 -0500 Subject: [PATCH] remove is_top_level dead code --- slither/core/compilation_unit.py | 2 +- slither/core/declarations/contract.py | 2 -- slither/printers/functions/authorization.py | 2 -- slither/printers/functions/cfg.py | 2 -- slither/printers/inheritance/inheritance.py | 4 ---- slither/printers/inheritance/inheritance_graph.py | 2 -- slither/printers/summary/contract.py | 3 --- slither/printers/summary/data_depenency.py | 2 -- slither/printers/summary/function.py | 2 -- slither/printers/summary/human_summary.py | 2 +- slither/printers/summary/slithir.py | 2 -- slither/printers/summary/slithir_ssa.py | 2 -- slither/solc_parsing/slither_compilation_unit_solc.py | 5 +---- 13 files changed, 3 insertions(+), 29 deletions(-) diff --git a/slither/core/compilation_unit.py b/slither/core/compilation_unit.py index 8d7167451..4550ea894 100644 --- a/slither/core/compilation_unit.py +++ b/slither/core/compilation_unit.py @@ -128,7 +128,7 @@ class SlitherCompilationUnit(Context): """list(Contract): List of contracts that are derived and not inherited.""" inheritances = [x.inheritance for x in self.contracts] inheritance = [item for sublist in inheritances for item in sublist] - return [c for c in self.contracts if c not in inheritance and not c.is_top_level] + return [c for c in self.contracts if c not in inheritance] def get_contract_from_name(self, contract_name: Union[str, Constant]) -> List[Contract]: """ diff --git a/slither/core/declarations/contract.py b/slither/core/declarations/contract.py index fd8f761c6..821ccda57 100644 --- a/slither/core/declarations/contract.py +++ b/slither/core/declarations/contract.py @@ -97,8 +97,6 @@ class Contract(SourceMapping): # pylint: disable=too-many-public-methods self._is_upgradeable_proxy: Optional[bool] = None self._upgradeable_version: Optional[str] = None - self.is_top_level = False # heavily used, so no @property - self._initial_state_variables: List["StateVariable"] = [] # ssa self._is_incorrectly_parsed: bool = False diff --git a/slither/printers/functions/authorization.py b/slither/printers/functions/authorization.py index 48b94c297..32efeaabe 100644 --- a/slither/printers/functions/authorization.py +++ b/slither/printers/functions/authorization.py @@ -47,8 +47,6 @@ class PrinterWrittenVariablesAndAuthorization(AbstractPrinter): txt = "" all_tables = [] for contract in self.contracts: # type: ignore - if contract.is_top_level: - continue txt += f"\nContract {contract.name}\n" table = MyPrettyTable( ["Function", "State variables written", "Conditions on msg.sender"] diff --git a/slither/printers/functions/cfg.py b/slither/printers/functions/cfg.py index 3c75f723f..00804a34d 100644 --- a/slither/printers/functions/cfg.py +++ b/slither/printers/functions/cfg.py @@ -19,8 +19,6 @@ class CFG(AbstractPrinter): info = "" all_files = [] for contract in self.contracts: # type: ignore - if contract.is_top_level: - continue for function in contract.functions + list(contract.modifiers): if filename: new_filename = f"{filename}-{contract.name}-{function.full_name}.dot" diff --git a/slither/printers/inheritance/inheritance.py b/slither/printers/inheritance/inheritance.py index 08c05f95f..4ef961a5a 100644 --- a/slither/printers/inheritance/inheritance.py +++ b/slither/printers/inheritance/inheritance.py @@ -36,8 +36,6 @@ class PrinterInheritance(AbstractPrinter): result = {"child_to_base": {}} for child in self.contracts: - if child.is_top_level: - continue info += blue(f"\n+ {child.name}\n") result["child_to_base"][child.name] = {"immediate": [], "not_immediate": []} if child.inheritance: @@ -58,8 +56,6 @@ class PrinterInheritance(AbstractPrinter): result["base_to_child"] = {} for base in self.contracts: - if base.is_top_level: - continue info += green(f"\n+ {base.name}") + "\n" children = list(self._get_child_contracts(base)) diff --git a/slither/printers/inheritance/inheritance_graph.py b/slither/printers/inheritance/inheritance_graph.py index 2ec9dee1a..95022c067 100644 --- a/slither/printers/inheritance/inheritance_graph.py +++ b/slither/printers/inheritance/inheritance_graph.py @@ -194,8 +194,6 @@ class PrinterInheritanceGraph(AbstractPrinter): content = 'digraph "" {\n' for c in self.contracts: - if c.is_top_level: - continue content += self._summary(c) + "\n" content += "}" diff --git a/slither/printers/summary/contract.py b/slither/printers/summary/contract.py index 5fee94416..3980c63fc 100644 --- a/slither/printers/summary/contract.py +++ b/slither/printers/summary/contract.py @@ -28,9 +28,6 @@ class ContractSummary(AbstractPrinter): all_contracts = [] for c in self.contracts: - if c.is_top_level: - continue - is_upgradeable_proxy = c.is_upgradeable_proxy is_upgradeable = c.is_upgradeable diff --git a/slither/printers/summary/data_depenency.py b/slither/printers/summary/data_depenency.py index f1c0dc8d5..864652978 100644 --- a/slither/printers/summary/data_depenency.py +++ b/slither/printers/summary/data_depenency.py @@ -40,8 +40,6 @@ class DataDependency(AbstractPrinter): txt = "" for c in self.contracts: - if c.is_top_level: - continue txt += f"\nContract {c.name}\n" table = MyPrettyTable(["Variable", "Dependencies"]) for v in c.state_variables: diff --git a/slither/printers/summary/function.py b/slither/printers/summary/function.py index 7f1633865..232980425 100644 --- a/slither/printers/summary/function.py +++ b/slither/printers/summary/function.py @@ -33,8 +33,6 @@ class FunctionSummary(AbstractPrinter): all_txt = "" for c in self.contracts: - if c.is_top_level: - continue (name, inheritance, var, func_summaries, modif_summaries) = c.get_summary() txt = f"\nContract {name}" txt += "\nContract vars: " + str(var) diff --git a/slither/printers/summary/human_summary.py b/slither/printers/summary/human_summary.py index ec8663198..2fc72f922 100644 --- a/slither/printers/summary/human_summary.py +++ b/slither/printers/summary/human_summary.py @@ -205,7 +205,7 @@ class PrinterHumanSummary(AbstractPrinter): def _number_contracts(self): if self.slither.crytic_compile is None: return len(self.slither.contracts), 0, 0 - contracts = [c for c in self.slither.contracts if not c.is_top_level] + contracts = [c for c in self.slither.contracts] deps = [c for c in contracts if c.is_from_dependency()] tests = [c for c in contracts if c.is_test] return len(contracts) - len(deps) - len(tests), len(deps), len(tests) diff --git a/slither/printers/summary/slithir.py b/slither/printers/summary/slithir.py index be9ebc8f5..cbdb50dcc 100644 --- a/slither/printers/summary/slithir.py +++ b/slither/printers/summary/slithir.py @@ -36,8 +36,6 @@ class PrinterSlithIR(AbstractPrinter): txt = "" for compilation_unit in self.slither.compilation_units: for contract in compilation_unit.contracts: - if contract.is_top_level: - continue txt += f"Contract {contract.name}\n" for function in contract.functions: txt += f'\tFunction {function.canonical_name} {"" if function.is_shadowed else "(*)"}\n' diff --git a/slither/printers/summary/slithir_ssa.py b/slither/printers/summary/slithir_ssa.py index e7f2ca1e3..052597299 100644 --- a/slither/printers/summary/slithir_ssa.py +++ b/slither/printers/summary/slithir_ssa.py @@ -21,8 +21,6 @@ class PrinterSlithIRSSA(AbstractPrinter): txt = "" for contract in self.contracts: - if contract.is_top_level: - continue txt += f"Contract {contract.name}" + "\n" for function in contract.functions: txt += f"\tFunction {function.canonical_name}" + "\n" diff --git a/slither/solc_parsing/slither_compilation_unit_solc.py b/slither/solc_parsing/slither_compilation_unit_solc.py index b1c2387f0..cb94a7d9e 100644 --- a/slither/solc_parsing/slither_compilation_unit_solc.py +++ b/slither/solc_parsing/slither_compilation_unit_solc.py @@ -402,10 +402,7 @@ class SlitherCompilationUnitSolc(CallerContextExpression): # First we save all the contracts in a dict # the key is the contractid for contract in self._underlying_contract_to_parser: - if ( - contract.name.startswith("SlitherInternalTopLevelContract") - and not contract.is_top_level - ): + if contract.name.startswith("SlitherInternalTopLevelContract"): raise SlitherException( # region multi-line-string """Your codebase has a contract named 'SlitherInternalTopLevelContract'.