From 1833299dd99d2a4c4a9a88034c3f459647f9d634 Mon Sep 17 00:00:00 2001 From: Simone Date: Wed, 9 Aug 2023 16:50:40 +0200 Subject: [PATCH 01/14] Add config function --- crytic_compile/platform/abstract_platform.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/crytic_compile/platform/abstract_platform.py b/crytic_compile/platform/abstract_platform.py index c266520a..3555abdd 100644 --- a/crytic_compile/platform/abstract_platform.py +++ b/crytic_compile/platform/abstract_platform.py @@ -4,7 +4,7 @@ This gives the skeleton for any platform supported by crytic-compile """ import abc -from typing import TYPE_CHECKING, List, Dict +from typing import TYPE_CHECKING, List, Dict, Any, Optional from crytic_compile.platform import Type from crytic_compile.utils.unit_tests import guess_tests @@ -154,6 +154,19 @@ def is_dependency(self, path: str) -> bool: """ return False + @staticmethod + @abc.abstractmethod + def config(working_dir: str) -> Optional[Dict[str, Any]]: + """Return configuration data that should be passed to solc, such as version, remappings ecc. + + Args: + working_dir (str): path to the target + + Returns: + Optional[Dict[str, Any]]: Data such as version, remappings ecc + """ + return None + # Only _guessed_tests is an abstract method # guessed_tests will call the generic guess_tests and appends to the list # platforms-dependent tests From a7a508023c2a600652aa0a93d7aa6e0966b94e89 Mon Sep 17 00:00:00 2001 From: Simone Date: Wed, 9 Aug 2023 16:51:08 +0200 Subject: [PATCH 02/14] Add default config function --- crytic_compile/platform/archive.py | 14 +++++++++++++- crytic_compile/platform/brownie.py | 14 +++++++++++++- crytic_compile/platform/buidler.py | 14 +++++++++++++- crytic_compile/platform/dapp.py | 14 +++++++++++++- crytic_compile/platform/embark.py | 14 +++++++++++++- crytic_compile/platform/etherlime.py | 14 +++++++++++++- crytic_compile/platform/etherscan.py | 14 +++++++++++++- crytic_compile/platform/hardhat.py | 12 ++++++++++++ crytic_compile/platform/solc.py | 12 ++++++++++++ crytic_compile/platform/truffle.py | 14 +++++++++++++- crytic_compile/platform/vyper.py | 14 +++++++++++++- crytic_compile/platform/waffle.py | 14 +++++++++++++- 12 files changed, 154 insertions(+), 10 deletions(-) diff --git a/crytic_compile/platform/archive.py b/crytic_compile/platform/archive.py index e7fc417d..f7ed0faf 100644 --- a/crytic_compile/platform/archive.py +++ b/crytic_compile/platform/archive.py @@ -7,7 +7,7 @@ import json import os from pathlib import Path -from typing import TYPE_CHECKING, Dict, List, Tuple, Type, Any +from typing import TYPE_CHECKING, Dict, List, Tuple, Type, Any, Optional from crytic_compile.platform import Type as TypePlatform from crytic_compile.platform import standard @@ -118,6 +118,18 @@ def is_supported(target: str, **kwargs: str) -> bool: return False return Path(target).parts[-1].endswith("_export_archive.json") + @staticmethod + def config(working_dir: str) -> Optional[Dict[str, Any]]: + """Return configuration data that should be passed to solc, such as remappings. + + Args: + working_dir (str): path to the working directory + + Returns: + Dict[str, Any]: Data such as remappings + """ + return None + def is_dependency(self, _path: str) -> bool: """Check if the _path is a dependency. Always false diff --git a/crytic_compile/platform/brownie.py b/crytic_compile/platform/brownie.py index 855d7269..22db2191 100755 --- a/crytic_compile/platform/brownie.py +++ b/crytic_compile/platform/brownie.py @@ -8,7 +8,7 @@ import shutil import subprocess from pathlib import Path -from typing import TYPE_CHECKING, Dict, List, Optional +from typing import TYPE_CHECKING, Dict, List, Optional, Any from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion @@ -114,6 +114,18 @@ def is_supported(target: str, **kwargs: str) -> bool: or os.path.isfile(os.path.join(target, "brownie-config.yml")) ) + @staticmethod + def config(working_dir: str) -> Optional[Dict[str, Any]]: + """Return configuration data that should be passed to solc, such as remappings. + + Args: + working_dir (str): path to the working directory + + Returns: + Dict[str, Any]: Data such as remappings + """ + return None + def is_dependency(self, _path: str) -> bool: """Check if the path is a dependency (not supported for brownie) diff --git a/crytic_compile/platform/buidler.py b/crytic_compile/platform/buidler.py index 3f577d9f..9689d034 100755 --- a/crytic_compile/platform/buidler.py +++ b/crytic_compile/platform/buidler.py @@ -7,7 +7,7 @@ import shutil import subprocess from pathlib import Path -from typing import TYPE_CHECKING, List, Tuple +from typing import TYPE_CHECKING, List, Tuple, Optional, Dict, Any from crytic_compile.compiler.compiler import CompilerVersion from crytic_compile.platform.exceptions import InvalidCompilation @@ -193,6 +193,18 @@ def is_supported(target: str, **kwargs: str) -> bool: is_typescript = os.path.isfile(os.path.join(target, "buidler.config.ts")) return is_javascript or is_typescript + @staticmethod + def config(working_dir: str) -> Optional[Dict[str, Any]]: + """Return configuration data that should be passed to solc, such as remappings. + + Args: + working_dir (str): path to the working directory + + Returns: + Dict[str, Any]: Data such as remappings + """ + return None + def is_dependency(self, path: str) -> bool: """Check if the path is a dependency diff --git a/crytic_compile/platform/dapp.py b/crytic_compile/platform/dapp.py index 5749569b..c788bec5 100755 --- a/crytic_compile/platform/dapp.py +++ b/crytic_compile/platform/dapp.py @@ -12,7 +12,7 @@ from pathlib import Path # Cycle dependency -from typing import TYPE_CHECKING, List, Optional +from typing import TYPE_CHECKING, List, Optional, Dict, Any from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion @@ -157,6 +157,18 @@ def is_supported(target: str, **kwargs: str) -> bool: return "dapp " in txt return False + @staticmethod + def config(working_dir: str) -> Optional[Dict[str, Any]]: + """Return configuration data that should be passed to solc, such as remappings. + + Args: + working_dir (str): path to the working directory + + Returns: + Dict[str, Any]: Data such as remappings + """ + return None + def is_dependency(self, path: str) -> bool: """Check if the path is a dependency (not supported for brownie) diff --git a/crytic_compile/platform/embark.py b/crytic_compile/platform/embark.py index 37503413..189c51cc 100755 --- a/crytic_compile/platform/embark.py +++ b/crytic_compile/platform/embark.py @@ -8,7 +8,7 @@ import shutil import subprocess from pathlib import Path -from typing import TYPE_CHECKING, List +from typing import TYPE_CHECKING, List, Dict, Any, Optional from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion @@ -200,6 +200,18 @@ def is_supported(target: str, **kwargs: str) -> bool: return False return os.path.isfile(os.path.join(target, "embark.json")) + @staticmethod + def config(working_dir: str) -> Optional[Dict[str, Any]]: + """Return configuration data that should be passed to solc, such as remappings. + + Args: + working_dir (str): path to the working directory + + Returns: + Dict[str, Any]: Data such as remappings + """ + return None + def is_dependency(self, path: str) -> bool: """Check if the path is a dependency diff --git a/crytic_compile/platform/etherlime.py b/crytic_compile/platform/etherlime.py index e677b60d..0e535e2f 100755 --- a/crytic_compile/platform/etherlime.py +++ b/crytic_compile/platform/etherlime.py @@ -10,7 +10,7 @@ import shutil import subprocess from pathlib import Path -from typing import TYPE_CHECKING, List, Optional, Any +from typing import TYPE_CHECKING, List, Optional, Any, Dict from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion @@ -192,6 +192,18 @@ def is_supported(target: str, **kwargs: str) -> bool: ) return False + @staticmethod + def config(working_dir: str) -> Optional[Dict[str, Any]]: + """Return configuration data that should be passed to solc, such as remappings. + + Args: + working_dir (str): path to the working directory + + Returns: + Dict[str, Any]: Data such as remappings + """ + return None + def is_dependency(self, path: str) -> bool: """Check if the path is a dependency diff --git a/crytic_compile/platform/etherscan.py b/crytic_compile/platform/etherscan.py index 0a490977..5163c018 100644 --- a/crytic_compile/platform/etherscan.py +++ b/crytic_compile/platform/etherscan.py @@ -9,7 +9,7 @@ import urllib.request from json.decoder import JSONDecodeError from pathlib import Path, PurePosixPath -from typing import TYPE_CHECKING, Dict, List, Union, Tuple, Optional +from typing import TYPE_CHECKING, Dict, List, Union, Tuple, Optional, Any from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion @@ -411,6 +411,18 @@ def is_supported(target: str, **kwargs: str) -> bool: target = target[target.find(":") + 1 :] return bool(re.match(r"^\s*0x[a-zA-Z0-9]{40}\s*$", target)) + @staticmethod + def config(working_dir: str) -> Optional[Dict[str, Any]]: + """Return configuration data that should be passed to solc, such as remappings. + + Args: + working_dir (str): path to the working directory + + Returns: + Dict[str, Any]: Data such as remappings + """ + return None + def is_dependency(self, _path: str) -> bool: """Check if the path is a dependency diff --git a/crytic_compile/platform/hardhat.py b/crytic_compile/platform/hardhat.py index ca3f5f84..9b20fcbe 100755 --- a/crytic_compile/platform/hardhat.py +++ b/crytic_compile/platform/hardhat.py @@ -218,6 +218,18 @@ def is_supported(target: str, **kwargs: str) -> bool: or os.path.isfile(os.path.join(target, "hardhat.config.cjs")) ) + @staticmethod + def config(working_dir: str) -> Optional[Dict[str, Any]]: + """Return configuration data that should be passed to solc, such as remappings. + + Args: + working_dir (str): path to the working directory + + Returns: + Dict[str, Any]: Data such as remappings + """ + return None + def is_dependency(self, path: str) -> bool: """Check if the path is a dependency diff --git a/crytic_compile/platform/solc.py b/crytic_compile/platform/solc.py index ef8b93fa..47e88cf5 100644 --- a/crytic_compile/platform/solc.py +++ b/crytic_compile/platform/solc.py @@ -199,6 +199,18 @@ def is_supported(target: str, **kwargs: str) -> bool: """ return os.path.isfile(target) and target.endswith(".sol") + @staticmethod + def config(working_dir: str) -> Optional[Dict[str, Any]]: + """Return configuration data that should be passed to solc, such as remappings. + + Args: + working_dir (str): path to the working directory + + Returns: + Dict[str, Any]: Data such as remappings + """ + return None + def is_dependency(self, _path: str) -> bool: """Check if the path is a dependency (always false for direct solc) diff --git a/crytic_compile/platform/truffle.py b/crytic_compile/platform/truffle.py index 67c3b74c..852b83a4 100755 --- a/crytic_compile/platform/truffle.py +++ b/crytic_compile/platform/truffle.py @@ -11,7 +11,7 @@ import subprocess import uuid from pathlib import Path -from typing import TYPE_CHECKING, Dict, List, Optional, Tuple +from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Any from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion @@ -309,6 +309,18 @@ def is_supported(target: str, **kwargs: str) -> bool: os.path.join(target, "truffle-config.js") ) + @staticmethod + def config(working_dir: str) -> Optional[Dict[str, Any]]: + """Return configuration data that should be passed to solc, such as remappings. + + Args: + working_dir (str): path to the working directory + + Returns: + Dict[str, Any]: Data such as remappings + """ + return None + # pylint: disable=no-self-use def is_dependency(self, path: str) -> bool: """Check if the path is a dependency diff --git a/crytic_compile/platform/vyper.py b/crytic_compile/platform/vyper.py index 49133fd9..7c8e7600 100644 --- a/crytic_compile/platform/vyper.py +++ b/crytic_compile/platform/vyper.py @@ -7,7 +7,7 @@ import shutil import subprocess from pathlib import Path -from typing import TYPE_CHECKING, Dict, List, Optional +from typing import TYPE_CHECKING, Dict, List, Optional, Any from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion @@ -120,6 +120,18 @@ def is_supported(target: str, **kwargs: str) -> bool: return False return os.path.isfile(target) and target.endswith(".vy") + @staticmethod + def config(working_dir: str) -> Optional[Dict[str, Any]]: + """Return configuration data that should be passed to solc, such as remappings. + + Args: + working_dir (str): path to the working directory + + Returns: + Dict[str, Any]: Data such as remappings + """ + return None + def _guessed_tests(self) -> List[str]: """Guess the potential unit tests commands diff --git a/crytic_compile/platform/waffle.py b/crytic_compile/platform/waffle.py index 6735649a..25738c5d 100755 --- a/crytic_compile/platform/waffle.py +++ b/crytic_compile/platform/waffle.py @@ -10,7 +10,7 @@ import subprocess import tempfile from pathlib import Path -from typing import TYPE_CHECKING, Dict, List, Optional +from typing import TYPE_CHECKING, Dict, List, Optional, Any from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion @@ -260,6 +260,18 @@ def is_supported(target: str, **kwargs: str) -> bool: return False + @staticmethod + def config(working_dir: str) -> Optional[Dict[str, Any]]: + """Return configuration data that should be passed to solc, such as remappings. + + Args: + working_dir (str): path to the working directory + + Returns: + Dict[str, Any]: Data such as remappings + """ + return None + def is_dependency(self, path: str) -> bool: """Check if the path is a dependency From c65f67b7694914a34cdf155b31c2f4efd978b33e Mon Sep 17 00:00:00 2001 From: Simone Date: Wed, 9 Aug 2023 16:52:37 +0200 Subject: [PATCH 03/14] Parse foundry configuration --- crytic_compile/platform/foundry.py | 51 +++++++++++++++++++++++++++++- setup.py | 2 +- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/crytic_compile/platform/foundry.py b/crytic_compile/platform/foundry.py index f0d6c7f8..67fef228 100755 --- a/crytic_compile/platform/foundry.py +++ b/crytic_compile/platform/foundry.py @@ -3,8 +3,10 @@ """ import logging import os +import subprocess from pathlib import Path -from typing import TYPE_CHECKING, List +from typing import TYPE_CHECKING, List, Dict, Any +import toml from crytic_compile.platform.abstract_platform import AbstractPlatform from crytic_compile.platform.types import Type @@ -98,6 +100,53 @@ def is_supported(target: str, **kwargs: str) -> bool: return os.path.isfile(os.path.join(target, "foundry.toml")) + @staticmethod + def config(working_dir: str) -> Dict[str, Any]: + """Return configuration data that should be passed to solc, such as remappings. + + Args: + working_dir (str): path to the working directory + + Returns: + Dict[str, Any]: Data such as remappings + """ + result = {} + result["remappings"] = ( + subprocess.run(["forge", "remappings"], stdout=subprocess.PIPE, check=True) + .stdout.decode("utf-8") + .replace("\n", " ") + .strip() + ) + with open("foundry.toml", "r") as f: + foundry_toml = toml.loads(f.read()) + default_profile = foundry_toml["profile"]["default"] + + if "solc_version" in default_profile: + result["solc_version"] = default_profile["solc_version"] + if "offline" in default_profile: + result["offline"] = default_profile["offline"] + if "optimizer" in default_profile: + result["optimizer"] = default_profile["optimizer"] + else: + # Default to true + result["optimizer"] = True + if "optimizer_runs" in default_profile: + result["optimizer_runs"] = default_profile["optimizer_runs"] + else: + # Default to 200 + result["optimizer_runs"] = 200 + if "via_ir" in default_profile: + result["via_ir"] = default_profile["via_ir"] + if "allow_paths" in default_profile: + result["allow_paths"] = default_profile["allow_paths"] + if "evm_version" in default_profile: + result["evm_version"] = default_profile["evm_version"] + else: + # Default to london + result["evm_version"] = "london" + + return result + # pylint: disable=no-self-use def is_dependency(self, path: str) -> bool: """Check if the path is a dependency diff --git a/setup.py b/setup.py index b268b07b..06b2f3d4 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ version="0.3.2", packages=find_packages(), python_requires=">=3.8", - install_requires=["pycryptodome>=3.4.6", "cbor2", "solc-select>=v1.0.2"], + install_requires=["pycryptodome>=3.4.6", "cbor2", "solc-select>=v1.0.2", "toml>=0.10.2"], extras_require={ "test": [ "pytest", From e34b0cc57c5b8eb3af74c18b9809826d49313729 Mon Sep 17 00:00:00 2001 From: Simone Date: Wed, 9 Aug 2023 16:52:56 +0200 Subject: [PATCH 04/14] Add auto-compile option --- crytic_compile/crytic_compile.py | 44 +++++++++++++++++++++ crytic_compile/cryticparser/cryticparser.py | 8 ++++ crytic_compile/cryticparser/defaults.py | 1 + 3 files changed, 53 insertions(+) diff --git a/crytic_compile/crytic_compile.py b/crytic_compile/crytic_compile.py index e437afef..a087b001 100644 --- a/crytic_compile/crytic_compile.py +++ b/crytic_compile/crytic_compile.py @@ -14,6 +14,7 @@ from pathlib import Path from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple, Type, Union +from solc_select.solc_select import switch_global_version, current_version from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.platform import all_platforms, solc_standard_json from crytic_compile.platform.abstract_platform import AbstractPlatform @@ -116,6 +117,49 @@ def __init__(self, target: Union[str, AbstractPlatform], **kwargs: str) -> None: if isinstance(target, str): platform = self._init_platform(target, **kwargs) + # If the platform is Solc it means we are trying to compile a single + # we try to see if we are in a known compilation framework to retrieve + # information like remappings and solc version + if kwargs["auto_compile"] and isinstance(platform, Solc): + # Try to get the platform of the current working directory + platform_wd = next( + ( + p(target) + for p in get_platforms() + if p.is_supported(str(self._working_dir), **kwargs) + ), + None, + ) + # If no platform has been found or if it's a Solc we can't do anything + if platform_wd and not isinstance(platform_wd, Solc): + solc_config = platform_wd.config(str(self._working_dir)) + if solc_config: + kwargs["solc_args"] = "" + kwargs["solc_remaps"] = "" + + if "remappings" in solc_config: + kwargs["solc_remaps"] = solc_config["remappings"] + if ( + "solc_version" in solc_config + and solc_config["solc_version"] != current_version()[0] + ): + # Respect foundry offline option and don't install a missing solc version + if "offline" in solc_config and solc_config["offline"]: + switch_global_version(solc_config["solc_version"], False) + else: + switch_global_version(solc_config["solc_version"], True) + if "optimizer" in solc_config and solc_config["optimizer"]: + kwargs["solc_args"] += "--optimize" + if "optimizer_runs" in solc_config: + kwargs[ + "solc_args" + ] += f"--optimize-runs {solc_config['optimizer_runs']}" + if "via_ir" in solc_config and solc_config["via_ir"]: + kwargs["solc_args"] += "--via-ir" + if "allow_paths" in solc_config: + kwargs["solc_args"] += f"--allow-paths {solc_config['allow_paths']}" + if "evm_version" in solc_config: + kwargs["solc_args"] += f"--evm-version {solc_config['evm_version']}" else: platform = target diff --git a/crytic_compile/cryticparser/cryticparser.py b/crytic_compile/cryticparser/cryticparser.py index f8848377..a134a2e3 100755 --- a/crytic_compile/cryticparser/cryticparser.py +++ b/crytic_compile/cryticparser/cryticparser.py @@ -65,6 +65,14 @@ def init(parser: ArgumentParser) -> None: default=DEFAULTS_FLAG_IN_CONFIG["skip_clean"], ) + group_compile.add_argument( + "--auto-compile", + help="Try to get the solc options automatically when compiling a single file", + action="store_true", + dest="auto_compile", + default=DEFAULTS_FLAG_IN_CONFIG["auto_compile"], + ) + _init_solc(parser) _init_truffle(parser) _init_embark(parser) diff --git a/crytic_compile/cryticparser/defaults.py b/crytic_compile/cryticparser/defaults.py index fda8dc0a..518baf6f 100755 --- a/crytic_compile/cryticparser/defaults.py +++ b/crytic_compile/cryticparser/defaults.py @@ -47,4 +47,5 @@ "foundry_out_directory": "out", "export_dir": "crytic-export", "compile_libraries": None, + "auto_compile": False, } From 1e736711e79839d9de3fa8f1a984f3e3f458aefd Mon Sep 17 00:00:00 2001 From: Simone Date: Wed, 9 Aug 2023 17:30:42 +0200 Subject: [PATCH 05/14] Don't change the global solc version --- crytic_compile/crytic_compile.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/crytic_compile/crytic_compile.py b/crytic_compile/crytic_compile.py index a087b001..388a127c 100644 --- a/crytic_compile/crytic_compile.py +++ b/crytic_compile/crytic_compile.py @@ -14,7 +14,12 @@ from pathlib import Path from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple, Type, Union -from solc_select.solc_select import switch_global_version, current_version +from solc_select.solc_select import ( + install_artifacts, + installed_versions, + current_version, + artifact_path, +) from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.platform import all_platforms, solc_standard_json from crytic_compile.platform.abstract_platform import AbstractPlatform @@ -143,11 +148,18 @@ def __init__(self, target: Union[str, AbstractPlatform], **kwargs: str) -> None: "solc_version" in solc_config and solc_config["solc_version"] != current_version()[0] ): - # Respect foundry offline option and don't install a missing solc version - if "offline" in solc_config and solc_config["offline"]: - switch_global_version(solc_config["solc_version"], False) + solc_version = solc_config["solc_version"] + if solc_version in installed_versions(): + kwargs["solc"] = str(artifact_path(solc_version).absolute()) else: - switch_global_version(solc_config["solc_version"], True) + # Respect foundry offline option and don't install a missing solc version + if ( + "offline" not in solc_config + or "offline" in solc_config + and not solc_config["offline"] + ): + install_artifacts([solc_version]) + kwargs["solc"] = str(artifact_path(solc_version).absolute()) if "optimizer" in solc_config and solc_config["optimizer"]: kwargs["solc_args"] += "--optimize" if "optimizer_runs" in solc_config: From b91b88a5b4892c5ea0d37bf599476d9fe896d1a7 Mon Sep 17 00:00:00 2001 From: Simone Date: Thu, 10 Aug 2023 18:17:44 +0200 Subject: [PATCH 06/14] Add PlatformConfig class --- crytic_compile/crytic_compile.py | 36 +++++++++---------- crytic_compile/platform/abstract_platform.py | 25 +++++++++++-- crytic_compile/platform/archive.py | 6 ++-- crytic_compile/platform/brownie.py | 8 ++--- crytic_compile/platform/buidler.py | 8 ++--- crytic_compile/platform/dapp.py | 8 ++--- crytic_compile/platform/embark.py | 8 ++--- crytic_compile/platform/etherlime.py | 8 ++--- crytic_compile/platform/etherscan.py | 8 ++--- crytic_compile/platform/foundry.py | 38 +++++++++++--------- crytic_compile/platform/hardhat.py | 6 ++-- crytic_compile/platform/solc.py | 6 ++-- crytic_compile/platform/standard.py | 16 +++++++-- crytic_compile/platform/truffle.py | 8 ++--- crytic_compile/platform/vyper.py | 8 ++--- crytic_compile/platform/waffle.py | 8 ++--- 16 files changed, 119 insertions(+), 86 deletions(-) diff --git a/crytic_compile/crytic_compile.py b/crytic_compile/crytic_compile.py index 388a127c..551b0f03 100644 --- a/crytic_compile/crytic_compile.py +++ b/crytic_compile/crytic_compile.py @@ -137,41 +137,37 @@ def __init__(self, target: Union[str, AbstractPlatform], **kwargs: str) -> None: ) # If no platform has been found or if it's a Solc we can't do anything if platform_wd and not isinstance(platform_wd, Solc): - solc_config = platform_wd.config(str(self._working_dir)) - if solc_config: + platform_config = platform_wd.config(str(self._working_dir)) + if platform_config: kwargs["solc_args"] = "" kwargs["solc_remaps"] = "" - if "remappings" in solc_config: - kwargs["solc_remaps"] = solc_config["remappings"] + if platform_config.remappings: + kwargs["solc_remaps"] = platform_config.remappings if ( - "solc_version" in solc_config - and solc_config["solc_version"] != current_version()[0] + platform_config.solc_version + and platform_config.solc_version != current_version()[0] ): - solc_version = solc_config["solc_version"] + solc_version = platform_config.solc_version if solc_version in installed_versions(): kwargs["solc"] = str(artifact_path(solc_version).absolute()) else: # Respect foundry offline option and don't install a missing solc version - if ( - "offline" not in solc_config - or "offline" in solc_config - and not solc_config["offline"] - ): + if not platform_config.offline: install_artifacts([solc_version]) kwargs["solc"] = str(artifact_path(solc_version).absolute()) - if "optimizer" in solc_config and solc_config["optimizer"]: + if platform_config.optimizer: kwargs["solc_args"] += "--optimize" - if "optimizer_runs" in solc_config: + if platform_config.optimizer_runs: kwargs[ "solc_args" - ] += f"--optimize-runs {solc_config['optimizer_runs']}" - if "via_ir" in solc_config and solc_config["via_ir"]: + ] += f"--optimize-runs {platform_config.optimizer_runs}" + if platform_config.via_ir: kwargs["solc_args"] += "--via-ir" - if "allow_paths" in solc_config: - kwargs["solc_args"] += f"--allow-paths {solc_config['allow_paths']}" - if "evm_version" in solc_config: - kwargs["solc_args"] += f"--evm-version {solc_config['evm_version']}" + if platform_config.allow_paths: + kwargs["solc_args"] += f"--allow-paths {platform_config.allow_paths}" + if platform_config.evm_version: + kwargs["solc_args"] += f"--evm-version {platform_config.evm_version}" else: platform = target diff --git a/crytic_compile/platform/abstract_platform.py b/crytic_compile/platform/abstract_platform.py index 3555abdd..eae66b91 100644 --- a/crytic_compile/platform/abstract_platform.py +++ b/crytic_compile/platform/abstract_platform.py @@ -4,7 +4,8 @@ This gives the skeleton for any platform supported by crytic-compile """ import abc -from typing import TYPE_CHECKING, List, Dict, Any, Optional +from typing import TYPE_CHECKING, List, Dict, Optional +from dataclasses import dataclass, field from crytic_compile.platform import Type from crytic_compile.utils.unit_tests import guess_tests @@ -22,6 +23,24 @@ class IncorrectPlatformInitialization(Exception): pass +@dataclass +class PlatformConfig: + """ + This class represents a generic platform configuration + """ + offline: bool = False + remappings: Optional[str] = None + solc_version: Optional[str] = None + optimizer: bool = False + optimizer_runs: Optional[int] = None + via_ir: bool = False + allow_paths: Optional[str] = None + evm_version: Optional[str] = None + src_path: str = "src" + tests_path: str = "test" + libs_path: List[str] = field(default_factory=lambda: ["lib"]) + + class AbstractPlatform(metaclass=abc.ABCMeta): """ This is the abstract class for the platform @@ -156,14 +175,14 @@ def is_dependency(self, path: str) -> bool: @staticmethod @abc.abstractmethod - def config(working_dir: str) -> Optional[Dict[str, Any]]: + def config(working_dir: str) -> Optional[PlatformConfig]: """Return configuration data that should be passed to solc, such as version, remappings ecc. Args: working_dir (str): path to the target Returns: - Optional[Dict[str, Any]]: Data such as version, remappings ecc + Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... """ return None diff --git a/crytic_compile/platform/archive.py b/crytic_compile/platform/archive.py index f7ed0faf..93c1e447 100644 --- a/crytic_compile/platform/archive.py +++ b/crytic_compile/platform/archive.py @@ -13,7 +13,7 @@ from crytic_compile.platform import standard # Cycle dependency -from crytic_compile.platform.abstract_platform import AbstractPlatform +from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig if TYPE_CHECKING: from crytic_compile import CryticCompile @@ -119,14 +119,14 @@ def is_supported(target: str, **kwargs: str) -> bool: return Path(target).parts[-1].endswith("_export_archive.json") @staticmethod - def config(working_dir: str) -> Optional[Dict[str, Any]]: + def config(working_dir: str) -> Optional[PlatformConfig]: """Return configuration data that should be passed to solc, such as remappings. Args: working_dir (str): path to the working directory Returns: - Dict[str, Any]: Data such as remappings + Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... """ return None diff --git a/crytic_compile/platform/brownie.py b/crytic_compile/platform/brownie.py index 22db2191..5677f964 100755 --- a/crytic_compile/platform/brownie.py +++ b/crytic_compile/platform/brownie.py @@ -8,11 +8,11 @@ import shutil import subprocess from pathlib import Path -from typing import TYPE_CHECKING, Dict, List, Optional, Any +from typing import TYPE_CHECKING, Dict, List, Optional from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion -from crytic_compile.platform.abstract_platform import AbstractPlatform +from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig from crytic_compile.platform.exceptions import InvalidCompilation from crytic_compile.platform.types import Type from crytic_compile.utils.naming import Filename, convert_filename @@ -115,14 +115,14 @@ def is_supported(target: str, **kwargs: str) -> bool: ) @staticmethod - def config(working_dir: str) -> Optional[Dict[str, Any]]: + def config(working_dir: str) -> Optional[PlatformConfig]: """Return configuration data that should be passed to solc, such as remappings. Args: working_dir (str): path to the working directory Returns: - Dict[str, Any]: Data such as remappings + Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... """ return None diff --git a/crytic_compile/platform/buidler.py b/crytic_compile/platform/buidler.py index 9689d034..2186e9f4 100755 --- a/crytic_compile/platform/buidler.py +++ b/crytic_compile/platform/buidler.py @@ -7,7 +7,7 @@ import shutil import subprocess from pathlib import Path -from typing import TYPE_CHECKING, List, Tuple, Optional, Dict, Any +from typing import TYPE_CHECKING, List, Tuple, Optional from crytic_compile.compiler.compiler import CompilerVersion from crytic_compile.platform.exceptions import InvalidCompilation @@ -15,7 +15,7 @@ from crytic_compile.utils.naming import convert_filename, extract_name from crytic_compile.utils.natspec import Natspec from crytic_compile.compilation_unit import CompilationUnit -from .abstract_platform import AbstractPlatform +from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig # Handle cycle from .solc import relative_to_short @@ -194,14 +194,14 @@ def is_supported(target: str, **kwargs: str) -> bool: return is_javascript or is_typescript @staticmethod - def config(working_dir: str) -> Optional[Dict[str, Any]]: + def config(working_dir: str) -> Optional[PlatformConfig]: """Return configuration data that should be passed to solc, such as remappings. Args: working_dir (str): path to the working directory Returns: - Dict[str, Any]: Data such as remappings + Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... """ return None diff --git a/crytic_compile/platform/dapp.py b/crytic_compile/platform/dapp.py index c788bec5..f46296e8 100755 --- a/crytic_compile/platform/dapp.py +++ b/crytic_compile/platform/dapp.py @@ -12,11 +12,11 @@ from pathlib import Path # Cycle dependency -from typing import TYPE_CHECKING, List, Optional, Dict, Any +from typing import TYPE_CHECKING, List, Optional from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion -from crytic_compile.platform.abstract_platform import AbstractPlatform +from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig from crytic_compile.platform.types import Type from crytic_compile.utils.naming import convert_filename, extract_name from crytic_compile.utils.subprocess import run @@ -158,14 +158,14 @@ def is_supported(target: str, **kwargs: str) -> bool: return False @staticmethod - def config(working_dir: str) -> Optional[Dict[str, Any]]: + def config(working_dir: str) -> Optional[PlatformConfig]: """Return configuration data that should be passed to solc, such as remappings. Args: working_dir (str): path to the working directory Returns: - Dict[str, Any]: Data such as remappings + Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... """ return None diff --git a/crytic_compile/platform/embark.py b/crytic_compile/platform/embark.py index 189c51cc..9cddb275 100755 --- a/crytic_compile/platform/embark.py +++ b/crytic_compile/platform/embark.py @@ -8,11 +8,11 @@ import shutil import subprocess from pathlib import Path -from typing import TYPE_CHECKING, List, Dict, Any, Optional +from typing import TYPE_CHECKING, List, Optional from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion -from crytic_compile.platform.abstract_platform import AbstractPlatform +from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig from crytic_compile.platform.exceptions import InvalidCompilation from crytic_compile.platform.types import Type from crytic_compile.utils.naming import convert_filename, extract_filename, extract_name @@ -201,14 +201,14 @@ def is_supported(target: str, **kwargs: str) -> bool: return os.path.isfile(os.path.join(target, "embark.json")) @staticmethod - def config(working_dir: str) -> Optional[Dict[str, Any]]: + def config(working_dir: str) -> Optional[PlatformConfig]: """Return configuration data that should be passed to solc, such as remappings. Args: working_dir (str): path to the working directory Returns: - Dict[str, Any]: Data such as remappings + Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... """ return None diff --git a/crytic_compile/platform/etherlime.py b/crytic_compile/platform/etherlime.py index 0e535e2f..a5883b95 100755 --- a/crytic_compile/platform/etherlime.py +++ b/crytic_compile/platform/etherlime.py @@ -10,11 +10,11 @@ import shutil import subprocess from pathlib import Path -from typing import TYPE_CHECKING, List, Optional, Any, Dict +from typing import TYPE_CHECKING, List, Optional, Any from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion -from crytic_compile.platform.abstract_platform import AbstractPlatform +from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig from crytic_compile.platform.exceptions import InvalidCompilation from crytic_compile.platform.types import Type from crytic_compile.utils.naming import convert_filename @@ -193,14 +193,14 @@ def is_supported(target: str, **kwargs: str) -> bool: return False @staticmethod - def config(working_dir: str) -> Optional[Dict[str, Any]]: + def config(working_dir: str) -> Optional[PlatformConfig]: """Return configuration data that should be passed to solc, such as remappings. Args: working_dir (str): path to the working directory Returns: - Dict[str, Any]: Data such as remappings + Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... """ return None diff --git a/crytic_compile/platform/etherscan.py b/crytic_compile/platform/etherscan.py index 5163c018..89e66352 100644 --- a/crytic_compile/platform/etherscan.py +++ b/crytic_compile/platform/etherscan.py @@ -9,12 +9,12 @@ import urllib.request from json.decoder import JSONDecodeError from pathlib import Path, PurePosixPath -from typing import TYPE_CHECKING, Dict, List, Union, Tuple, Optional, Any +from typing import TYPE_CHECKING, Dict, List, Union, Tuple, Optional from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion from crytic_compile.platform import solc_standard_json -from crytic_compile.platform.abstract_platform import AbstractPlatform +from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig from crytic_compile.platform.exceptions import InvalidCompilation from crytic_compile.platform.types import Type from crytic_compile.utils.naming import Filename @@ -412,14 +412,14 @@ def is_supported(target: str, **kwargs: str) -> bool: return bool(re.match(r"^\s*0x[a-zA-Z0-9]{40}\s*$", target)) @staticmethod - def config(working_dir: str) -> Optional[Dict[str, Any]]: + def config(working_dir: str) -> Optional[PlatformConfig]: """Return configuration data that should be passed to solc, such as remappings. Args: working_dir (str): path to the working directory Returns: - Dict[str, Any]: Data such as remappings + Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... """ return None diff --git a/crytic_compile/platform/foundry.py b/crytic_compile/platform/foundry.py index 67fef228..2e7a7901 100755 --- a/crytic_compile/platform/foundry.py +++ b/crytic_compile/platform/foundry.py @@ -5,10 +5,10 @@ import os import subprocess from pathlib import Path -from typing import TYPE_CHECKING, List, Dict, Any +from typing import TYPE_CHECKING, List, Optional import toml -from crytic_compile.platform.abstract_platform import AbstractPlatform +from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig from crytic_compile.platform.types import Type from crytic_compile.platform.hardhat import hardhat_like_parsing from crytic_compile.utils.subprocess import run @@ -101,17 +101,17 @@ def is_supported(target: str, **kwargs: str) -> bool: return os.path.isfile(os.path.join(target, "foundry.toml")) @staticmethod - def config(working_dir: str) -> Dict[str, Any]: + def config(working_dir: str) -> Optional[PlatformConfig]: """Return configuration data that should be passed to solc, such as remappings. Args: working_dir (str): path to the working directory Returns: - Dict[str, Any]: Data such as remappings + Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... """ - result = {} - result["remappings"] = ( + result = PlatformConfig() + result.remappings = ( subprocess.run(["forge", "remappings"], stdout=subprocess.PIPE, check=True) .stdout.decode("utf-8") .replace("\n", " ") @@ -122,28 +122,34 @@ def config(working_dir: str) -> Dict[str, Any]: default_profile = foundry_toml["profile"]["default"] if "solc_version" in default_profile: - result["solc_version"] = default_profile["solc_version"] + result.solc_version = default_profile["solc_version"] if "offline" in default_profile: - result["offline"] = default_profile["offline"] + result.offline = default_profile["offline"] if "optimizer" in default_profile: - result["optimizer"] = default_profile["optimizer"] + result.optimizer = default_profile["optimizer"] else: # Default to true - result["optimizer"] = True + result.optimizer = True if "optimizer_runs" in default_profile: - result["optimizer_runs"] = default_profile["optimizer_runs"] + result.optimizer_runs = default_profile["optimizer_runs"] else: # Default to 200 - result["optimizer_runs"] = 200 + result.optimizer_runs = 200 if "via_ir" in default_profile: - result["via_ir"] = default_profile["via_ir"] + result.via_ir = default_profile["via_ir"] if "allow_paths" in default_profile: - result["allow_paths"] = default_profile["allow_paths"] + result.allow_paths = default_profile["allow_paths"] if "evm_version" in default_profile: - result["evm_version"] = default_profile["evm_version"] + result.evm_version = default_profile["evm_version"] else: # Default to london - result["evm_version"] = "london" + result.evm_version = "london" + if "src" in default_profile: + result.src_path = default_profile["src"] + if "test" in default_profile: + result.tests_path = default_profile["test"] + if "libs" in default_profile: + result.libs_path = default_profile["libs"] return result diff --git a/crytic_compile/platform/hardhat.py b/crytic_compile/platform/hardhat.py index 9b20fcbe..32e07a13 100755 --- a/crytic_compile/platform/hardhat.py +++ b/crytic_compile/platform/hardhat.py @@ -15,7 +15,7 @@ from crytic_compile.utils.naming import convert_filename, extract_name from crytic_compile.utils.natspec import Natspec from crytic_compile.utils.subprocess import run -from crytic_compile.platform.abstract_platform import AbstractPlatform +from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig # Handle cycle from crytic_compile.platform.solc import relative_to_short @@ -219,14 +219,14 @@ def is_supported(target: str, **kwargs: str) -> bool: ) @staticmethod - def config(working_dir: str) -> Optional[Dict[str, Any]]: + def config(working_dir: str) -> Optional[PlatformConfig]: """Return configuration data that should be passed to solc, such as remappings. Args: working_dir (str): path to the working directory Returns: - Dict[str, Any]: Data such as remappings + Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... """ return None diff --git a/crytic_compile/platform/solc.py b/crytic_compile/platform/solc.py index 47e88cf5..0dd3800d 100644 --- a/crytic_compile/platform/solc.py +++ b/crytic_compile/platform/solc.py @@ -12,7 +12,7 @@ from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion -from crytic_compile.platform.abstract_platform import AbstractPlatform +from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig from crytic_compile.platform.exceptions import InvalidCompilation from crytic_compile.platform.types import Type from crytic_compile.utils.naming import ( @@ -200,14 +200,14 @@ def is_supported(target: str, **kwargs: str) -> bool: return os.path.isfile(target) and target.endswith(".sol") @staticmethod - def config(working_dir: str) -> Optional[Dict[str, Any]]: + def config(working_dir: str) -> Optional[PlatformConfig]: """Return configuration data that should be passed to solc, such as remappings. Args: working_dir (str): path to the working directory Returns: - Dict[str, Any]: Data such as remappings + Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... """ return None diff --git a/crytic_compile/platform/standard.py b/crytic_compile/platform/standard.py index f2046dfa..9273bb8b 100644 --- a/crytic_compile/platform/standard.py +++ b/crytic_compile/platform/standard.py @@ -5,12 +5,12 @@ import os from collections import defaultdict from pathlib import Path -from typing import TYPE_CHECKING, Dict, List, Tuple, Type, Any +from typing import TYPE_CHECKING, Dict, List, Tuple, Type, Any, Optional from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion from crytic_compile.platform import Type as PlatformType -from crytic_compile.platform.abstract_platform import AbstractPlatform +from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig from crytic_compile.utils.naming import Filename # Cycle dependency @@ -120,6 +120,18 @@ def is_supported(target: str, **kwargs: str) -> bool: return False return Path(target).parts[-1].endswith("_export.json") + @staticmethod + def config(working_dir: str) -> Optional[PlatformConfig]: + """Return configuration data that should be passed to solc, such as remappings. + + Args: + working_dir (str): path to the working directory + + Returns: + Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... + """ + return None + def is_dependency(self, path: str) -> bool: """Check if the target is a dependency This function always return false, the deps are handled by crytic_compile_dependencies diff --git a/crytic_compile/platform/truffle.py b/crytic_compile/platform/truffle.py index 852b83a4..486ddc6f 100755 --- a/crytic_compile/platform/truffle.py +++ b/crytic_compile/platform/truffle.py @@ -11,12 +11,12 @@ import subprocess import uuid from pathlib import Path -from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Any +from typing import TYPE_CHECKING, Dict, List, Optional, Tuple from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion from crytic_compile.platform import solc -from crytic_compile.platform.abstract_platform import AbstractPlatform +from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig from crytic_compile.platform.exceptions import InvalidCompilation from crytic_compile.platform.types import Type from crytic_compile.utils.naming import convert_filename @@ -310,14 +310,14 @@ def is_supported(target: str, **kwargs: str) -> bool: ) @staticmethod - def config(working_dir: str) -> Optional[Dict[str, Any]]: + def config(working_dir: str) -> Optional[PlatformConfig]: """Return configuration data that should be passed to solc, such as remappings. Args: working_dir (str): path to the working directory Returns: - Dict[str, Any]: Data such as remappings + Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... """ return None diff --git a/crytic_compile/platform/vyper.py b/crytic_compile/platform/vyper.py index 7c8e7600..6fac311d 100644 --- a/crytic_compile/platform/vyper.py +++ b/crytic_compile/platform/vyper.py @@ -7,11 +7,11 @@ import shutil import subprocess from pathlib import Path -from typing import TYPE_CHECKING, Dict, List, Optional, Any +from typing import TYPE_CHECKING, Dict, List, Optional from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion -from crytic_compile.platform.abstract_platform import AbstractPlatform +from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig from crytic_compile.platform.exceptions import InvalidCompilation from crytic_compile.platform.types import Type from crytic_compile.utils.naming import convert_filename @@ -121,14 +121,14 @@ def is_supported(target: str, **kwargs: str) -> bool: return os.path.isfile(target) and target.endswith(".vy") @staticmethod - def config(working_dir: str) -> Optional[Dict[str, Any]]: + def config(working_dir: str) -> Optional[PlatformConfig]: """Return configuration data that should be passed to solc, such as remappings. Args: working_dir (str): path to the working directory Returns: - Dict[str, Any]: Data such as remappings + Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... """ return None diff --git a/crytic_compile/platform/waffle.py b/crytic_compile/platform/waffle.py index 25738c5d..053bc7c3 100755 --- a/crytic_compile/platform/waffle.py +++ b/crytic_compile/platform/waffle.py @@ -10,11 +10,11 @@ import subprocess import tempfile from pathlib import Path -from typing import TYPE_CHECKING, Dict, List, Optional, Any +from typing import TYPE_CHECKING, Dict, List, Optional from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion -from crytic_compile.platform.abstract_platform import AbstractPlatform +from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig from crytic_compile.platform.exceptions import InvalidCompilation from crytic_compile.platform.types import Type from crytic_compile.utils.naming import convert_filename @@ -261,14 +261,14 @@ def is_supported(target: str, **kwargs: str) -> bool: return False @staticmethod - def config(working_dir: str) -> Optional[Dict[str, Any]]: + def config(working_dir: str) -> Optional[PlatformConfig]: """Return configuration data that should be passed to solc, such as remappings. Args: working_dir (str): path to the working directory Returns: - Dict[str, Any]: Data such as remappings + Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... """ return None From 677075ced3669bb567f680238e62c810ffb00b57 Mon Sep 17 00:00:00 2001 From: Simone Date: Fri, 11 Aug 2023 10:37:09 +0200 Subject: [PATCH 07/14] Add scripts path in PlatformConfig --- crytic_compile/platform/abstract_platform.py | 2 ++ crytic_compile/platform/foundry.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/crytic_compile/platform/abstract_platform.py b/crytic_compile/platform/abstract_platform.py index eae66b91..d48df420 100644 --- a/crytic_compile/platform/abstract_platform.py +++ b/crytic_compile/platform/abstract_platform.py @@ -28,6 +28,7 @@ class PlatformConfig: """ This class represents a generic platform configuration """ + offline: bool = False remappings: Optional[str] = None solc_version: Optional[str] = None @@ -39,6 +40,7 @@ class PlatformConfig: src_path: str = "src" tests_path: str = "test" libs_path: List[str] = field(default_factory=lambda: ["lib"]) + scripts_path: str = "script" class AbstractPlatform(metaclass=abc.ABCMeta): diff --git a/crytic_compile/platform/foundry.py b/crytic_compile/platform/foundry.py index 2e7a7901..4969e8cc 100755 --- a/crytic_compile/platform/foundry.py +++ b/crytic_compile/platform/foundry.py @@ -150,6 +150,8 @@ def config(working_dir: str) -> Optional[PlatformConfig]: result.tests_path = default_profile["test"] if "libs" in default_profile: result.libs_path = default_profile["libs"] + if "script" in default_profile: + result.scripts_path = default_profile["script"] return result From 0d3e8e8354fb74473c2dd2f3e1df693912dcf6d6 Mon Sep 17 00:00:00 2001 From: Simone Date: Fri, 11 Aug 2023 10:37:28 +0200 Subject: [PATCH 08/14] Update foundry link --- crytic_compile/platform/foundry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crytic_compile/platform/foundry.py b/crytic_compile/platform/foundry.py index 4969e8cc..f5f91a08 100755 --- a/crytic_compile/platform/foundry.py +++ b/crytic_compile/platform/foundry.py @@ -26,7 +26,7 @@ class Foundry(AbstractPlatform): """ NAME = "Foundry" - PROJECT_URL = "https://github.com/gakonst/foundry" + PROJECT_URL = "https://github.com/foundry-rs/foundry" TYPE = Type.FOUNDRY # pylint: disable=too-many-locals,too-many-statements,too-many-branches From 7e186a8bc487d4464c5116c92723f6f25e81e48d Mon Sep 17 00:00:00 2001 From: Simone Date: Fri, 11 Aug 2023 10:38:45 +0200 Subject: [PATCH 09/14] Skip compiling foundry test and script --- crytic_compile/cryticparser/cryticparser.py | 8 +++++++ crytic_compile/cryticparser/defaults.py | 1 + crytic_compile/platform/foundry.py | 23 ++++++++++++++++----- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/crytic_compile/cryticparser/cryticparser.py b/crytic_compile/cryticparser/cryticparser.py index a134a2e3..88ea4da6 100755 --- a/crytic_compile/cryticparser/cryticparser.py +++ b/crytic_compile/cryticparser/cryticparser.py @@ -504,3 +504,11 @@ def _init_foundry(parser: ArgumentParser) -> None: dest="foundry_out_directory", default=DEFAULTS_FLAG_IN_CONFIG["foundry_out_directory"], ) + + group_foundry.add_argument( + "--foundry-compile-all", + help="Don't skip compiling test and script", + action="store_true", + dest="foundry_compile_all", + default=DEFAULTS_FLAG_IN_CONFIG["foundry_compile_all"], + ) diff --git a/crytic_compile/cryticparser/defaults.py b/crytic_compile/cryticparser/defaults.py index 518baf6f..8b57e64a 100755 --- a/crytic_compile/cryticparser/defaults.py +++ b/crytic_compile/cryticparser/defaults.py @@ -45,6 +45,7 @@ "hardhat_artifacts_directory": None, "foundry_ignore_compile": False, "foundry_out_directory": "out", + "foundry_compile_all": False, "export_dir": "crytic-export", "compile_libraries": None, "auto_compile": False, diff --git a/crytic_compile/platform/foundry.py b/crytic_compile/platform/foundry.py index f5f91a08..65e95583 100755 --- a/crytic_compile/platform/foundry.py +++ b/crytic_compile/platform/foundry.py @@ -51,12 +51,25 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None: ) if not ignore_compile: + compilation_command = [ + "forge", + "build", + "--build-info", + ] + + compile_all = kwargs.get("foundry_compile_all", False) + + if not compile_all: + foundry_config = self.config(crytic_compile.working_dir) + compilation_command += [ + "--skip", + f"*/{foundry_config.tests_path}/**", + f"*/{foundry_config.scripts_path}/**", + "--force", + ] + run( - [ - "forge", - "build", - "--build-info", - ], + compilation_command, cwd=self._target, ) From 3bd372970a8eafec4b0ef12266fa4ed26f368cba Mon Sep 17 00:00:00 2001 From: Simone Date: Fri, 11 Aug 2023 10:49:44 +0200 Subject: [PATCH 10/14] Lint --- crytic_compile/crytic_compile.py | 2 ++ crytic_compile/platform/abstract_platform.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/crytic_compile/crytic_compile.py b/crytic_compile/crytic_compile.py index 551b0f03..2c077197 100644 --- a/crytic_compile/crytic_compile.py +++ b/crytic_compile/crytic_compile.py @@ -90,6 +90,7 @@ class CryticCompile: Main class. """ + # pylint: disable=too-many-branches def __init__(self, target: Union[str, AbstractPlatform], **kwargs: str) -> None: """See https://github.com/crytic/crytic-compile/wiki/Configuration Target is usually a file or a project directory. It can be an AbstractPlatform @@ -120,6 +121,7 @@ def __init__(self, target: Union[str, AbstractPlatform], **kwargs: str) -> None: self._working_dir = Path.cwd() + # pylint: disable=too-many-nested-blocks if isinstance(target, str): platform = self._init_platform(target, **kwargs) # If the platform is Solc it means we are trying to compile a single diff --git a/crytic_compile/platform/abstract_platform.py b/crytic_compile/platform/abstract_platform.py index d48df420..167bf5c3 100644 --- a/crytic_compile/platform/abstract_platform.py +++ b/crytic_compile/platform/abstract_platform.py @@ -22,7 +22,7 @@ class IncorrectPlatformInitialization(Exception): # pylint: disable=unnecessary-pass pass - +# pylint: disable=too-many-instance-attributes @dataclass class PlatformConfig: """ From 0b8f205c83e751fb55edc5ba93ff8d92d88092b7 Mon Sep 17 00:00:00 2001 From: Simone Date: Fri, 11 Aug 2023 11:31:42 +0200 Subject: [PATCH 11/14] Lint --- crytic_compile/crytic_compile.py | 2 +- crytic_compile/platform/abstract_platform.py | 1 + crytic_compile/platform/foundry.py | 17 +++++++++-------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/crytic_compile/crytic_compile.py b/crytic_compile/crytic_compile.py index 2c077197..b3809284 100644 --- a/crytic_compile/crytic_compile.py +++ b/crytic_compile/crytic_compile.py @@ -127,7 +127,7 @@ def __init__(self, target: Union[str, AbstractPlatform], **kwargs: str) -> None: # If the platform is Solc it means we are trying to compile a single # we try to see if we are in a known compilation framework to retrieve # information like remappings and solc version - if kwargs["auto_compile"] and isinstance(platform, Solc): + if kwargs.get("auto_compile", False) and isinstance(platform, Solc): # Try to get the platform of the current working directory platform_wd = next( ( diff --git a/crytic_compile/platform/abstract_platform.py b/crytic_compile/platform/abstract_platform.py index 167bf5c3..8654a35e 100644 --- a/crytic_compile/platform/abstract_platform.py +++ b/crytic_compile/platform/abstract_platform.py @@ -22,6 +22,7 @@ class IncorrectPlatformInitialization(Exception): # pylint: disable=unnecessary-pass pass + # pylint: disable=too-many-instance-attributes @dataclass class PlatformConfig: diff --git a/crytic_compile/platform/foundry.py b/crytic_compile/platform/foundry.py index 65e95583..d46494d5 100755 --- a/crytic_compile/platform/foundry.py +++ b/crytic_compile/platform/foundry.py @@ -60,13 +60,14 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None: compile_all = kwargs.get("foundry_compile_all", False) if not compile_all: - foundry_config = self.config(crytic_compile.working_dir) - compilation_command += [ - "--skip", - f"*/{foundry_config.tests_path}/**", - f"*/{foundry_config.scripts_path}/**", - "--force", - ] + foundry_config = self.config(str(crytic_compile.working_dir.absolute())) + if foundry_config: + compilation_command += [ + "--skip", + f"*/{foundry_config.tests_path}/**", + f"*/{foundry_config.scripts_path}/**", + "--force", + ] run( compilation_command, @@ -130,7 +131,7 @@ def config(working_dir: str) -> Optional[PlatformConfig]: .replace("\n", " ") .strip() ) - with open("foundry.toml", "r") as f: + with open("foundry.toml", "r", encoding="utf-8") as f: foundry_toml = toml.loads(f.read()) default_profile = foundry_toml["profile"]["default"] From fb5de47337e2fb5b06fc8fe9b5ba2dd1a4cac617 Mon Sep 17 00:00:00 2001 From: Feist Josselin Date: Thu, 5 Oct 2023 11:34:35 +0200 Subject: [PATCH 12/14] Improvements - Remove the auto flag, crytic-compile will directly use the auto feature if its on .sol file + the working director is a known platform - Remove abstract from config to reduce code footprint --- crytic_compile/crytic_compile.py | 2 +- crytic_compile/cryticparser/cryticparser.py | 8 -------- crytic_compile/platform/abstract_platform.py | 1 - crytic_compile/platform/archive.py | 12 ------------ crytic_compile/platform/brownie.py | 12 ------------ crytic_compile/platform/buidler.py | 12 ------------ crytic_compile/platform/dapp.py | 12 ------------ crytic_compile/platform/embark.py | 12 ------------ crytic_compile/platform/etherlime.py | 12 ------------ crytic_compile/platform/etherscan.py | 12 ------------ crytic_compile/platform/hardhat.py | 12 ------------ crytic_compile/platform/solc.py | 12 ------------ crytic_compile/platform/standard.py | 12 ------------ crytic_compile/platform/truffle.py | 12 ------------ crytic_compile/platform/vyper.py | 12 ------------ 15 files changed, 1 insertion(+), 154 deletions(-) diff --git a/crytic_compile/crytic_compile.py b/crytic_compile/crytic_compile.py index b3809284..5c238598 100644 --- a/crytic_compile/crytic_compile.py +++ b/crytic_compile/crytic_compile.py @@ -127,7 +127,7 @@ def __init__(self, target: Union[str, AbstractPlatform], **kwargs: str) -> None: # If the platform is Solc it means we are trying to compile a single # we try to see if we are in a known compilation framework to retrieve # information like remappings and solc version - if kwargs.get("auto_compile", False) and isinstance(platform, Solc): + if isinstance(platform, Solc): # Try to get the platform of the current working directory platform_wd = next( ( diff --git a/crytic_compile/cryticparser/cryticparser.py b/crytic_compile/cryticparser/cryticparser.py index 9754ce9e..d8b3da6a 100755 --- a/crytic_compile/cryticparser/cryticparser.py +++ b/crytic_compile/cryticparser/cryticparser.py @@ -65,14 +65,6 @@ def init(parser: ArgumentParser) -> None: default=DEFAULTS_FLAG_IN_CONFIG["skip_clean"], ) - group_compile.add_argument( - "--auto-compile", - help="Try to get the solc options automatically when compiling a single file", - action="store_true", - dest="auto_compile", - default=DEFAULTS_FLAG_IN_CONFIG["auto_compile"], - ) - _init_solc(parser) _init_truffle(parser) _init_embark(parser) diff --git a/crytic_compile/platform/abstract_platform.py b/crytic_compile/platform/abstract_platform.py index 8654a35e..92413abf 100644 --- a/crytic_compile/platform/abstract_platform.py +++ b/crytic_compile/platform/abstract_platform.py @@ -177,7 +177,6 @@ def is_dependency(self, path: str) -> bool: return False @staticmethod - @abc.abstractmethod def config(working_dir: str) -> Optional[PlatformConfig]: """Return configuration data that should be passed to solc, such as version, remappings ecc. diff --git a/crytic_compile/platform/archive.py b/crytic_compile/platform/archive.py index 93c1e447..2f1b5105 100644 --- a/crytic_compile/platform/archive.py +++ b/crytic_compile/platform/archive.py @@ -118,18 +118,6 @@ def is_supported(target: str, **kwargs: str) -> bool: return False return Path(target).parts[-1].endswith("_export_archive.json") - @staticmethod - def config(working_dir: str) -> Optional[PlatformConfig]: - """Return configuration data that should be passed to solc, such as remappings. - - Args: - working_dir (str): path to the working directory - - Returns: - Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... - """ - return None - def is_dependency(self, _path: str) -> bool: """Check if the _path is a dependency. Always false diff --git a/crytic_compile/platform/brownie.py b/crytic_compile/platform/brownie.py index 5677f964..17065dcd 100755 --- a/crytic_compile/platform/brownie.py +++ b/crytic_compile/platform/brownie.py @@ -114,18 +114,6 @@ def is_supported(target: str, **kwargs: str) -> bool: or os.path.isfile(os.path.join(target, "brownie-config.yml")) ) - @staticmethod - def config(working_dir: str) -> Optional[PlatformConfig]: - """Return configuration data that should be passed to solc, such as remappings. - - Args: - working_dir (str): path to the working directory - - Returns: - Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... - """ - return None - def is_dependency(self, _path: str) -> bool: """Check if the path is a dependency (not supported for brownie) diff --git a/crytic_compile/platform/buidler.py b/crytic_compile/platform/buidler.py index 2186e9f4..14bd0573 100755 --- a/crytic_compile/platform/buidler.py +++ b/crytic_compile/platform/buidler.py @@ -193,18 +193,6 @@ def is_supported(target: str, **kwargs: str) -> bool: is_typescript = os.path.isfile(os.path.join(target, "buidler.config.ts")) return is_javascript or is_typescript - @staticmethod - def config(working_dir: str) -> Optional[PlatformConfig]: - """Return configuration data that should be passed to solc, such as remappings. - - Args: - working_dir (str): path to the working directory - - Returns: - Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... - """ - return None - def is_dependency(self, path: str) -> bool: """Check if the path is a dependency diff --git a/crytic_compile/platform/dapp.py b/crytic_compile/platform/dapp.py index f46296e8..9d367245 100755 --- a/crytic_compile/platform/dapp.py +++ b/crytic_compile/platform/dapp.py @@ -157,18 +157,6 @@ def is_supported(target: str, **kwargs: str) -> bool: return "dapp " in txt return False - @staticmethod - def config(working_dir: str) -> Optional[PlatformConfig]: - """Return configuration data that should be passed to solc, such as remappings. - - Args: - working_dir (str): path to the working directory - - Returns: - Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... - """ - return None - def is_dependency(self, path: str) -> bool: """Check if the path is a dependency (not supported for brownie) diff --git a/crytic_compile/platform/embark.py b/crytic_compile/platform/embark.py index 9cddb275..24a54b19 100755 --- a/crytic_compile/platform/embark.py +++ b/crytic_compile/platform/embark.py @@ -200,18 +200,6 @@ def is_supported(target: str, **kwargs: str) -> bool: return False return os.path.isfile(os.path.join(target, "embark.json")) - @staticmethod - def config(working_dir: str) -> Optional[PlatformConfig]: - """Return configuration data that should be passed to solc, such as remappings. - - Args: - working_dir (str): path to the working directory - - Returns: - Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... - """ - return None - def is_dependency(self, path: str) -> bool: """Check if the path is a dependency diff --git a/crytic_compile/platform/etherlime.py b/crytic_compile/platform/etherlime.py index a5883b95..2e82f035 100755 --- a/crytic_compile/platform/etherlime.py +++ b/crytic_compile/platform/etherlime.py @@ -192,18 +192,6 @@ def is_supported(target: str, **kwargs: str) -> bool: ) return False - @staticmethod - def config(working_dir: str) -> Optional[PlatformConfig]: - """Return configuration data that should be passed to solc, such as remappings. - - Args: - working_dir (str): path to the working directory - - Returns: - Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... - """ - return None - def is_dependency(self, path: str) -> bool: """Check if the path is a dependency diff --git a/crytic_compile/platform/etherscan.py b/crytic_compile/platform/etherscan.py index 6e50133c..1ce9497c 100644 --- a/crytic_compile/platform/etherscan.py +++ b/crytic_compile/platform/etherscan.py @@ -430,18 +430,6 @@ def is_supported(target: str, **kwargs: str) -> bool: target = target[target.find(":") + 1 :] return bool(re.match(r"^\s*0x[a-zA-Z0-9]{40}\s*$", target)) - @staticmethod - def config(working_dir: str) -> Optional[PlatformConfig]: - """Return configuration data that should be passed to solc, such as remappings. - - Args: - working_dir (str): path to the working directory - - Returns: - Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... - """ - return None - def is_dependency(self, _path: str) -> bool: """Check if the path is a dependency diff --git a/crytic_compile/platform/hardhat.py b/crytic_compile/platform/hardhat.py index 32e07a13..92738866 100755 --- a/crytic_compile/platform/hardhat.py +++ b/crytic_compile/platform/hardhat.py @@ -218,18 +218,6 @@ def is_supported(target: str, **kwargs: str) -> bool: or os.path.isfile(os.path.join(target, "hardhat.config.cjs")) ) - @staticmethod - def config(working_dir: str) -> Optional[PlatformConfig]: - """Return configuration data that should be passed to solc, such as remappings. - - Args: - working_dir (str): path to the working directory - - Returns: - Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... - """ - return None - def is_dependency(self, path: str) -> bool: """Check if the path is a dependency diff --git a/crytic_compile/platform/solc.py b/crytic_compile/platform/solc.py index 0dd3800d..5c9f8c3e 100644 --- a/crytic_compile/platform/solc.py +++ b/crytic_compile/platform/solc.py @@ -199,18 +199,6 @@ def is_supported(target: str, **kwargs: str) -> bool: """ return os.path.isfile(target) and target.endswith(".sol") - @staticmethod - def config(working_dir: str) -> Optional[PlatformConfig]: - """Return configuration data that should be passed to solc, such as remappings. - - Args: - working_dir (str): path to the working directory - - Returns: - Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... - """ - return None - def is_dependency(self, _path: str) -> bool: """Check if the path is a dependency (always false for direct solc) diff --git a/crytic_compile/platform/standard.py b/crytic_compile/platform/standard.py index 9273bb8b..88a8ac76 100644 --- a/crytic_compile/platform/standard.py +++ b/crytic_compile/platform/standard.py @@ -120,18 +120,6 @@ def is_supported(target: str, **kwargs: str) -> bool: return False return Path(target).parts[-1].endswith("_export.json") - @staticmethod - def config(working_dir: str) -> Optional[PlatformConfig]: - """Return configuration data that should be passed to solc, such as remappings. - - Args: - working_dir (str): path to the working directory - - Returns: - Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... - """ - return None - def is_dependency(self, path: str) -> bool: """Check if the target is a dependency This function always return false, the deps are handled by crytic_compile_dependencies diff --git a/crytic_compile/platform/truffle.py b/crytic_compile/platform/truffle.py index 486ddc6f..d2cea0cf 100755 --- a/crytic_compile/platform/truffle.py +++ b/crytic_compile/platform/truffle.py @@ -309,18 +309,6 @@ def is_supported(target: str, **kwargs: str) -> bool: os.path.join(target, "truffle-config.js") ) - @staticmethod - def config(working_dir: str) -> Optional[PlatformConfig]: - """Return configuration data that should be passed to solc, such as remappings. - - Args: - working_dir (str): path to the working directory - - Returns: - Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... - """ - return None - # pylint: disable=no-self-use def is_dependency(self, path: str) -> bool: """Check if the path is a dependency diff --git a/crytic_compile/platform/vyper.py b/crytic_compile/platform/vyper.py index 6fac311d..a99e0b85 100644 --- a/crytic_compile/platform/vyper.py +++ b/crytic_compile/platform/vyper.py @@ -120,18 +120,6 @@ def is_supported(target: str, **kwargs: str) -> bool: return False return os.path.isfile(target) and target.endswith(".vy") - @staticmethod - def config(working_dir: str) -> Optional[PlatformConfig]: - """Return configuration data that should be passed to solc, such as remappings. - - Args: - working_dir (str): path to the working directory - - Returns: - Optional[PlatformConfig]: Platform configuration data such as optimization, remappings... - """ - return None - def _guessed_tests(self) -> List[str]: """Guess the potential unit tests commands From 41577ea243027391c4550d9ede94099feff29802 Mon Sep 17 00:00:00 2001 From: Feist Josselin Date: Thu, 5 Oct 2023 11:40:36 +0200 Subject: [PATCH 13/14] Fix linter --- crytic_compile/platform/abstract_platform.py | 2 +- crytic_compile/platform/archive.py | 4 ++-- crytic_compile/platform/brownie.py | 2 +- crytic_compile/platform/buidler.py | 6 +++--- crytic_compile/platform/dapp.py | 4 ++-- crytic_compile/platform/embark.py | 4 ++-- crytic_compile/platform/etherlime.py | 2 +- crytic_compile/platform/etherscan.py | 2 +- crytic_compile/platform/hardhat.py | 10 +++++----- crytic_compile/platform/solc.py | 2 +- crytic_compile/platform/standard.py | 4 ++-- crytic_compile/platform/truffle.py | 2 +- crytic_compile/platform/vyper.py | 2 +- 13 files changed, 23 insertions(+), 23 deletions(-) diff --git a/crytic_compile/platform/abstract_platform.py b/crytic_compile/platform/abstract_platform.py index 92413abf..b369e155 100644 --- a/crytic_compile/platform/abstract_platform.py +++ b/crytic_compile/platform/abstract_platform.py @@ -177,7 +177,7 @@ def is_dependency(self, path: str) -> bool: return False @staticmethod - def config(working_dir: str) -> Optional[PlatformConfig]: + def config(working_dir: str) -> Optional[PlatformConfig]: # pylint: disable=unused-argument """Return configuration data that should be passed to solc, such as version, remappings ecc. Args: diff --git a/crytic_compile/platform/archive.py b/crytic_compile/platform/archive.py index 2f1b5105..e7fc417d 100644 --- a/crytic_compile/platform/archive.py +++ b/crytic_compile/platform/archive.py @@ -7,13 +7,13 @@ import json import os from pathlib import Path -from typing import TYPE_CHECKING, Dict, List, Tuple, Type, Any, Optional +from typing import TYPE_CHECKING, Dict, List, Tuple, Type, Any from crytic_compile.platform import Type as TypePlatform from crytic_compile.platform import standard # Cycle dependency -from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig +from crytic_compile.platform.abstract_platform import AbstractPlatform if TYPE_CHECKING: from crytic_compile import CryticCompile diff --git a/crytic_compile/platform/brownie.py b/crytic_compile/platform/brownie.py index 17065dcd..855d7269 100755 --- a/crytic_compile/platform/brownie.py +++ b/crytic_compile/platform/brownie.py @@ -12,7 +12,7 @@ from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion -from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig +from crytic_compile.platform.abstract_platform import AbstractPlatform from crytic_compile.platform.exceptions import InvalidCompilation from crytic_compile.platform.types import Type from crytic_compile.utils.naming import Filename, convert_filename diff --git a/crytic_compile/platform/buidler.py b/crytic_compile/platform/buidler.py index 14bd0573..9c596cbd 100755 --- a/crytic_compile/platform/buidler.py +++ b/crytic_compile/platform/buidler.py @@ -7,15 +7,15 @@ import shutil import subprocess from pathlib import Path -from typing import TYPE_CHECKING, List, Tuple, Optional +from typing import TYPE_CHECKING, List, Tuple +from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion +from crytic_compile.platform.abstract_platform import AbstractPlatform from crytic_compile.platform.exceptions import InvalidCompilation from crytic_compile.platform.types import Type from crytic_compile.utils.naming import convert_filename, extract_name from crytic_compile.utils.natspec import Natspec -from crytic_compile.compilation_unit import CompilationUnit -from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig # Handle cycle from .solc import relative_to_short diff --git a/crytic_compile/platform/dapp.py b/crytic_compile/platform/dapp.py index 9d367245..3cc38a7a 100755 --- a/crytic_compile/platform/dapp.py +++ b/crytic_compile/platform/dapp.py @@ -16,13 +16,13 @@ from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion -from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig +from crytic_compile.platform.abstract_platform import AbstractPlatform from crytic_compile.platform.types import Type from crytic_compile.utils.naming import convert_filename, extract_name -from crytic_compile.utils.subprocess import run # Handle cycle from crytic_compile.utils.natspec import Natspec +from crytic_compile.utils.subprocess import run if TYPE_CHECKING: from crytic_compile import CryticCompile diff --git a/crytic_compile/platform/embark.py b/crytic_compile/platform/embark.py index 24a54b19..37503413 100755 --- a/crytic_compile/platform/embark.py +++ b/crytic_compile/platform/embark.py @@ -8,11 +8,11 @@ import shutil import subprocess from pathlib import Path -from typing import TYPE_CHECKING, List, Optional +from typing import TYPE_CHECKING, List from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion -from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig +from crytic_compile.platform.abstract_platform import AbstractPlatform from crytic_compile.platform.exceptions import InvalidCompilation from crytic_compile.platform.types import Type from crytic_compile.utils.naming import convert_filename, extract_filename, extract_name diff --git a/crytic_compile/platform/etherlime.py b/crytic_compile/platform/etherlime.py index 2e82f035..e677b60d 100755 --- a/crytic_compile/platform/etherlime.py +++ b/crytic_compile/platform/etherlime.py @@ -14,7 +14,7 @@ from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion -from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig +from crytic_compile.platform.abstract_platform import AbstractPlatform from crytic_compile.platform.exceptions import InvalidCompilation from crytic_compile.platform.types import Type from crytic_compile.utils.naming import convert_filename diff --git a/crytic_compile/platform/etherscan.py b/crytic_compile/platform/etherscan.py index 1ce9497c..dfddbbea 100644 --- a/crytic_compile/platform/etherscan.py +++ b/crytic_compile/platform/etherscan.py @@ -14,7 +14,7 @@ from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion from crytic_compile.platform import solc_standard_json -from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig +from crytic_compile.platform.abstract_platform import AbstractPlatform from crytic_compile.platform.exceptions import InvalidCompilation from crytic_compile.platform.types import Type from crytic_compile.utils.naming import Filename diff --git a/crytic_compile/platform/hardhat.py b/crytic_compile/platform/hardhat.py index 92738866..35a02122 100755 --- a/crytic_compile/platform/hardhat.py +++ b/crytic_compile/platform/hardhat.py @@ -9,17 +9,17 @@ from pathlib import Path from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union +from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion +from crytic_compile.platform.abstract_platform import AbstractPlatform from crytic_compile.platform.exceptions import InvalidCompilation + +# Handle cycle +from crytic_compile.platform.solc import relative_to_short from crytic_compile.platform.types import Type from crytic_compile.utils.naming import convert_filename, extract_name from crytic_compile.utils.natspec import Natspec from crytic_compile.utils.subprocess import run -from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig - -# Handle cycle -from crytic_compile.platform.solc import relative_to_short -from crytic_compile.compilation_unit import CompilationUnit if TYPE_CHECKING: from crytic_compile import CryticCompile diff --git a/crytic_compile/platform/solc.py b/crytic_compile/platform/solc.py index 5c9f8c3e..ef8b93fa 100644 --- a/crytic_compile/platform/solc.py +++ b/crytic_compile/platform/solc.py @@ -12,7 +12,7 @@ from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion -from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig +from crytic_compile.platform.abstract_platform import AbstractPlatform from crytic_compile.platform.exceptions import InvalidCompilation from crytic_compile.platform.types import Type from crytic_compile.utils.naming import ( diff --git a/crytic_compile/platform/standard.py b/crytic_compile/platform/standard.py index 88a8ac76..f2046dfa 100644 --- a/crytic_compile/platform/standard.py +++ b/crytic_compile/platform/standard.py @@ -5,12 +5,12 @@ import os from collections import defaultdict from pathlib import Path -from typing import TYPE_CHECKING, Dict, List, Tuple, Type, Any, Optional +from typing import TYPE_CHECKING, Dict, List, Tuple, Type, Any from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion from crytic_compile.platform import Type as PlatformType -from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig +from crytic_compile.platform.abstract_platform import AbstractPlatform from crytic_compile.utils.naming import Filename # Cycle dependency diff --git a/crytic_compile/platform/truffle.py b/crytic_compile/platform/truffle.py index d2cea0cf..67c3b74c 100755 --- a/crytic_compile/platform/truffle.py +++ b/crytic_compile/platform/truffle.py @@ -16,7 +16,7 @@ from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion from crytic_compile.platform import solc -from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig +from crytic_compile.platform.abstract_platform import AbstractPlatform from crytic_compile.platform.exceptions import InvalidCompilation from crytic_compile.platform.types import Type from crytic_compile.utils.naming import convert_filename diff --git a/crytic_compile/platform/vyper.py b/crytic_compile/platform/vyper.py index a99e0b85..49133fd9 100644 --- a/crytic_compile/platform/vyper.py +++ b/crytic_compile/platform/vyper.py @@ -11,7 +11,7 @@ from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion -from crytic_compile.platform.abstract_platform import AbstractPlatform, PlatformConfig +from crytic_compile.platform.abstract_platform import AbstractPlatform from crytic_compile.platform.exceptions import InvalidCompilation from crytic_compile.platform.types import Type from crytic_compile.utils.naming import convert_filename From 7f854428e0a7dd8121f6799320d9c79764026c60 Mon Sep 17 00:00:00 2001 From: Feist Josselin Date: Thu, 5 Oct 2023 11:49:44 +0200 Subject: [PATCH 14/14] Minor --- crytic_compile/cryticparser/defaults.py | 1 - 1 file changed, 1 deletion(-) diff --git a/crytic_compile/cryticparser/defaults.py b/crytic_compile/cryticparser/defaults.py index 8b57e64a..9635f365 100755 --- a/crytic_compile/cryticparser/defaults.py +++ b/crytic_compile/cryticparser/defaults.py @@ -48,5 +48,4 @@ "foundry_compile_all": False, "export_dir": "crytic-export", "compile_libraries": None, - "auto_compile": False, }