diff --git a/brownie/project/compiler/__init__.py b/brownie/project/compiler/__init__.py index b19f6b349..658346275 100644 --- a/brownie/project/compiler/__init__.py +++ b/brownie/project/compiler/__init__.py @@ -58,6 +58,7 @@ def compile_and_format( interface_sources: Optional[Dict[str, str]] = None, remappings: Optional[list] = None, optimizer: Optional[Dict] = None, + viaIR: Optional[bool] = None, ) -> Dict: """Compiles contracts and returns build data. @@ -72,6 +73,7 @@ def compile_and_format( interface_sources: dictionary of interfaces as {'path': "source code"} remappings: list of solidity path remappings optimizer: dictionary of solidity optimizer settings + viaIR: enable compilation pipeline to go through the Yul intermediate representation Returns: build data dict @@ -136,6 +138,7 @@ def compile_and_format( interface_sources=interfaces, remappings=remappings, optimizer=optimizer, + viaIR=viaIR, ) output_json = compile_from_input_json(input_json, silent, allow_paths) @@ -153,6 +156,7 @@ def generate_input_json( interface_sources: Optional[Dict[str, str]] = None, remappings: Optional[list] = None, optimizer: Optional[Dict] = None, + viaIR: Optional[bool] = None, ) -> Dict: """Formats contracts to the standard solc input json. @@ -166,6 +170,7 @@ def generate_input_json( interface_sources: dictionary of interfaces as {'path': "source code"} remappings: list of solidity path remappings optimizer: dictionary of solidity optimizer settings + viaIR: enable compilation pipeline to go through the Yul intermediate representation Returns: dict """ @@ -188,6 +193,8 @@ def generate_input_json( if language == "Solidity": input_json["settings"]["optimizer"] = optimizer input_json["settings"]["remappings"] = _get_solc_remappings(remappings) + if viaIR is not None: + input_json["settings"]["viaIR"] = viaIR input_json["sources"] = _sources_dict(contract_sources, language) if interface_sources: diff --git a/brownie/project/compiler/solidity.py b/brownie/project/compiler/solidity.py index e244735bd..01ad293d4 100644 --- a/brownie/project/compiler/solidity.py +++ b/brownie/project/compiler/solidity.py @@ -480,8 +480,12 @@ def _generate_coverage_data( include_children=False, required_offset=fn_offset, filters={"nodeType": "FunctionDefinition"}, - )[0] - revert_nodes = fn_node.children( + ) + if len(fn_node) == 0: + # In Solidity >=0.8.13, with the viaIR option set, there is a dispatch + # function present in the generated bytecode + continue + revert_nodes = fn_node[0].children( filters=( {"nodeType": "FunctionCall", "expression.name": "revert"}, {"nodeType": "FunctionCall", "expression.name": "require"}, diff --git a/brownie/project/main.py b/brownie/project/main.py index fb9df5286..e11828785 100644 --- a/brownie/project/main.py +++ b/brownie/project/main.py @@ -108,6 +108,7 @@ def _compile(self, contract_sources: Dict, compiler_config: Dict, silent: bool) allow_paths=allow_paths, remappings=compiler_config["solc"].get("remappings", []), optimizer=compiler_config["solc"].get("optimizer", None), + viaIR=compiler_config["solc"].get("viaIR", None), ) finally: os.chdir(cwd) diff --git a/docs/config.rst b/docs/config.rst index 1980633ad..946461ccd 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -209,6 +209,12 @@ Compiler settings. See :ref:`compiler settings` for more infor default value: ``null`` + .. py:attribute:: viaIR + + Enable solc compilation pipeline to go through the Yul Intermediate Representation to generate IR-based EVM bytecode. See the `Solidity documentation `_ for breaking changes. + + default value: ``false`` + .. py:attribute:: optimizer Optimizer settings to be passed to the Solidity compiler. Values given here are passed into the compiler with no reformatting. See the `Solidity documentation `_ for a list of possible values.