foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.31k stars 1.75k forks source link

`forge create --verify` "already verified" #9219

Closed adraffy closed 2 weeks ago

adraffy commented 2 weeks ago

Component

Forge

Have you ensured that all of these are up to date?

What version of Foundry are you on?

forge 0.2.0 (5c69a9d 2024-10-28T00:23:24.836557329Z)

What command(s) is the bug in?

forge create

Operating System

Linux

Describe the bug

forge create CONTRACT --verify --private-key $PRIVATE_KEY --rpc-url https://rpc.ankr.com/eth_sepolia --etherscan-api-key $ETHERSCAN_KEY always prints "is already verified. Skipping verification."


With RUST_LOG=trace

2024-10-28T19:46:15.432798Z DEBUG alloy_provider::heart: notifying tx=0x...
2024-10-28T19:46:15.432810Z DEBUG alloy_provider::heart: updating latest block block_height=6965098
2024-10-28T19:46:15.578924Z TRACE hyper_util::client::legacy::pool: put; add idle connection for ("https", api-sepolia.etherscan.io)
2024-10-28T19:46:15.578968Z DEBUG hyper_util::client::legacy::pool: pooling idle connection for ("https", api-sepolia.etherscan.io)
Contract [src/Namespace.sol:Namespace] "0x..." is already verified. Skipping verification.
2024-10-28T19:46:15.579599Z TRACE mio::poll: deregistering event source from poller

With etherscan v2 endpoint --verifier-url "https://api.etherscan.io/v2/api"

Failed to deserialize content: expected value at line 1 column 1 Missing or unsupported chainid parameter (required for v2 api)


Since there's no way to configure the verifier, this only supports etherscan verification? https://github.com/foundry-rs/foundry/blob/a428ba6ad8856611339a6319290aade3347d25d9/crates/forge/bin/cmd/create.rs#L335-L365

skip_is_verified_check cannot be set by forge create: https://github.com/foundry-rs/foundry/blob/a428ba6ad8856611339a6319290aade3347d25d9/crates/verify/src/etherscan/mod.rs#L65-L75

https://github.com/foundry-rs/foundry/blob/a428ba6ad8856611339a6319290aade3347d25d9/crates/verify/src/etherscan/mod.rs#L233-L248

The foundry-rs/block-explorers:contract_abi() call: https://github.com/foundry-rs/block-explorers/blob/a4582e4b300e70ec7b6224c352278625a28eec8d/crates/block-explorers/src/contract.rs#L364-L395

grandizzy commented 2 weeks ago

@adraffy the verifier URL can be configured in foundry.toml as shown in https://book.getfoundry.sh/reference/config/etherscan#etherscan:

[rpc_endpoints]
sepolia = "https://rpc.ankr.com/eth_sepolia"

[etherscan]
sepolia = { key = "KEY_HERE", url = "https://api.etherscan.io/v2/api"}

then

forge create --rpc-url sepolia --private-key $PRIVATE_KEY src/Counter.sol:Counter --verify
Submitting verification for [src/Counter.sol:Counter] 0x128Abc30357bE673C20D08756B0C1ab304623Fe4.
Encountered an error verifying this contract:
Response: `NOTOK`
Details: `Missing or unsupported chainid parameter (required for v2 api), please see https://api.etherscan.io/v2/chainlist for the list of supported chainids

For the already verified message we should probably apply same defaults to deploy as for verify args, that is https://github.com/foundry-rs/foundry/blob/a428ba6ad8856611339a6319290aade3347d25d9/crates/script/src/verify.rs#L149 instead https://github.com/foundry-rs/foundry/blob/a428ba6ad8856611339a6319290aade3347d25d9/crates/forge/bin/cmd/create.rs#L353