foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.04k stars 1.64k forks source link

bug: `forge clone` returns wrong evm version #8356

Open stiefn opened 1 month ago

stiefn commented 1 month ago

Component

Forge

Have you ensured that all of these are up to date?

What version of Foundry are you on?

forge 0.2.0 (0dceb53 2024-07-04T00:18:38.827591668Z)

What command(s) is the bug in?

forge clone

Operating System

Linux

Describe the bug

``forge clone returns the evm version "constantinople" for the USDC contract on mainnet:

forge clone 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48

The compiled bytecode does not match the on-chain bytecode. With the correct evm version "byzantium", the bytecode is identical.

The generated foundry.toml from the command above is:

[profile.default]
src = "src"
out = "out"
libs = ["lib"]
auto_detect_remappings = false
chain_id = 1
auto_detect_solc = false
solc_version = "0.4.24"
evm_version = "constantinople"
optimizer = false
optimizer_runs = 200
libraries = []
mattsse commented 1 month ago

hmm, yeah this is slightly problematic. etherscan does not return the evm version but instead returns Default so we try to detect the evm version based on the solc version.

Constantinople was introduced in 0.4.21, which explains why we detect this.

this is a bit ambiguous, so not sure how to improve this...

klkvr commented 1 month ago

this is a bit ambiguous, so not sure how to improve this...

should we add a mapping version -> default evm version to block-explorers? It should be possible to parse from solc --help output, so would require a simple script

  --evm-version version
                       Select desired EVM version. Either homestead, 
                       tangerineWhistle, spuriousDragon, byzantium, 
                       constantinople, petersburg, istanbul (default) or 
                       berlin.

edit: actually, seems like most of updates are mentioned in changelog: https://raw.githubusercontent.com/ethereum/solidity/develop/Changelog.md (search for "default evm")

mattsse commented 1 month ago

I guess if it's ambiguous, we could also try compile and match the bytecode.

but this would be a lot of effort, not sure it's worth it

zerosnacks commented 1 month ago

Possibly related: https://github.com/foundry-rs/foundry/issues/8446

ZhangZhuoSJTU commented 3 hours ago

Potentially related: https://github.com/foundry-rs/compilers/pull/189