From ba6c85112f4c34fc8eb081645bad278f48343ec4 Mon Sep 17 00:00:00 2001 From: tsite Date: Sun, 22 Oct 2023 05:45:05 -0500 Subject: [PATCH] fix(forge): fix `verify-contract` etherscan cloudflare bug (#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 #4865, #5251, #5741 * run cargo +nightly fmt -- --check * check if the api url already ends with ? Also apply the fix to --verifier-url urls --- crates/forge/bin/cmd/verify/etherscan/mod.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/forge/bin/cmd/verify/etherscan/mod.rs b/crates/forge/bin/cmd/verify/etherscan/mod.rs index 7b57d13dbde5..35f0de49f2cc 100644 --- a/crates/forge/bin/cmd/verify/etherscan/mod.rs +++ b/crates/forge/bin/cmd/verify/etherscan/mod.rs @@ -264,8 +264,12 @@ impl EtherscanVerificationProvider { ) -> Result { 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())