ApeWorX / ape

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

Permit2 contract causes infinite loop fetching proxy information [APE-962] #1442

Closed fubuloubu closed 1 year ago

fubuloubu commented 1 year ago

Environment information

$ ape --version
0.6.8

$ ape plugins list
Installed Plugins:
  vyper        0.6.3
  alchemy      0.6.1
  etherscan    0.6.3
  template     0.6.0
  solidity     0.6.3
  foundry      0.6.7
  huff         0.1.2

What went wrong?

The Permit2 implementation contract (0x000000000022D473030F116dDEE9F6B43aC78BA3 on almost all networks) causes an infinite loop inside of our proxy info routine

How can it be fixed?

I'm guessing that the bytecode has a matching sequence to one of the regex comparisons we are doing, so it should be required to do some additional validation on the length of the bytecode to avoid false positives

banteg commented 1 year ago

i've identified where the issue comes from:

  1. a call to masterCopy() reverts
  2. then ape tries to get_virtual_machine_error of a not yet initialized contract.
  3. which in turn calls enrich_error, which tries to get the abi, so it falls into the inifinite loop.

the solution could be to either propagate skip_trace=True up to enrich_error or better not try getting partially-initialized abis from the error handler.

this can be done but acquiring a lock when initializing a contract and skip requesting the abi in downstream handlers if there is an active lock for the desired contract.