diffusc
diffusc copied to clipboard
[Bug-Candidate]: Error downloading from bscscan
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 :slightly_smiling_face:
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'
Hmm, I see two things here:
- According to BscScan, the contract at 0xef0031812FACA5E803B13fca55AbE9836356066A isn't verified. Unfortunately diffusc currently requires verified source code to work.
- Still, it should just fail to download the code and exit gracefully. I'm not sure why, but Slither appears to be throwing an error instead.
I will try to look into this on Monday, but for this case with the missing source code I think the best I'll be able to do is catch the error and inform the user before stopping.
In the meantime, you might want to open an issue over in crytic/Slither.
On Sat, Jul 22, 2023, 2:57 PM Rappie @.***> wrote:
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
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'
— Reply to this email directly, view it on GitHub https://github.com/crytic/diffusc/issues/16, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABRVFGOBMAZTYQXG6MIHRWLXRQWBXANCNFSM6AAAAAA2UAXEKQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>
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.
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.
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.
@webthethird : yes, setting etherscan_only_source_code should solve the issue here.