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

[Bug-Candidate]: Error downloading from bscscan #16

Open
rappie opened this issue Jul 22, 2023 · 5 comments
Open

[Bug-Candidate]: Error downloading from bscscan #16

rappie opened this issue Jul 22, 2023 · 5 comments

Comments

@rappie
Copy link
Contributor

rappie commented Jul 22, 2023

Describe the issue:

It looks like I'm getting a crash when trying to run diffusc on two contracts on BSC.

Chances are at least 50/50 that I'm doing something wrong 🙂

Code example to reproduce the issue:

diffusc 0x5dDDD9E7Aa629Be635Bf1b4311cCD680eB765883 0xa778088a07669EBFE5d3c5BAb357E526D39142C5 -V 0.8.17 -r -R https://bsc-dataseed1.binance.org/ -n bsc

Version:

❯ diffusc --version
0.1.0

Relevant log output:

* Inspecting V1 and V2 contracts:
* Using 'fork mode':
* Network specified via command line parameter: bsc
* RPC specified via command line parameter: https://bsc-dataseed1.binance.org/
* Warning: Block explorer API key not found. Either specify a key using the -K flag or set it with the ETHERSCAN_API_KEY environment variable.
  * Getting information from address 0x5dDDD9E7Aa629Be635Bf1b4311cCD680eB765883
  * Looking for contract 0x5dDDD9E7Aa629Be635Bf1b4311cCD680eB765883 in cache.
  * Did not find contract 0x5dDDD9E7Aa629Be635Bf1b4311cCD680eB765883 in cache. Downloading...
Traceback (most recent call last):
  File "/home/rappie/.pyenv/versions/diffusc/bin/diffusc", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/rappie/Desktop/repos/diffusc/diffusc/diffusc.py", line 255, in main
    contract = analysis.write_test_contract()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rappie/Desktop/repos/diffusc/diffusc/core/analysis_mode.py", line 94, in write_test_contract
    self.analyze_contracts()
  File "/home/rappie/Desktop/repos/diffusc/diffusc/core/fork_mode.py", line 191, in analyze_contracts
    self._v1 = get_contract_data_from_address(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rappie/Desktop/repos/diffusc/diffusc/utils/from_address.py", line 84, in get_contract_data_from_address
    contract_data["slither"] = slither_provider.get_slither_from_address(
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rappie/Desktop/repos/diffusc/diffusc/utils/slither_provider.py", line 107, in get_slither_from_address
    slither = Slither(f"{self._network_prefix}:{address}", **args)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rappie/.pyenv/versions/diffusc/lib/python3.11/site-packages/slither/slither.py", line 114, in __init__
    parser.parse_top_level_from_loaded_json(ast, path)
  File "/home/rappie/.pyenv/versions/diffusc/lib/python3.11/site-packages/slither/solc_parsing/slither_compilation_unit_solc.py", line 205, in parse_top_level_from_loaded_json
    if data_loaded[self.get_key()] == "root":
       ~~~~~~~~~~~^^^^^^^^^^^^^^^^
KeyError: 'name'
@webthethird
Copy link
Collaborator

webthethird commented Jul 22, 2023 via email

@rappie
Copy link
Contributor Author

rappie commented Jul 23, 2023

Thanks! I missed that the contract wasn't verified. As for the error, I'll wait for you to take a look monday, there's no rush.

@webthethird
Copy link
Collaborator

webthethird commented Jul 27, 2023

Sorry for the delay, it has been a busy week.

In order to reproduce this bug, I had to reinstall Diffusc, which reinstalled Slither from the branch that Diffusc depends on. It seems like while Slither is pinned to a particular version (from my fork), CryticCompile must have changed.

@montyly it seems that CryticCompile is not raising an InvalidCompilation("Contract has no public source code") anymore for unverified contracts, though it used to. Instead it is fetching the bytecode only during Etherscan.compile(), and then when it gets to parser.parse_top_level_from_loaded_json(ast, path) on line 114 of slither.py, compilation_unit.asts looks like {'': {}}.

Is the solution to pass in "etherscan_only_source_code": True with the kwargs when calling Slither? Or is this a bug in CryticCompile that we should open an issue for over there? It seems that both may be the case.

@rappie
Copy link
Contributor Author

rappie commented Jul 27, 2023

I'm now diffing with an older implementation contract that is verified. This solves the issue for me, so i'm unsubscribing from this issue.

@montyly
Copy link
Member

montyly commented Jul 30, 2023

@webthethird : yes, setting etherscan_only_source_code should solve the issue here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants