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

forge create --verify "already verified" #9219

Closed
2 tasks done
adraffy opened this issue Oct 28, 2024 · 1 comment · Fixed by #9222
Closed
2 tasks done

forge create --verify "already verified" #9219

adraffy opened this issue Oct 28, 2024 · 1 comment · Fixed by #9222
Labels
T-bug Type: bug T-needs-triage Type: this issue needs to be labelled

Comments

@adraffy
Copy link

adraffy commented Oct 28, 2024

Component

Forge

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

  • Foundry
  • Foundryup

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?

println!("Starting contract verification...");
let num_of_optimizations = if self.opts.compiler.optimize.unwrap_or_default() {
self.opts.compiler.optimizer_runs
} else {
None
};
let verify = forge_verify::VerifyArgs {
address,
contract: Some(self.contract),
compiler_version: None,
constructor_args,
constructor_args_path: None,
num_of_optimizations,
etherscan: EtherscanOpts { key: self.eth.etherscan.key(), chain: Some(chain.into()) },
rpc: Default::default(),
flatten: false,
force: false,
skip_is_verified_check: false,
watch: true,
retry: self.retry,
libraries: self.opts.libraries.clone(),
root: None,
verifier: self.verifier,
via_ir: self.opts.via_ir,
evm_version: self.opts.compiler.evm_version,
show_standard_json_input: self.show_standard_json_input,
guess_constructor_args: false,
};
println!("Waiting for {} to detect contract deployment...", verify.verifier.verifier);
verify.run().await

skip_is_verified_check cannot be set by forge create:

if !args.skip_is_verified_check &&
self.is_contract_verified(&etherscan, &verify_args).await?
{
println!(
"\nContract [{}] {:?} is already verified. Skipping verification.",
verify_args.contract_name,
verify_args.address.to_checksum(None)
);
return Ok(())
}

async fn is_contract_verified(
&self,
etherscan: &Client,
verify_contract: &VerifyContract,
) -> Result<bool> {
let check = etherscan.contract_abi(verify_contract.address).await;
if let Err(err) = check {
match err {
EtherscanError::ContractCodeNotVerified(_) => return Ok(false),
error => return Err(error.into()),
}
}
Ok(true)
}

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

@adraffy adraffy added T-bug Type: bug T-needs-triage Type: this issue needs to be labelled labels Oct 28, 2024
@github-project-automation github-project-automation bot moved this to Todo in Foundry Oct 28, 2024
@grandizzy
Copy link
Collaborator

grandizzy commented Oct 29, 2024

@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

skip_is_verified_check: true,

instead
skip_is_verified_check: false,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug T-needs-triage Type: this issue needs to be labelled
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants