diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 541fbd2d..14cb0322 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,10 +63,10 @@ jobs: solc-select use 0.5.7 --always-install - name: Set up nix if: matrix.type == 'dapp' - uses: cachix/install-nix-action@v25 + uses: cachix/install-nix-action@V27 - name: Set up cachix if: matrix.type == 'dapp' - uses: cachix/cachix-action@v14 + uses: cachix/cachix-action@v15 with: name: dapp - name: Install Foundry diff --git a/crytic_compile/platform/solc.py b/crytic_compile/platform/solc.py index ef8b93fa..528dd6b8 100644 --- a/crytic_compile/platform/solc.py +++ b/crytic_compile/platform/solc.py @@ -468,7 +468,7 @@ def _run_solc( solc_disable_warnings (bool): If True, disable solc warnings solc_arguments (Optional[str]): Additional solc cli arguments solc_remaps (Optional[Union[str, List[str]]], optional): Solc remaps. Can be a string where remap are separated with space, or list of str, or a list of. Defaults to None. - env (Optional[Dict]): Environement variable when solc is run. Defaults to None. + env (Optional[Dict]): Environment variable when solc is run. Defaults to None. working_dir (Optional[Union[Path, str]]): Working directory when solc is run. Defaults to None. force_legacy_json (bool): Force to use the legacy json format. Defaults to False. @@ -607,7 +607,7 @@ def _run_solcs_path( solc_disable_warnings (bool): If True, disable solc warnings solc_arguments (str): Additional solc cli arguments solc_remaps (Optional[Union[str, List[str]]], optional): Solc remaps. Can be a string where remap are separated with space, or list of str, or a list of. Defaults to None. - env (Optional[Dict]): Environement variable when solc is run. Defaults to None. + env (Optional[Dict]): Environment variable when solc is run. Defaults to None. working_dir (Optional[Union[Path, str]], optional): Working directory when solc is run. Defaults to None. force_legacy_json (bool): Force to use the legacy json format. Defaults to False. @@ -697,7 +697,7 @@ def _run_solcs_env( solc_disable_warnings (bool): If True, disable solc warnings solc_arguments (str): Additional solc cli arguments solc_remaps (Optional[Union[str, List[str]]], optional): Solc remaps. Can be a string where remap are separated with space, or list of str, or a list of. Defaults to None. - env (Optional[Dict], optional): Environement variable when solc is run. Defaults to None. + env (Optional[Dict], optional): Environment variable when solc is run. Defaults to None. working_dir (Optional[Union[Path, str]], optional): Working directory when solc is run. Defaults to None. solcs_env (Optional[List[str]]): List of solc env variable to try. Defaults to None. force_legacy_json (bool): Force to use the legacy json format. Defaults to False. diff --git a/crytic_compile/platform/solc_standard_json.py b/crytic_compile/platform/solc_standard_json.py index 3bc4a94c..335beef0 100644 --- a/crytic_compile/platform/solc_standard_json.py +++ b/crytic_compile/platform/solc_standard_json.py @@ -4,15 +4,20 @@ import json import logging import os -from pathlib import Path import shutil import subprocess -from typing import TYPE_CHECKING, Dict, List, Optional, Union, Any +from pathlib import Path +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union from crytic_compile.compilation_unit import CompilationUnit from crytic_compile.compiler.compiler import CompilerVersion from crytic_compile.platform.exceptions import InvalidCompilation -from crytic_compile.platform.solc import Solc, get_version, is_optimized, relative_to_short +from crytic_compile.platform.solc import ( + Solc, + get_version, + is_optimized, + relative_to_short, +) from crytic_compile.platform.types import Type from crytic_compile.utils.naming import convert_filename @@ -166,7 +171,6 @@ def run_solc_standard_json( " ".join(cmd), ) try: - with subprocess.Popen( cmd, stdin=subprocess.PIPE, @@ -176,7 +180,6 @@ def run_solc_standard_json( executable=shutil.which(cmd[0]), **additional_kwargs, ) as process: - stdout_b, stderr_b = process.communicate(json.dumps(solc_input).encode("utf-8")) stdout, stderr = ( stdout_b.decode(), @@ -457,7 +460,7 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: Any) -> None: Args: crytic_compile (CryticCompile): Associated CryticCompile object **kwargs: optional arguments. Used: "solc", "solc_disable_warnings", "solc_args", "solc_working_dir", - "solc_remaps" + "solc_remaps", "solc_env" """ solc: str = kwargs.get("solc", "solc") @@ -466,13 +469,16 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: Any) -> None: solc_remaps: Optional[Union[str, List[str]]] = kwargs.get("solc_remaps", None) solc_working_dir: Optional[str] = kwargs.get("solc_working_dir", None) + solc_env: Optional[Dict] = kwargs.get("solc_env", None) compilation_unit = CompilationUnit(crytic_compile, "standard_json") compilation_unit.compiler_version = CompilerVersion( compiler="solc", - version=get_version(solc, None), - optimized=is_optimized(solc_arguments), + version=get_version(solc, solc_env), + optimized=is_optimized(solc_arguments) + or self.to_dict().get("settings", {}).get("optimizer", {}).get("enabled", False), + optimize_runs=self.to_dict().get("settings", {}).get("optimizer", {}).get("runs", None), ) add_optimization( @@ -493,6 +499,7 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: Any) -> None: self.to_dict(), compilation_unit.compiler_version, solc_disable_warnings=solc_disable_warnings, + working_dir=solc_working_dir, ) parse_standard_json_output( diff --git a/crytic_compile/platform/waffle.py b/crytic_compile/platform/waffle.py index 053bc7c3..56fa9543 100755 --- a/crytic_compile/platform/waffle.py +++ b/crytic_compile/platform/waffle.py @@ -321,7 +321,7 @@ def _load_config(config_file: str) -> Dict: def _get_version(compiler: str, cwd: str, config: Optional[Dict] = None) -> str: - """Return the solidity verison used + """Return the solidity version used Args: compiler (str): compiler used diff --git a/scripts/ci_test_truffle.sh b/scripts/ci_test_truffle.sh index dc0b117a..816fbab3 100755 --- a/scripts/ci_test_truffle.sh +++ b/scripts/ci_test_truffle.sh @@ -14,7 +14,7 @@ then echo "Truffle test failed" exit 255 fi -# TODO: for some reason truffle output is not deterministc +# TODO: for some reason truffle output is not deterministic # The assigned id changes #cd - #