Skip to content

Commit 4294572

Browse files
committed
platform: etherscan: add support for viaIR
1 parent cc7c021 commit 4294572

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

crytic_compile/platform/etherscan.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
372372
working_dir: Optional[str] = None
373373
remappings: Optional[List[str]] = None
374374

375+
dict_source_code: Optional[Dict] = None
375376
try:
376377
# etherscan might return an object with two curly braces, {{ content }}
377378
dict_source_code = json.loads(source_code[1:-1])
@@ -390,6 +391,11 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
390391
_handle_single_file(source_code, addr, prefix, contract_name, export_dir)
391392
]
392393

394+
# viaIR is not exposed on the top level JSON offered by etherscan, so we need to inspect the settings
395+
via_ir_enabled: Optional[bool] = None
396+
if isinstance(dict_source_code, dict):
397+
via_ir_enabled = dict_source_code.get("settings", {}).get("viaIR", None)
398+
393399
compilation_unit = CompilationUnit(crytic_compile, contract_name)
394400

395401
compilation_unit.compiler_version = CompilerVersion(
@@ -413,6 +419,7 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
413419
working_dir=working_dir,
414420
remappings=remappings,
415421
evm_version=evm_version,
422+
via_ir=via_ir_enabled,
416423
)
417424

418425
def clean(self, **_kwargs: str) -> None:

crytic_compile/platform/solc_standard_json.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def standalone_compile(
3131
working_dir: Optional[str] = None,
3232
remappings: Optional[List[str]] = None,
3333
evm_version: Optional[str] = None,
34+
via_ir: Optional[bool] = None,
3435
) -> None:
3536
"""
3637
Boilerplate function to run the the standardjson. compilation_unit.compiler_version must be set before calling this function
@@ -48,6 +49,7 @@ def standalone_compile(
4849
working_dir (Optional[str]): working directory
4950
remappings (Optional[List[str]]): list of solc remaps to use
5051
evm_version (Optional[str]): EVM version to target. None for default
52+
via_ir (Optional[bool]): whether to enable the viaIR compilation flag. None for unset
5153
5254
Returns:
5355
@@ -70,6 +72,9 @@ def standalone_compile(
7072
if evm_version is not None:
7173
add_evm_version(standard_json_dict, evm_version)
7274

75+
if via_ir is not None:
76+
add_via_ir(standard_json_dict, via_ir)
77+
7378
add_optimization(
7479
standard_json_dict,
7580
compilation_unit.compiler_version.optimized,
@@ -278,6 +283,20 @@ def add_evm_version(json_dict: Dict, version: str) -> None:
278283
json_dict["settings"]["evmVersion"] = version
279284

280285

286+
def add_via_ir(json_dict: Dict, enabled: bool) -> None:
287+
"""
288+
Enable or disable the "viaIR" compilation flag.
289+
290+
Args:
291+
json_dict (Dict): solc standard json input
292+
enabled (bool): whether viaIR is enabled
293+
294+
Returns:
295+
296+
"""
297+
json_dict["settings"]["viaIR"] = enabled
298+
299+
281300
def parse_standard_json_output(
282301
targets_json: Dict, compilation_unit: CompilationUnit, solc_working_dir: Optional[str] = None
283302
) -> None:

0 commit comments

Comments
 (0)