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

Exceeded max recursion depth when generating build data for 0x exchange contracts #392

Closed
jonathanmalo opened this issue Apr 7, 2020 · 2 comments · Fixed by #393
Closed
Labels
bug Something isn't working

Comments

@jonathanmalo
Copy link

jonathanmalo commented Apr 7, 2020

Environment information

  • brownie Version: 1.6.9
  • ganache-cli Version: 6.9.1
  • solc Version: 0.5.17
  • Python Version: 3.7.6
  • OS: Fedora release 31 (Thirty One)

What was wrong?

Tried to compile 0x exchange contract as found on https://github.com/0xProject/0x-monorepo/tree/development/contracts using a bash script refactor.sh:

#!/bin/bash

mkdir zx && cd zx
brownie init
cd contracts
ZX=0x-monorepo/contracts
git clone git@github.com:0xProject/0x-monorepo.git
mkdir exchange && cp -r $ZX/exchange/contracts/src/* exchange
cp -r $ZX/asset-proxy   exchange/contracts-asset-proxy
cp -r $ZX/erc20         exchange/contracts-erc20
cp -r $ZX/exchange-libs exchange/contracts-exchange-libs
cp -r $ZX/staking       exchange/contracts-staking
cp -r $ZX/utils         exchange/contracts-utils
rm -rf 0x-monorepo
cd exchange

# erase files not in dependency manifest
cp ../../../MANIFEST .
(find ./ -type f -printf "%P\n"; cat MANIFEST MANIFEST; echo MANIFEST) |
  sort | uniq -u | xargs -r rm

# refactor solidity imports
egrep -lRZ '@0x' . | xargs -0 -l sed -i -e "s+@0x+$PWD+"

cd ../../ && brownie compile

and this MANIFEST file in the same directory as refactor.sh:

MANIFEST
Exchange.sol
MixinAssetProxyDispatcher.sol
MixinExchangeCore.sol
MixinMatchOrders.sol
MixinProtocolFees.sol
MixinSignatureValidator.sol
MixinTransactions.sol
MixinTransferSimulator.sol
MixinWrapperFunctions.sol
interfaces/IAssetProxy.sol
interfaces/IAssetProxyDispatcher.sol
interfaces/IEIP1271Data.sol
interfaces/IEIP1271Wallet.sol
interfaces/IExchange.sol
interfaces/IExchangeCore.sol
interfaces/IMatchOrders.sol
interfaces/IProtocolFees.sol
interfaces/ISignatureValidator.sol
interfaces/ITransactions.sol
interfaces/ITransferSimulator.sol
interfaces/IWallet.sol
interfaces/IWrapperFunctions.sol
libs/LibExchangeRichErrorDecoder.sol
contracts-erc20/contracts/src/interfaces/IERC20Token.sol
contracts-erc20/contracts/src/interfaces/IEtherToken.sol
contracts-exchange-libs/contracts/src/LibEIP712ExchangeDomain.sol
contracts-exchange-libs/contracts/src/LibExchangeRichErrors.sol
contracts-exchange-libs/contracts/src/LibFillResults.sol
contracts-exchange-libs/contracts/src/LibMath.sol
contracts-exchange-libs/contracts/src/LibMathRichErrors.sol
contracts-exchange-libs/contracts/src/LibOrder.sol
contracts-exchange-libs/contracts/src/LibZeroExTransaction.sol
contracts-staking/contracts/src/interfaces/IStaking.sol
contracts-staking/contracts/src/interfaces/IStructs.sol
contracts-staking/contracts/src/interfaces/IZrxVault.sol
contracts-utils/contracts/src/LibBytes.sol
contracts-utils/contracts/src/LibBytesRichErrors.sol
contracts-utils/contracts/src/LibEIP1271.sol
contracts-utils/contracts/src/LibEIP712.sol
contracts-utils/contracts/src/LibOwnableRichErrors.sol
contracts-utils/contracts/src/LibReentrancyGuardRichErrors.sol
contracts-utils/contracts/src/LibRichErrors.sol
contracts-utils/contracts/src/LibSafeMath.sol
contracts-utils/contracts/src/LibSafeMathRichErrors.sol
contracts-utils/contracts/src/Ownable.sol
contracts-utils/contracts/src/ReentrancyGuard.sol
contracts-utils/contracts/src/Refundable.sol
contracts-utils/contracts/src/interfaces/IOwnable.sol

Using this command to reproduce the error:

./refactor.sh

Python stack trace:

Brownie v1.6.9 - Python development framework for Ethereum

Compiling contracts...
  Solc version: 0.5.17+commit.d19bba13.Linux.gpp
  Optimizer: Enabled  Runs: 200
  EVM Version: Istanbul
Generating build data...
  File "brownie/_cli/__main__.py", line 57, in main
    importlib.import_module(f"brownie._cli.{cmd}").main()
  File "brownie/_cli/compile.py", line 30, in main
    project.load(project_path)
  File "brownie/project/main.py", line 513, in load
    return Project(name, project_path)
  File "brownie/project/main.py", line 132, in __init__
    self.load()
  File "brownie/project/main.py", line 161, in load
    self._compile(changed, self._compiler_config, False)
  File "brownie/project/main.py", line 78, in _compile
    interface_sources=self._sources.get_interface_sources(),
  File "brownie/project/compiler/__init__.py", line 120, in compile_and_format
    build_json.update(generate_build_json(input_json, output_json, compiler_data, silent))
  File "brownie/project/compiler/__init__.py", line 227, in generate_build_json
    source_nodes, statement_nodes, branch_nodes = solidity._get_nodes(output_json)
  File "brownie/project/compiler/solidity.py", line 519, 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 42, in set_dependencies
    _add_dependencies(contract)
  File "solcast/dependencies.py", line 52, in _add_dependencies
    contract.dependencies |= _add_dependencies(node)
  File "solcast/dependencies.py", line 52, in _add_dependencies
    contract.dependencies |= _add_dependencies(node)
  File "solcast/dependencies.py", line 52, in _add_dependencies
    contract.dependencies |= _add_dependencies(node)
  File line, line 983, in times]
  File "solcast/dependencies.py", line 51, in _add_dependencies
    for node in contract.dependencies.copy():
RecursionError: maximum recursion depth exceeded while calling a Python object

This may be jumping the gun considering #368 has yet to be addressed. Thought I'd share this since there were no import errors from the compiler. Is it possible to replace recursion here?

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

Thanks for such a detailed report! I'll have a look at this right away.

@iamdefinitelyahuman
Copy link
Member

Found the issue! In contracts-exchange-libs/contracts/src/LibOrder.sol:

library LibOrder {

    using LibOrder for Order;

This caused py-solc-ast to break while trying to determine the deps-of-deps of LibOrder. I hadn't anticipated a contract depending on itself.

I'll push a new patch version of py-solc-ast right away. With the patch I'm able to locally compile the repo built from your refactor.sh script. Also with the soon-to-merge work in #390 you can set the reampping in the config file and avoid the last egrep statement.

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