crytic / crytic-compile

Abstraction layer for smart contract build systems
GNU Affero General Public License v3.0
157 stars 84 forks source link

Conflict when multiple explorer API keys provided #568

Open vovikhangcdv opened 4 months ago

vovikhangcdv commented 4 months ago

When you use the --etherscan-apikey along with other explorer API key parameters, such as --optim-apikey, the etherscan API key will be added as the first apikey parameter, with other explorer's keys following. This will cause the etherscan key to be counted and loaded when requesting explorer API, which is not expected when used with other explorers such as Optim, and it will result in an invalid API key error.

For example:

❯ crytic-compile optim:0x5499178919c79086fd580d6c5f332a4253244d91 --etherscan-apikey $ETHERSCAN_API_KEY --optim-apikey $OPTIM_API_KEY
ERROR:CryticCompile:Invalid etherscan API Key
ERROR:CryticCompile:Invalid etherscan API Key: https://api-optimistic.etherscan.io/api?module=contract&action=getsourcecode&address=0x5499178919c79086fd580d6c5f332a4253244d91&apikey=<$ETHERSCAN_API_KEY>&apikey=<$OPTIM_API_KEY>

Expected Behavior: It should work seamlessly, and the provided priority API key should adhere to the explorer's address prefix.

elopez commented 4 months ago

Hi! thanks for the report. It looks like the optimism scanner includes the word "etherscan" on the URL, causing the check implemented here not be accurate:

https://github.com/crytic/crytic-compile/blob/603218d/crytic_compile/platform/etherscan.py#L252-L287

We should rework this to be more precise; maybe we can check the hostname from e.g. the list in SUPPORTED_NETWORK

vovikhangcdv commented 4 months ago

Hi, I created a fix pr #569