diff --git a/Cargo.lock b/Cargo.lock index bc598c5f6e041..81da6b2be3294 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2497,6 +2497,7 @@ dependencies = [ "pretty_assertions", "regex", "reqwest", + "revm-primitives", "semver 1.0.18", "serde", "serde_json", @@ -5312,7 +5313,6 @@ dependencies = [ "once_cell", "revm-primitives", "ripemd", - "secp256k1", "sha2 0.10.7", "sha3", "substrate-bn", @@ -5808,24 +5808,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "secp256k1" -version = "0.27.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25996b82292a7a57ed3508f052cfff8640d38d32018784acd714758b43da9c8f" -dependencies = [ - "secp256k1-sys", -] - -[[package]] -name = "secp256k1-sys" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70a129b9e9efbfb223753b9163c4ab3b13cff7fd9c7f010fbac25ab4099fa07e" -dependencies = [ - "cc", -] - [[package]] name = "security-framework" version = "2.9.2" diff --git a/Cargo.toml b/Cargo.toml index ed52a22b2859b..494fa3f545793 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -125,6 +125,10 @@ foundry-test-utils = { path = "crates/test-utils" } foundry-utils = { path = "crates/utils" } ui = { path = "crates/ui" } +## revm +revm = { version = "3", default-features = false } +revm-primitives = { version = "1", default-features = false } + ethers = { git = "https://github.com/gakonst/ethers-rs", default-features = false } ethers-addressbook = { git = "https://github.com/gakonst/ethers-rs", default-features = false } ethers-core = { git = "https://github.com/gakonst/ethers-rs", default-features = false } @@ -156,3 +160,4 @@ tikv-jemallocator = "0.5.4" [patch.crates-io] revm = { git = "https://github.com/bluealloy/revm/", rev = "6b55b9c0ab264c000e087c2f54f2d8dc24b869aa" } +revm-primitives = { git = "https://github.com/bluealloy/revm/", rev = "6b55b9c0ab264c000e087c2f54f2d8dc24b869aa" } diff --git a/crates/anvil/core/Cargo.toml b/crates/anvil/core/Cargo.toml index 2bf66e8d9756b..9c371cb851353 100644 --- a/crates/anvil/core/Cargo.toml +++ b/crates/anvil/core/Cargo.toml @@ -12,7 +12,7 @@ repository.workspace = true [dependencies] # foundry internal foundry-evm = { path = "../../evm" } -revm = { version = "3", default-features = false, features = ["std", "serde", "memory_limit"] } +revm = { workspace = true, default-features = false, features = ["std", "serde", "memory_limit"] } ethers-core.workspace = true serde = { version = "1", features = ["derive"], optional = true } diff --git a/crates/chisel/Cargo.toml b/crates/chisel/Cargo.toml index bd910cc7786c0..9633386b58a68 100644 --- a/crates/chisel/Cargo.toml +++ b/crates/chisel/Cargo.toml @@ -43,7 +43,7 @@ serde = "1" serde_json = { version = "1", features = ["raw_value"] } semver = "1" bytes = "1" -revm = "3" +revm.workspace = true eyre = "0.6" dirs = "5" time = { version = "0.3", features = ["formatting"] } diff --git a/crates/chisel/src/executor.rs b/crates/chisel/src/executor.rs index f1c3a5c33caf2..3aa973eb89cf8 100644 --- a/crates/chisel/src/executor.rs +++ b/crates/chisel/src/executor.rs @@ -297,7 +297,7 @@ impl SessionSource { ) }) .gas_limit(self.config.evm_opts.gas_limit()) - .spec(foundry_evm::utils::evm_spec(self.config.foundry_config.evm_version)) + .spec(self.config.foundry_config.evm_spec_id()) .build(env, backend); // Create a [ChiselRunner] with a default balance of [U256::MAX] and diff --git a/crates/config/Cargo.toml b/crates/config/Cargo.toml index d24450f0ab3e2..391bb926caf32 100644 --- a/crates/config/Cargo.toml +++ b/crates/config/Cargo.toml @@ -15,6 +15,7 @@ repository.workspace = true ethers-core.workspace = true ethers-solc = { workspace = true, features = ["async", "svm-solc"] } ethers-etherscan.workspace = true +revm-primitives.workspace = true # formats Inflector = "0.11" diff --git a/crates/config/src/lib.rs b/crates/config/src/lib.rs index a3cac6b3e18bf..622ad699b37f6 100644 --- a/crates/config/src/lib.rs +++ b/crates/config/src/lib.rs @@ -76,6 +76,7 @@ pub mod fix; // reexport so cli types can implement `figment::Provider` to easily merge compiler arguments pub use figment; +use revm_primitives::SpecId; use tracing::warn; /// config providers @@ -685,6 +686,12 @@ impl Config { Ok(None) } + /// Returns the [SpecId] derived from the configured [EvmVersion] + #[inline] + pub fn evm_spec_id(&self) -> SpecId { + evm_spec_id(&self.evm_version) + } + /// Returns whether the compiler version should be auto-detected /// /// Returns `false` if `solc_version` is explicitly set, otherwise returns the value of diff --git a/crates/config/src/utils.rs b/crates/config/src/utils.rs index d71419481bf25..5bb383bdc8a37 100644 --- a/crates/config/src/utils.rs +++ b/crates/config/src/utils.rs @@ -2,8 +2,12 @@ use crate::Config; use ethers_core::types::{serde_helpers::Numeric, U256}; -use ethers_solc::remappings::{Remapping, RemappingError}; +use ethers_solc::{ + remappings::{Remapping, RemappingError}, + EvmVersion, +}; use figment::value::Value; +use revm_primitives::SpecId; use serde::{de::Error, Deserialize, Deserializer}; use std::{ path::{Path, PathBuf}, @@ -255,6 +259,24 @@ where Ok(num) } +/// Returns the [SpecId] derived from [EvmVersion] +#[inline] +pub fn evm_spec_id(evm_version: &EvmVersion) -> SpecId { + match evm_version { + EvmVersion::Homestead => SpecId::HOMESTEAD, + EvmVersion::TangerineWhistle => SpecId::TANGERINE, + EvmVersion::SpuriousDragon => SpecId::SPURIOUS_DRAGON, + EvmVersion::Byzantium => SpecId::BYZANTIUM, + EvmVersion::Constantinople => SpecId::CONSTANTINOPLE, + EvmVersion::Petersburg => SpecId::PETERSBURG, + EvmVersion::Istanbul => SpecId::ISTANBUL, + EvmVersion::Berlin => SpecId::BERLIN, + EvmVersion::London => SpecId::LONDON, + EvmVersion::Paris => SpecId::MERGE, + EvmVersion::Shanghai => SpecId::SHANGHAI, + } +} + #[cfg(test)] mod tests { use crate::get_available_profiles; diff --git a/crates/evm/Cargo.toml b/crates/evm/Cargo.toml index 4ebb920539d46..55d0e0c04469e 100644 --- a/crates/evm/Cargo.toml +++ b/crates/evm/Cargo.toml @@ -40,7 +40,7 @@ once_cell = "1" # EVM bytes = "1" hashbrown = { version = "0.13", features = ["serde"] } -revm = { version = "3", default-features = false, features = [ +revm = { workspace = true, default-features = false, features = [ "std", "serde", "memory_limit", diff --git a/crates/evm/src/trace/executor.rs b/crates/evm/src/trace/executor.rs index 7a57f68c42fe0..6cd9263bb855d 100644 --- a/crates/evm/src/trace/executor.rs +++ b/crates/evm/src/trace/executor.rs @@ -1,9 +1,6 @@ -use crate::{ - executor::{fork::CreateFork, opts::EvmOpts, Backend, Executor, ExecutorBuilder}, - utils::evm_spec, -}; +use crate::executor::{fork::CreateFork, opts::EvmOpts, Backend, Executor, ExecutorBuilder}; use ethers::solc::EvmVersion; -use foundry_config::Config; +use foundry_config::{utils::evm_spec_id, Config}; use revm::primitives::Env; use std::ops::{Deref, DerefMut}; @@ -25,7 +22,7 @@ impl TracingExecutor { // tracing will be enabled only for the targeted transaction executor: ExecutorBuilder::new() .inspectors(|stack| stack.trace(true).debug(debug)) - .spec(evm_spec(version.unwrap_or_default())) + .spec(evm_spec_id(&version.unwrap_or_default())) .build(env, db), } } diff --git a/crates/evm/src/utils.rs b/crates/evm/src/utils.rs index 2d22947ffa92a..3f15523d7822d 100644 --- a/crates/evm/src/utils.rs +++ b/crates/evm/src/utils.rs @@ -1,6 +1,5 @@ use ethers::{ abi::{Abi, FixedBytes, Function}, - solc::EvmVersion, types::{Block, Chain, H256, U256}, }; use eyre::ContextCompat; @@ -112,24 +111,6 @@ pub fn halt_to_instruction_result(halt: Halt) -> InstructionResult { } } -/// Converts an `EvmVersion` into a `SpecId`. -#[inline] -pub fn evm_spec(evm: EvmVersion) -> SpecId { - match evm { - EvmVersion::Homestead => SpecId::HOMESTEAD, - EvmVersion::TangerineWhistle => SpecId::TANGERINE, - EvmVersion::SpuriousDragon => SpecId::SPURIOUS_DRAGON, - EvmVersion::Byzantium => SpecId::BYZANTIUM, - EvmVersion::Constantinople => SpecId::CONSTANTINOPLE, - EvmVersion::Petersburg => SpecId::PETERSBURG, - EvmVersion::Istanbul => SpecId::ISTANBUL, - EvmVersion::Berlin => SpecId::BERLIN, - EvmVersion::London => SpecId::LONDON, - EvmVersion::Paris => SpecId::MERGE, - EvmVersion::Shanghai => SpecId::SHANGHAI, - } -} - /// Depending on the configured chain id and block number this should apply any specific changes /// /// This checks for: diff --git a/crates/forge/bin/cmd/coverage.rs b/crates/forge/bin/cmd/coverage.rs index ca0580f92331e..0ce7fdbc40f1a 100644 --- a/crates/forge/bin/cmd/coverage.rs +++ b/crates/forge/bin/cmd/coverage.rs @@ -27,7 +27,6 @@ use foundry_cli::{ }; use foundry_common::{compile::ProjectCompiler, evm::EvmArgs, fs}; use foundry_config::{Config, SolcReq}; -use foundry_evm::utils::evm_spec; use semver::Version; use std::{collections::HashMap, sync::mpsc::channel}; use tracing::trace; @@ -286,11 +285,10 @@ impl CoverageArgs { let root = project.paths.root; // Build the contract runner - let evm_spec = evm_spec(config.evm_version); let env = evm_opts.evm_env().await?; let mut runner = MultiContractRunnerBuilder::default() .initial_balance(evm_opts.initial_balance) - .evm_spec(evm_spec) + .evm_spec(config.evm_spec_id()) .sender(evm_opts.sender) .with_fork(evm_opts.get_fork(&config, env.clone())) .with_cheats_config(CheatsConfig::new(&config, &evm_opts)) diff --git a/crates/forge/bin/cmd/script/executor.rs b/crates/forge/bin/cmd/script/executor.rs index ac42e3c2a9ee1..bc31d78bfe916 100644 --- a/crates/forge/bin/cmd/script/executor.rs +++ b/crates/forge/bin/cmd/script/executor.rs @@ -20,7 +20,6 @@ use forge::{ }; use foundry_cli::utils::{ensure_clean_constructor, needs_setup}; use foundry_common::{shell, RpcUrl}; -use foundry_evm::utils::evm_spec; use futures::future::join_all; use parking_lot::RwLock; use std::{collections::VecDeque, sync::Arc}; @@ -305,7 +304,7 @@ impl ScriptArgs { // We need to enable tracing to decode contract names: local or external. let mut builder = ExecutorBuilder::new() .inspectors(|stack| stack.trace(true)) - .spec(evm_spec(script_config.config.evm_version)) + .spec(script_config.config.evm_spec_id()) .gas_limit(script_config.evm_opts.gas_limit()); if let SimulationStage::Local = stage { diff --git a/crates/forge/bin/cmd/test/mod.rs b/crates/forge/bin/cmd/test/mod.rs index 6bf9441ec3a43..d2ab5c0de80ff 100644 --- a/crates/forge/bin/cmd/test/mod.rs +++ b/crates/forge/bin/cmd/test/mod.rs @@ -30,7 +30,7 @@ use foundry_config::{ }, get_available_profiles, Config, }; -use foundry_evm::{fuzz::CounterExample, utils::evm_spec}; +use foundry_evm::fuzz::CounterExample; use regex::Regex; use std::{collections::BTreeMap, path::PathBuf, sync::mpsc::channel, time::Duration}; use tracing::trace; @@ -177,11 +177,9 @@ impl TestArgs { let env = evm_opts.evm_env().await?; // Prepare the test builder - let evm_spec = evm_spec(config.evm_version); - let mut runner = MultiContractRunnerBuilder::default() .initial_balance(evm_opts.initial_balance) - .evm_spec(evm_spec) + .evm_spec(config.evm_spec_id()) .sender(evm_opts.sender) .with_fork(evm_opts.get_fork(&config, env.clone())) .with_cheats_config(CheatsConfig::new(&config, &evm_opts)) diff --git a/crates/forge/tests/fixtures/can_test_repeatedly.stdout b/crates/forge/tests/fixtures/can_test_repeatedly.stdout index 9a044e74e69cb..6d645a5606b55 100644 --- a/crates/forge/tests/fixtures/can_test_repeatedly.stdout +++ b/crates/forge/tests/fixtures/can_test_repeatedly.stdout @@ -2,7 +2,7 @@ No files changed, compilation skipped Running 2 tests for test/Counter.t.sol:CounterTest [PASS] testFuzz_SetNumber(uint256) (runs: 256, μ: 26521, ~: 28387) -[PASS] test_Increment() (gas: 28357) +[PASS] test_Increment() (gas: 28379) Test result: ok. 2 passed; 0 failed; 0 skipped; finished in 9.42ms Ran 1 test suites: 2 tests passed, 0 failed, 0 skipped (2 total tests) diff --git a/crates/forge/tests/fixtures/can_use_libs_in_multi_fork.stdout b/crates/forge/tests/fixtures/can_use_libs_in_multi_fork.stdout index 3d5da024a361c..499648933b44c 100644 --- a/crates/forge/tests/fixtures/can_use_libs_in_multi_fork.stdout +++ b/crates/forge/tests/fixtures/can_use_libs_in_multi_fork.stdout @@ -3,7 +3,7 @@ Solc 0.8.13 finished in 1.95s Compiler run successful! Running 1 test for test/Contract.t.sol:ContractTest -[PASS] test() (gas: 70373) +[PASS] test() (gas: 70351) Test result: ok. 1 passed; 0 failed; 0 skipped; finished in 3.21s Ran 1 test suites: 1 tests passed, 0 failed, 0 skipped (1 total tests) diff --git a/crates/ui/Cargo.toml b/crates/ui/Cargo.toml index 7efe80c1aa530..74bce4d2fea8b 100644 --- a/crates/ui/Cargo.toml +++ b/crates/ui/Cargo.toml @@ -17,5 +17,5 @@ ethers.workspace = true crossterm = "0.26" eyre = "0.6" -revm = { version = "3", features = ["std", "serde"] } +revm = { workspace = true, features = ["std", "serde"] } ratatui = { version = "0.22.0", default-features = false, features = ["crossterm"]} \ No newline at end of file