-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix Etherscan Verification Failing to Retry with Full Solc Input #7577
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
base: main
Are you sure you want to change the base?
Fix Etherscan Verification Failing to Retry with Full Solc Input #7577
Conversation
|
|
@michalbrabec, @alcuadrado, any updates regarding this PR? |
|
Hey @SyedAsadKazmi, sorry for the delay. We'll release some etherscan related fixes next, and will take a look at it after. Thanks for sending the PR! |
|
Noted, @alcuadrado. Thanks! |
|
Hi @SyedAsadKazmi, could you share the steps to reproduce that specific error?
The order of these checks in the I’ll need the sample contracts you used to trigger this scenario. I tested with the Counter contract you shared and was able to verify it successfully, so it could be related to your compiler settings or the way you’re verifying (for example, via the programmatic API). Could you share the exact contract and detailed steps to reproduce the issue? |
|
Hello @schaable, It's reproducible unless we use the exact same solidity: {
profiles: {
default: {
version: "0.8.24",
settings: {
optimizer: {
enabled: true,
runs: 1_000,
},
}
},
production: {
version: "0.8.24",
settings: {
optimizer: {
enabled: true,
runs: 1_000,
},
}
},
},
},When you run So, generally speaking, the problem is more related to |
Summary
This PR fixes a critical bug in Etherscan contract verification where detailed failure messages prevented the automatic retry with full solc input, causing verification to fail even though it would succeed with the full compiler input.
Problem
When verifying contracts on Etherscan, users were experiencing failures with the error:
However, the same verification would succeed on Blockscout, which properly retried with the full solc input after the minimal input failed.
Root Cause
There were two bugs in the Etherscan verification status polling logic:
Bug 1 - Exact String Matching: The
isFailure()method used exact string matching (===) instead of prefix matching (startsWith()), so it couldn't recognize failure messages that included additional details.Bug 2 - Incorrect Logic Order: The polling logic checked
isOk()before checkingisFailure(), causing it to throw an error before recognizing legitimate failures. When Etherscan returns a failure, the status code is0, makingisOk()returnfalseand immediately throwing an error.This prevented the automatic retry mechanism from kicking in, even though the verification logic was designed to retry with full solc input on failure.
Solution
Change 1: Use Prefix Matching for Failure Detection
Changed the
isFailure()method to usestartsWith()to properly detect failure messages with additional details:Change 2: Reorder Logic to Check Success/Failure First
Reordered the polling logic to check for recognized success/failure states before throwing errors:
Impact
Before
After
Testing
Tested with a Counter contract deployed to Sepolia:
Files Changed
v-next/hardhat-verify/src/internal/etherscan.tsisFailure()method to use prefix matchingpollVerificationStatus()logic to check success/failure before throwing errorsBreaking Changes
None. This is a bug fix that makes Etherscan verification work as originally intended.
Related Issues
Fixes the issue where Etherscan verification fails with:
"Compiled contract deployment bytecode does NOT match the transaction deployment bytecode"This aligns Etherscan verification behavior with Blockscout, ensuring both providers properly utilize the two-step verification process (minimal input first, then full input on failure).