Skip to content

Commit

Permalink
platform: etherscan: add support for viaIR
Browse files Browse the repository at this point in the history
  • Loading branch information
elopez committed Nov 13, 2023
1 parent cc7c021 commit b45f119
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions crytic_compile/platform/etherscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,11 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
_handle_single_file(source_code, addr, prefix, contract_name, export_dir)
]

# viaIR is not exposed on the top level JSON offered by etherscan, so we need to inspect the settings
via_ir_enabled: Optional[bool] = None
if isinstance(dict_source_code, dict):
via_ir_enabled = dict_source_code.get("settings", {}).get("viaIR", False)

compilation_unit = CompilationUnit(crytic_compile, contract_name)

compilation_unit.compiler_version = CompilerVersion(
Expand All @@ -413,6 +418,7 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
working_dir=working_dir,
remappings=remappings,
evm_version=evm_version,
via_ir=via_ir_enabled,
)

def clean(self, **_kwargs: str) -> None:
Expand Down
19 changes: 19 additions & 0 deletions crytic_compile/platform/solc_standard_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def standalone_compile(
working_dir: Optional[str] = None,
remappings: Optional[List[str]] = None,
evm_version: Optional[str] = None,
via_ir: Optional[bool] = None,
) -> None:
"""
Boilerplate function to run the the standardjson. compilation_unit.compiler_version must be set before calling this function
Expand All @@ -48,6 +49,7 @@ def standalone_compile(
working_dir (Optional[str]): working directory
remappings (Optional[List[str]]): list of solc remaps to use
evm_version (Optional[str]): EVM version to target. None for default
via_ir (Optional[bool]): whether to enable the viaIR compilation flag. None for unset
Returns:
Expand All @@ -70,6 +72,9 @@ def standalone_compile(
if evm_version is not None:
add_evm_version(standard_json_dict, evm_version)

if via_ir is not None:
add_via_ir(standard_json_dict, via_ir)

add_optimization(
standard_json_dict,
compilation_unit.compiler_version.optimized,
Expand Down Expand Up @@ -278,6 +283,20 @@ def add_evm_version(json_dict: Dict, version: str) -> None:
json_dict["settings"]["evmVersion"] = version


def add_via_ir(json_dict: Dict, enabled: bool) -> None:
"""
Enable or disable the "viaIR" compilation flag.
Args:
json_dict (Dict): solc standard json input
enabled (bool): whether viaIR is enabled
Returns:
"""
json_dict["settings"]["viaIR"] = enabled


def parse_standard_json_output(
targets_json: Dict, compilation_unit: CompilationUnit, solc_working_dir: Optional[str] = None
) -> None:
Expand Down

0 comments on commit b45f119

Please sign in to comment.