Skip to content

fix(forge): allow verify-bytecode to run without a block explorer#15142

Open
PrazwalR wants to merge 4 commits into
foundry-rs:masterfrom
PrazwalR:fix/verify-bytecode-no-explorer
Open

fix(forge): allow verify-bytecode to run without a block explorer#15142
PrazwalR wants to merge 4 commits into
foundry-rs:masterfrom
PrazwalR:fix/verify-bytecode-no-explorer

Conversation

@PrazwalR

Copy link
Copy Markdown

Motivation

forge verify-bytecode fails unconditionally when no block explorer is configured — three separate failure points: client construction dies on unknown chains, creation-data fetch errors with InvalidApiKey, source-code fetch errors with "Contract source code not verified". Private chains, custom L2s, and local anvil nodes are entirely excluded.

This supersedes #14583 (closed as stale — @figtracer asked for a regression test that was never added; approach is the same, credit to @ParthSinghPS).

Closes #13479.

Changes

crates/verify/src/bytecode.rs

  • Etherscan client construction now Option<Client> — unknown chains get None, no hard error
  • Creation data fetch, source code fetch both wrapped to None when explorer unavailable
  • EVM version falls back to local foundry.toml config when no explorer metadata
  • Constructor args fall back to Bytes::new() when no source code available
  • if creation_data.is_none() branch unified: covers both predeploy (genesis) and no-explorer cases — does runtime-only verification at --block/latest, emitting a warning instead of erroring

crates/verify/src/utils.rs

  • print_result takes Option<&Metadata> — mismatch hints only printed when explorer metadata present

crates/forge/tests/cli/verify_bytecode.rs

Testing

cargo test -p forge --test cli -- verify_bytecode::can_verify_bytecode_without_explorer

Copilot AI review requested due to automatic review settings June 11, 2026 16:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates verify-bytecode to proceed when a block explorer client or explorer data is unavailable, falling back to local project configuration and runtime-bytecode-only verification to address #13479.

Changes:

  • Make explorer integration optional (client creation, creation data, source code/metadata) and continue verification with local data when missing.
  • Add fallback logic to verify runtime bytecode when creation data can’t be fetched.
  • Add a CLI integration test ensuring verification works on anvil without any explorer.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
crates/verify/src/utils.rs Makes mismatch reporting conditional on available explorer metadata.
crates/verify/src/bytecode.rs Makes explorer client/data optional; adds runtime-only verification fallback and EVM version selection fallback.
crates/forge/tests/cli/verify_bytecode.rs Adds an integration test for verification without a block explorer.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/verify/src/bytecode.rs Outdated
Comment thread crates/verify/src/bytecode.rs
Comment thread crates/verify/src/bytecode.rs Outdated
Comment thread crates/verify/src/utils.rs Outdated
Comment thread crates/verify/src/bytecode.rs
Comment thread crates/verify/src/bytecode.rs
PrazwalR and others added 3 commits June 11, 2026 22:01
verify-bytecode unconditionally required the target contract to be
verified on a block explorer: it bailed when the explorer client could
not be created (unsupported chain), when creation data could not be
fetched (missing API key), or when the source was not verified.

Degrade gracefully instead, so bytecode can be verified against a local
build with only an RPC endpoint:
- an unavailable explorer client or failed source/creation-data fetch
  now warns instead of failing;
- without explorer metadata, the EVM version falls back to the local
  project configuration and constructor args must be user-provided;
- without creation data, the creation code check is skipped and the
  runtime bytecode is verified by deploying the local creation code at
  the target block (generalizing the existing predeploy path);
- compiler-settings mismatch hints are only printed when explorer
  metadata is available.

Supersedes the stale foundry-rs#14583 and adds the regression test requested in
its review: deploys a contract on a local Anvil node and verifies it
without any explorer.

Closes foundry-rs#13479

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@PrazwalR PrazwalR force-pushed the fix/verify-bytecode-no-explorer branch from 2eea384 to d42a448 Compare June 11, 2026 16:31

@figtracer figtracer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another nit

Comment thread crates/verify/src/bytecode.rs
@github-actions

Copy link
Copy Markdown
Contributor

This pull request is stale because it has been open for 14 days with no activity. It will be closed in 7 days if there is no further activity.

@github-actions github-actions Bot added the stale label Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

forge verify-bytecode command can not verify a contract without external services

3 participants