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

Brownie crashes when compiling a library defined in a separate file using solc >= 0.7.2 #828

Closed
cameel opened this issue Oct 28, 2020 · 1 comment · Fixed by iamdefinitelyahuman/py-solc-ast#14
Labels
bug Something isn't working

Comments

@cameel
Copy link

cameel commented Oct 28, 2020

Environment information

  • brownie Version: 1.11.10
  • ganache-cli Version: v6.9.1 (ganache-core: 2.10.2)
  • solc Version: 0.7.4
  • Python Version: 3.8.6
  • OS: linux

What was wrong?

A trivial project that just includes an empty contract and an empty library in separate files crashes brownie (KeyError: 'L').

This happens only when using solc >= 0.7.2.

To reproduce, run this code in the shell in an empty directory (assuming that Brownie is already installed):

brownie init

cat << EOF > contracts/C.sol
pragma solidity >=0.7.2;

import './L.sol';

contract C {}
EOF

cat << EOF > contracts/L.sol
pragma solidity >=0.7.2;

library L {}
EOF

brownie compile

Output:

Brownie v1.11.10 - Python development framework for Ethereum

Compiling contracts...
  Solc version: 0.7.4
  Optimizer: Enabled  Runs: 200
  EVM Version: Istanbul
Generating build data...
  File "brownie/_cli/__main__.py", line 64, in main
    importlib.import_module(f"brownie._cli.{cmd}").main()
  File "brownie/_cli/compile.py", line 50, in main
    proj = project.load()
  File "brownie/project/main.py", line 702, in load
    return Project(name, project_path)
  File "brownie/project/main.py", line 164, in __init__
    self.load()
  File "brownie/project/main.py", line 217, in load
    self._compile(changed, self._compiler_config, False)
  File "brownie/project/main.py", line 90, in _compile
    build_json = compiler.compile_and_format(
  File "brownie/project/compiler/__init__.py", line 146, in compile_and_format
    build_json.update(generate_build_json(input_json, output_json, compiler_data, silent))
  File "brownie/project/compiler/__init__.py", line 287, in generate_build_json
    source_nodes, statement_nodes, branch_nodes = solidity._get_nodes(output_json)
  File "brownie/project/compiler/solidity.py", line 545, in _get_nodes
    source_nodes = solcast.from_standard_output(output_json)
  File "solcast/main.py", line 33, in from_standard_output
    source_nodes = set_dependencies(source_nodes)
  File "solcast/dependencies.py", line 12, in set_dependencies
    symbol_map = get_symbol_map(source_nodes)
  File "solcast/dependencies.py", line 74, in get_symbol_map
    symbol_map.update((v[0], node[k]) for k, v in node.exportedSymbols.items())
  File "solcast/dependencies.py", line 74, in <genexpr>
    symbol_map.update((v[0], node[k]) for k, v in node.exportedSymbols.items())
  File "solcast/nodes.py", line 207, in __getitem__
    raise KeyError(key)
KeyError: 'L'

How can it be fixed?

I'm not sure but solc 0.7.2 introduced some AST changes that were not properly handled e.g. in Truffle (generatedSources, see trufflesuite/truffle#3419, ethereum/solidity#9980) and this might be a similar situation.

@iamdefinitelyahuman iamdefinitelyahuman added the bug Something isn't working label Oct 29, 2020
@iamdefinitelyahuman
Copy link
Member

Indeed, this is a result of changes to the AST in v0.7.2. Thanks for the related issues, they will make it easier to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants