Repository: foundry-rs/foundry (language: rust)

Issue:
bug(`forge`): `forge script` with `--evm-version` and `--verify` verifies with incorrect metadata.json (wrong EVM version)
### Component

Forge

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

- [x] Foundry
- [x] Foundryup

### What version of Foundry are you on?

forge Version: 1.0.0-nightly Commit SHA: 2fe902962cd76846f3fb02c24576789ee82b35d5 Build Timestamp: 2025-02-27T00:21:46.486606262Z (1740615706) Build Profile: maxperf

### What version of Foundryup are you on?

_No response_

### What command(s) is the bug in?

forge script

### Operating System

Linux

### Describe the bug

If you run `forge script ...` with the `--evm-version` flag and `--verify` (with `--verifier sourcify` in my case), the EVM version submitted to the verifier does not match the EVM version the contracts were compiled with, resulting in a failed verification.

For example, with `forge script <script path> --evm-version london --broadcast --optimize --optimizer-runs --verify --verifier sourcify --verification-url http://localhost:5555`:

The verifier server receives (test with `nc -l -p 5555`):

```
...
\"settings\": {\n    \"remappings\": [\n      \"forge-std/=lib/forge-std/src/\"\n    ],\n    \"optimizer\": {\n      \"enabled\": true,\n      \"runs\": 200\n    },\n    \"metadata\": {\n      \"bytecodeHash\": \"ipfs\"\n    },\n    \"compilationTarget\": {\n      \"src/AsteroidMiningOperation.sol\": \"AsteroidMiningOperation\"\n    },\n    \"evmVersion\": \"cancun\",\n    \"libraries\": {}\n  }
...
```

The evmVersion is set to `cancun` instead of `london`, resulting in a failed verification.


Discussion / hints:
@sealer3 that's most likely due to the contract pragma (it is maybe strict?) which cannot be normalized to the evm version you're passing  (like if it is strict 0.8.10 and you pass shanghai it won't work since shanghai is since 0.8.20 so will be normalized to london which is 0.8.7, see https://t.me/foundry_support/59989)
Please reopen with more details if not the case, thank you
@grandizzy The contract pragma is `pragma solidity ^0.8.28;` and verification is successful with the same parameters but using `forge verify-contract`.

I don't have the authority to reopen the issue, by the way.
got it, please provide details to reproduce, thank you
[evm_verify_repr.zip](https://github.com/user-attachments/files/19013603/evm_verify_repr.zip)

1. Extract the provided reproduction zip file.
2. Run `anvil` to get an RPC on `http://localhost:8545`.
3. Run `nc -l -p 5555` to listen on port 5555 for requests.
4. Inspect and then run the provided `./deploy_verify.sh` script to deploy some contracts. Note that it has `--evm-version london` set.
5. The first verification will send a request to your `nc` program. Read the output and notice `\"evmVersion\": \"cancun\"` is present.
6. Compare to `forge verify-contract 0x5FbDB2315678afecb367f032d93F642f64180aa3 src/AsteroidMiningOperation.sol:AsteroidMiningOperation -r http://localhost:8545 --optimizer-runs 200 --verifier-url http://localhost:5555/ --verifier sourcify --evm-version london`, which submits `"evmVersion": "london"`
thank you, was able to reproduce with the sample you sent, will try to provide a quick fix

Fix patch:
diff --git a/crates/script/src/verify.rs b/crates/script/src/verify.rs
index c2f995543481..c6a6bd14dca3 100644
--- a/crates/script/src/verify.rs
+++ b/crates/script/src/verify.rs
@@ -9,7 +9,7 @@ use forge_script_sequence::{AdditionalContract, ScriptSequence};
 use forge_verify::{provider::VerificationProviderType, RetryArgs, VerifierArgs, VerifyArgs};
 use foundry_cli::opts::{EtherscanOpts, ProjectPathOpts};
 use foundry_common::ContractsByArtifact;
-use foundry_compilers::{info::ContractInfo, Project};
+use foundry_compilers::{artifacts::EvmVersion, info::ContractInfo, Project};
 use foundry_config::{Chain, Config};
 use semver::Version;
 
@@ -108,6 +108,7 @@ impl VerifyBundle {
         create2_offset: usize,
         data: &[u8],
         libraries: &[String],
+        evm_version: EvmVersion,
     ) -> Option<VerifyArgs> {
         for (artifact, contract) in self.known_contracts.iter() {
             let Some(bytecode) = contract.bytecode() else { continue };
@@ -157,7 +158,7 @@ impl VerifyBundle {
                     root: None,
                     verifier: self.verifier.clone(),
                     via_ir: self.via_ir,
-                    evm_version: None,
+                    evm_version: Some(evm_version),
                     show_standard_json_input: false,
                     guess_constructor_args: false,
                     compilation_profile: Some(artifact.profile.to_string()),
@@ -202,7 +203,13 @@ async fn verify_contracts(
 
             // Verify contract created directly from the transaction
             if let (Some(address), Some(data)) = (receipt.contract_address, tx.tx().input()) {
-                match verify.get_verify_args(address, offset, data, &sequence.libraries) {
+                match verify.get_verify_args(
+                    address,
+                    offset,
+                    data,
+                    &sequence.libraries,
+                    config.evm_version,
+                ) {
                     Some(verify) => future_verifications.push(verify.run()),
                     None => unverifiable_contracts.push(address),
                 };
@@ -210,7 +217,13 @@ async fn verify_contracts(
 
             // Verify potential contracts created during the transaction execution
             for AdditionalContract { address, init_code, .. } in &tx.additional_contracts {
-                match verify.get_verify_args(*address, 0, init_code.as_ref(), &sequence.libraries) {
+                match verify.get_verify_args(
+                    *address,
+                    0,
+                    init_code.as_ref(),
+                    &sequence.libraries,
+                    config.evm_version,
+                ) {
                     Some(verify) => future_verifications.push(verify.run()),
                     None => unverifiable_contracts.push(*address),
                 };
diff --git a/crates/verify/src/verify.rs b/crates/verify/src/verify.rs
index 1e95f251d1d7..71bfc60cc167 100644
--- a/crates/verify/src/verify.rs
+++ b/crates/verify/src/verify.rs
@@ -221,6 +221,9 @@ impl VerifyArgs {
 
         let verifier_url = self.verifier.verifier_url.clone();
         sh_println!("Start verifying contract `{}` deployed on {chain}", self.address)?;
+        if let Some(version) = &self.evm_version {
+            sh_println!("EVM version: {version}")?;
+        }
         if let Some(version) = &self.compiler_version {
             sh_println!("Compiler version: {version}")?;
         }


Test patch: