From 37dcd2a98e9f708bc7a30eb6a6211ed0b8515b8b Mon Sep 17 00:00:00 2001 From: garythung Date: Wed, 1 Nov 2023 21:12:18 +0000 Subject: [PATCH 1/3] add solc env field for solc standard json --- crytic_compile/platform/solc_standard_json.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crytic_compile/platform/solc_standard_json.py b/crytic_compile/platform/solc_standard_json.py index beadf442..cf2a2515 100644 --- a/crytic_compile/platform/solc_standard_json.py +++ b/crytic_compile/platform/solc_standard_json.py @@ -437,7 +437,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") @@ -446,12 +446,13 @@ 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), + version=get_version(solc, solc_env), optimized=is_optimized(solc_arguments), ) From 5d35878691fbce27158ac28157b9a66a89ef0784 Mon Sep 17 00:00:00 2001 From: garythung Date: Wed, 1 Nov 2023 22:04:46 +0000 Subject: [PATCH 2/3] add solc working dir --- crytic_compile/platform/solc_standard_json.py | 1 + 1 file changed, 1 insertion(+) diff --git a/crytic_compile/platform/solc_standard_json.py b/crytic_compile/platform/solc_standard_json.py index cf2a2515..187e629f 100644 --- a/crytic_compile/platform/solc_standard_json.py +++ b/crytic_compile/platform/solc_standard_json.py @@ -474,6 +474,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( From c526de8df95e98f9337aa3177b5058707868df92 Mon Sep 17 00:00:00 2001 From: garythung Date: Tue, 19 Dec 2023 00:32:24 +0000 Subject: [PATCH 3/3] add optimizer settings to solc standard json --- crytic_compile/platform/solc_standard_json.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/crytic_compile/platform/solc_standard_json.py b/crytic_compile/platform/solc_standard_json.py index 187e629f..dfe5e4ca 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 @@ -160,7 +165,6 @@ def run_solc_standard_json( " ".join(cmd), ) try: - with subprocess.Popen( cmd, stdin=subprocess.PIPE, @@ -170,7 +174,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(), @@ -453,7 +456,9 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: Any) -> None: compilation_unit.compiler_version = CompilerVersion( compiler="solc", version=get_version(solc, solc_env), - optimized=is_optimized(solc_arguments), + 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(