From de1b7618b7624d792410b4486fd96cb5ee5aa68c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= Date: Mon, 26 Sep 2022 13:46:00 -0300 Subject: [PATCH] Platform detection check --- slither/tools/doctor/__main__.py | 65 ++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/slither/tools/doctor/__main__.py b/slither/tools/doctor/__main__.py index 25d764d47..410fabd33 100644 --- a/slither/tools/doctor/__main__.py +++ b/slither/tools/doctor/__main__.py @@ -1,21 +1,9 @@ import argparse -import logging +from pathlib import Path from crytic_compile import cryticparser - - -logging.basicConfig() -logging.getLogger("Slither").setLevel(logging.INFO) - -logger = logging.getLogger("Slither-doctor") -logger.setLevel(logging.INFO) - -ch = logging.StreamHandler() -ch.setLevel(logging.INFO) -formatter = logging.Formatter("%(message)s") -logger.addHandler(ch) -logger.handlers[0].setFormatter(formatter) -logger.propagate = False +import crytic_compile.crytic_compile as crytic_compile +from slither.utils.colors import red, yellow, green def parse_args(): @@ -36,10 +24,55 @@ def parse_args(): return parser.parse_args() +def detect_platform(project: str, **kwargs): + print("## Project platform") + print() + + path = Path(project) + if path.is_file(): + print( + yellow( + f"{project!r} is a file. Using it as target will manually compile your code with solc and _not_ use a compilation framework. Is that what you meant to do?" + ) + ) + return + + print(f"Trying to detect project type for {project!r}") + + supported_platforms = crytic_compile.get_platforms() + skip_platforms = {"solc", "solc-json", "archive", "standard", "etherscan"} + detected_platforms = { + platform.NAME: platform.is_supported(project, **kwargs) + for platform in supported_platforms + if platform.NAME.lower() not in skip_platforms + } + platform_qty = len([platform for platform, state in detected_platforms.items() if state]) + + print("Is this project using...") + for platform, state in detected_platforms.items(): + print(f" => {platform + '?':<15}{state and green('Yes') or red('No')}") + print() + + if platform_qty == 0: + print(red("No platform was detected! This doesn't sound right.")) + print( + yellow( + "Are you trying to analyze a folder with standalone solidity files, without using a compilation framework? If that's the case, then this is okay." + ) + ) + elif platform_qty > 1: + print(red("More than one platform was detected! This doesn't sound right.")) + print(red("Please use `--compile-force-framework` in Slither to force the correct framework.")) + else: + print(green("A single platform was detected."), yellow("Is it the one you expected?")) + + def main(): args = parse_args() - print("Hello world") + detect_platform(args.project) + + # TODO other checks if __name__ == "__main__":