ApeWorX / ape

The smart contract development tool for Pythonistas, Data Scientists, and Security Professionals
https://apeworx.io
Apache License 2.0
868 stars 133 forks source link

AttributeError while trying to compile Vyper contracts [APE-880] #1400

Closed bout3fiddy closed 1 year ago

bout3fiddy commented 1 year ago

Environment information

$ ape --version
0.6.8

$ ape plugins list
Installed Plugins:
  alchemy      0.6.1
  etherscan    0.6.3
  vyper        0.6.3
  arbitrum     0.6.0
  hardhat      0.6.4
  ledger       0.6.0
  optimism     0.6.0
$ cat ape-config.yaml
name: curve-tricrypto-ng
contracts_folder: contracts/main

plugins:
  - name: vyper
  - name: alchemy
  - name: hardhat
  - name: ledger
  - name: etherscan
  - name: arbitrum
  - name: optimism

default_ecosystem: ethereum

ethereum:
  default_network: mainnet-fork
  mainnet_fork:
    default_provider: hardhat
    transaction_acceptance_timeout: 99999999
  mainnet:
    transaction_acceptance_timeout: 99999999

arbitrum:
  default_network: mainnet-fork
  mainnet_fork:
    default_provider: hardhat
    transaction_acceptance_timeout: 99999999
  mainnet:
    transaction_acceptance_timeout: 99999999

optimism:
  default_network: mainnet-fork
  mainnet_fork:
    default_provider: hardhat
    transaction_acceptance_timeout: 99999999
  mainnet:
    transaction_acceptance_timeout: 99999999

hardhat:
  port: auto
  fork:
    ethereum:
      mainnet:
        upstream_provider: alchemy
    arbitrum:
      mainnet:
        upstream_provider: alchemy
    optimism:
      mainnet:
        upstream_provider: alchemy

geth:
  arbitrum:
    mainnet:
      uri: https://arb-mainnet.g.alchemy.com/v2/{KEY}

test:
  mnemonic: test test test test test test test test test test test junk
  number_of_accounts: 5

What went wrong?

running:

ape run scripts/deploy.py deploy-ethereum --network ethereum:mainnet-fork

for the following contract:

https://github.com/curvefi/tricrypto-ng/blob/11cbaaa1c05b73763ea5c7cfe67b76fd4d247f1c/contracts/main/CurveCryptoMathOptimized3.vy

gives the following error:

Traceback (most recent call last):
  File "~/.../ape/managers/project/manager.py", line 467, in _get_attr
    contract = self._get_contract(attr_name)
  File "~/.../ape/managers/project/manager.py", line 730, in _get_contract
    if name in self.contracts:
  File "~/.../ape/managers/project/manager.py", line 390, in contracts
    return self.load_contracts()
  File "~/.../ape/managers/project/manager.py", line 631, in load_contracts
    manifest = self.local_project.create_manifest(
  File "~/.../ape/managers/project/types.py", line 187, in create_manifest
    compiled_contract_types = self._compile(project_sources)
  File "~/.../ape/managers/project/types.py", line 222, in _compile
    return self.compiler_manager.compile(project_sources.sources_needing_compilation)
  File "~/.../ape/managers/compilers.py", line 128, in compile
    compiled_contracts = self.registered_compilers[extension].compile(
  File "~/.../ape_vyper/compiler.py", line 323, in compile
    pc_map_list[-1][1]["dev"] = val
IndexError: list index out of range

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "~/.../tricrypto-ng/apeenv/bin/ape", line 8, in <module>
    sys.exit(cli())
  File "~/.../click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "~/.../click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "~/.../ape/_cli.py", line 36, in invoke
    return super().invoke(ctx)
  File "~/.../click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "~/.../ape_run/_cli.py", line 31, in invoke
    return super().invoke(ctx)
  File "~/.../click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "~/.../click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "~/.../ape/cli/commands.py", line 18, in invoke
    super().invoke(ctx)
  File "~/.../click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "~/.../click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "~/.../curvefi/tricrypto-ng/scripts/deploy.py", line 79, in deploy_ethereum
    factory = deploy_utils.deploy_amm_factory(fee_receiver, account, weth)
  File "~/.../curvefi/tricrypto-ng/scripts/deployment_utils.py", line 323, in deploy_amm_factory
    math_contract = account.deploy(project.CurveCryptoMathOptimized3)
  File "~/.../ape/managers/project/manager.py", line 418, in __getattr__
    result = self._get_attr(attr_name)
  File "~/.../ape/managers/project/manager.py", line 486, in _get_attr
    raise AttributeError(str(err)) from err
AttributeError: list index out of range

How can it be fixed?

change: https://github.com/ApeWorX/ape/blob/c013bb82d58934b648093ac050e93d0fcee20c66/src/ape/managers/project/manager.py#L418

to:

try:
    result = self._get_attr(attr_name)
except:
    result = self._get_attr(attr_name)

and it magically works

antazoey commented 1 year ago

Weird thing to try, but can you try deleting your .build folder?

antazoey commented 1 year ago

Oh okay, I believe this got fixed in ape-vyper and we need to release, I will ping when ready.

fubuloubu commented 1 year ago

Weird thing to try, but can you try deleting your .build folder?

he did this privately and it did work

antazoey commented 1 year ago

OK - I have not been able to reproduce but I tried so many things! I am deeply sorry! The one thing I am pretty certain of is that the .build folder was in a weird state from previous configuration / plugin versions, maybe even ethpm-types version. IDK! So my solution is to raise an error directing to try removing the .build folder. Note, I really did try many version combinations, even installed vyper directly, and old versions of the contract itself... never got anything or the custom error to hit.... So if you have more detail there, I can try to make sure this actually does fix it. Otherwise, I think at least a better error when the revert will work (based on looking at the stacktrace here)

The one thing that stands out is that there is contract type name collision in that project - maybe somehow it was referencing the other one? shrug emoji

antazoey commented 1 year ago

Finally was able to repro -- happens when using latest unreleased Vyper (follow #1398 which is same issue)