From a58d99ac2df5e0a33ef10c40d1fbcd451748253d Mon Sep 17 00:00:00 2001 From: Josselin Date: Wed, 29 Jul 2020 09:12:11 +0200 Subject: [PATCH] Add --disallow-partial flag --- slither/__main__.py | 6 ++++++ slither/core/slither_core.py | 15 +++++++++++++++ slither/slither.py | 4 ++++ slither/solc_parsing/declarations/contract.py | 7 +++++-- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/slither/__main__.py b/slither/__main__.py index cc15e9c60..d0b043cd9 100644 --- a/slither/__main__.py +++ b/slither/__main__.py @@ -425,6 +425,12 @@ def parse_args(detector_classes, printer_classes): action='store_true', default=False) + # Disable the throw/catch on partial analyses + parser.add_argument('--disallow-partial', + help=argparse.SUPPRESS, + action="store_true", + default=False) + if len(sys.argv) == 1: parser.print_help(sys.stderr) sys.exit(1) diff --git a/slither/core/slither_core.py b/slither/core/slither_core.py index a4e186772..eb3fa8d72 100644 --- a/slither/core/slither_core.py +++ b/slither/core/slither_core.py @@ -59,6 +59,10 @@ class SlitherCore(Context): self._storage_layouts: Dict[str, Dict[str, Tuple[int, int]]] = {} + # If set to true, slither will not catch errors during parsing + self._disallow_partial: bool = False + + ################################################################################### ################################################################################### # region Source code @@ -365,6 +369,17 @@ class SlitherCore(Context): def contracts_with_missing_inheritance(self) -> Set: return self._contract_with_missing_inheritance + + @property + def disallow_partial(self) -> bool: + """ + Return true if partial analyses are disallowed + For example, codebase with duplicate names will lead to partial analyses + + :return: + """ + return self._disallow_partial + # endregion ################################################################################### ################################################################################### diff --git a/slither/slither.py b/slither/slither.py index 2eff55fa7..6d8f35a9d 100644 --- a/slither/slither.py +++ b/slither/slither.py @@ -43,6 +43,10 @@ class Slither(SlitherCore): """ super().__init__() self._parser: SlitherSolc # This could be another parser, like SlitherVyper, interface needs to be determined + + + self._disallow_partial: bool = kwargs.get("disallow_partial", False) + # list of files provided (see --splitted option) if isinstance(target, list): self._init_from_list(target) diff --git a/slither/solc_parsing/declarations/contract.py b/slither/solc_parsing/declarations/contract.py index d348cdccc..c89f4ff6e 100644 --- a/slither/solc_parsing/declarations/contract.py +++ b/slither/solc_parsing/declarations/contract.py @@ -337,8 +337,11 @@ class ContractSolc: ################################################################################### def log_incorrect_parsing(self, error): - LOGGER.error(error) - self._contract.is_incorrectly_parsed = True + if self._contract.slither.disallow_partial: + raise ParsingError(error) + else: + LOGGER.error(error) + self._contract.is_incorrectly_parsed = True def analyze_content_modifiers(self): try: