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 verify-bytecode should not require Etherscan API key #8617

Closed
2 tasks done
Thegaram opened this issue Aug 6, 2024 · 4 comments
Closed
2 tasks done

forge verify-bytecode should not require Etherscan API key #8617

Thegaram opened this issue Aug 6, 2024 · 4 comments
Labels
T-bug Type: bug T-needs-triage Type: this issue needs to be labelled

Comments

@Thegaram
Copy link

Thegaram commented Aug 6, 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 (f2518c9 2024-08-06T00:19:05.428689000Z)

What command(s) is the bug in?

forge verify-bytecode

Operating System

macOS (Apple Silicon)

Describe the bug

This is a bug report, but it's possible that it's a misunderstanding.

The purpose of forge verify-bytecode is to check whether the contract source code in a local repo matches the bytecode deployed on chain at a specific address. To achieve this, forge could simply compile the contract (using the local compiler, optimizer, etc. configurations), then simulate deployment, then compare the result with the on-chain bytecode.

However, when I run this command I keep getting Etherscan API key is required for verification. Why is Etherscan required for verifying the contract bytecode? Since compiler parameters could be read from foundry.toml, and constructor arguments can be provided by the user, Etherscan should be optional.

Original feature request: #6893
Original implementation: #7319

cc @mds1 @yash-atreya

@Thegaram Thegaram added T-bug Type: bug T-needs-triage Type: this issue needs to be labelled labels Aug 6, 2024
@mds1
Copy link
Collaborator

mds1 commented Aug 6, 2024

I believe the Etherscan API key is required to also verify the init code, which is harder to fetch than runtime code, therefore it's fetched from Etherscan. The reason you have to also verify the actual initcode used is because malicious initcode can e.g. set storage slots that shouldn't be set, then still return the same runtime code. So only verifying runtime code is not a sufficient safety guarantee.

#8510 will add a feature to skip initcode verification, and when using that I'd assume you don't need the etherscan API key, but cc @zerosnacks @klkvr to confirm

@klkvr
Copy link
Member

klkvr commented Aug 7, 2024

right, we need etherscan API to be able to fetch contract creation transaction. Knowing creation tx allows us to simulate local creation code execution at the needed block to later compare its result with on-chain runtime code

@zerosnacks
Copy link
Member

zerosnacks commented Aug 7, 2024

Marking as not planned given the conversation above, the Etherscan API is a hard requirement for fetching the contract creation transaction / initcode.

Please note that in #8510 we are adding support for additional block explorers, some of who do not require an API key.

@zerosnacks zerosnacks closed this as not planned Won't fix, can't repro, duplicate, stale Aug 7, 2024
@Thegaram
Copy link
Author

Thegaram commented Aug 7, 2024

The reason you have to also verify the actual initcode used is because malicious initcode can e.g. set storage slots that shouldn't be set, then still return the same runtime code.

That makes sense, thank you! I'd like to use this command to verify a proxy's implementation contract, so storage is not relevant. But I agree it's best to default to full verification.

#8510 will add a feature to skip initcode verification

Looking forward to it!

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
None yet
Development

No branches or pull requests

4 participants