Skip to content

Commit

Permalink
fix(forge): fix verify-contract etherscan cloudflare bug (foundry-r…
Browse files Browse the repository at this point in the history
…s#6079)

* fix `forge verify-contract` etherscan cloudflare bug

Etherscan verification for non-mainnet chains requires a question
mark at the end of the verifier url in order to prevent a forward slash
from being added to the url which trips a cloudflare rule on requests
from ec2 boxes.

Verification on both Goerli and Sepolia both fails without this
character present.

Hardhat-verify does not add the extra forward slash to the verifier url
and has no issues verifying contracts on etherscan.

Fixes foundry-rs#4865, foundry-rs#5251, foundry-rs#5741

* run cargo +nightly fmt -- --check

* check if the api url already ends with ?

Also apply the fix to --verifier-url urls
  • Loading branch information
tsite authored Oct 22, 2023
1 parent 0409342 commit ba6c851
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions crates/forge/bin/cmd/verify/etherscan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,12 @@ impl EtherscanVerificationProvider {
) -> Result<Client> {
let etherscan_config = config.get_etherscan_config_with_chain(Some(chain))?;

let api_url =
verifier_url.or_else(|| etherscan_config.as_ref().map(|c| c.api_url.as_str()));
let etherscan_api_url = verifier_url
.or_else(|| etherscan_config.as_ref().map(|c| c.api_url.as_str()))
.map(str::to_owned)
.map(|url| if url.ends_with('?') { url } else { url + "?" });

let api_url = etherscan_api_url.as_deref();
let base_url = etherscan_config
.as_ref()
.and_then(|c| c.browser_url.as_deref())
Expand Down

0 comments on commit ba6c851

Please sign in to comment.