Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add via ir support 1477 #1572

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions brownie/project/compiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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.
Expand All @@ -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
"""
Expand All @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions brownie/project/compiler/solidity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
1 change: 1 addition & 0 deletions brownie/project/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ Compiler settings. See :ref:`compiler settings<compile_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 <https://docs.soliditylang.org/en/latest/ir-breaking-changes.html>`_ 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 <https://solidity.readthedocs.io/en/latest/using-the-compiler.html#input-description>`_ for a list of possible values.
Expand Down