From 28fb534ca67196172b743d730acdcfc3c40544ff Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Tue, 16 Jan 2024 18:37:53 +0100 Subject: [PATCH] chore(evm): rm more etherses --- Cargo.lock | 28 +++++------ Cargo.toml | 6 ++- crates/anvil/src/eth/backend/mem/mod.rs | 4 +- crates/evm/core/Cargo.toml | 7 +-- crates/evm/core/src/fork/multi.rs | 24 ++++++---- crates/evm/core/src/utils.rs | 47 ++++--------------- crates/evm/evm/Cargo.toml | 3 +- .../evm/evm/src/executors/invariant/error.rs | 2 +- 8 files changed, 50 insertions(+), 71 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d3b288ea1fe1..ed0a9398099a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -90,7 +90,7 @@ dependencies = [ [[package]] name = "alloy-consensus" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#87de288dd3e6258ff634ce147f5fd06382d29660" +source = "git+https://github.com/alloy-rs/alloy#ccc6c9340be86cf6c054776747daf70ce18cc4aa" dependencies = [ "alloy-eips", "alloy-network", @@ -122,7 +122,7 @@ dependencies = [ [[package]] name = "alloy-eips" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#87de288dd3e6258ff634ce147f5fd06382d29660" +source = "git+https://github.com/alloy-rs/alloy#ccc6c9340be86cf6c054776747daf70ce18cc4aa" dependencies = [ "alloy-primitives", "alloy-rlp", @@ -145,7 +145,7 @@ dependencies = [ [[package]] name = "alloy-json-rpc" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#87de288dd3e6258ff634ce147f5fd06382d29660" +source = "git+https://github.com/alloy-rs/alloy#ccc6c9340be86cf6c054776747daf70ce18cc4aa" dependencies = [ "alloy-primitives", "serde", @@ -156,7 +156,7 @@ dependencies = [ [[package]] name = "alloy-network" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#87de288dd3e6258ff634ce147f5fd06382d29660" +source = "git+https://github.com/alloy-rs/alloy#ccc6c9340be86cf6c054776747daf70ce18cc4aa" dependencies = [ "alloy-eips", "alloy-json-rpc", @@ -195,7 +195,7 @@ dependencies = [ [[package]] name = "alloy-providers" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#87de288dd3e6258ff634ce147f5fd06382d29660" +source = "git+https://github.com/alloy-rs/alloy#ccc6c9340be86cf6c054776747daf70ce18cc4aa" dependencies = [ "alloy-network", "alloy-primitives", @@ -214,7 +214,7 @@ dependencies = [ [[package]] name = "alloy-pubsub" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#87de288dd3e6258ff634ce147f5fd06382d29660" +source = "git+https://github.com/alloy-rs/alloy#ccc6c9340be86cf6c054776747daf70ce18cc4aa" dependencies = [ "alloy-json-rpc", "alloy-primitives", @@ -252,7 +252,7 @@ dependencies = [ [[package]] name = "alloy-rpc-client" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#87de288dd3e6258ff634ce147f5fd06382d29660" +source = "git+https://github.com/alloy-rs/alloy#ccc6c9340be86cf6c054776747daf70ce18cc4aa" dependencies = [ "alloy-json-rpc", "alloy-transport", @@ -269,7 +269,7 @@ dependencies = [ [[package]] name = "alloy-rpc-trace-types" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#87de288dd3e6258ff634ce147f5fd06382d29660" +source = "git+https://github.com/alloy-rs/alloy#ccc6c9340be86cf6c054776747daf70ce18cc4aa" dependencies = [ "alloy-primitives", "alloy-rpc-types", @@ -280,7 +280,7 @@ dependencies = [ [[package]] name = "alloy-rpc-types" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#87de288dd3e6258ff634ce147f5fd06382d29660" +source = "git+https://github.com/alloy-rs/alloy#ccc6c9340be86cf6c054776747daf70ce18cc4aa" dependencies = [ "alloy-primitives", "alloy-rlp", @@ -335,7 +335,7 @@ dependencies = [ [[package]] name = "alloy-transport" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#87de288dd3e6258ff634ce147f5fd06382d29660" +source = "git+https://github.com/alloy-rs/alloy#ccc6c9340be86cf6c054776747daf70ce18cc4aa" dependencies = [ "alloy-json-rpc", "base64 0.21.7", @@ -351,7 +351,7 @@ dependencies = [ [[package]] name = "alloy-transport-http" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#87de288dd3e6258ff634ce147f5fd06382d29660" +source = "git+https://github.com/alloy-rs/alloy#ccc6c9340be86cf6c054776747daf70ce18cc4aa" dependencies = [ "alloy-json-rpc", "alloy-transport", @@ -364,7 +364,7 @@ dependencies = [ [[package]] name = "alloy-transport-ipc" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#87de288dd3e6258ff634ce147f5fd06382d29660" +source = "git+https://github.com/alloy-rs/alloy#ccc6c9340be86cf6c054776747daf70ce18cc4aa" dependencies = [ "alloy-json-rpc", "alloy-pubsub", @@ -382,7 +382,7 @@ dependencies = [ [[package]] name = "alloy-transport-ws" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy#87de288dd3e6258ff634ce147f5fd06382d29660" +source = "git+https://github.com/alloy-rs/alloy#ccc6c9340be86cf6c054776747daf70ce18cc4aa" dependencies = [ "alloy-pubsub", "alloy-transport", @@ -3164,7 +3164,6 @@ dependencies = [ "alloy-rpc-types", "alloy-sol-types", "const-hex", - "ethers-core", "ethers-signers", "eyre", "foundry-cheatcodes", @@ -3179,6 +3178,7 @@ dependencies = [ "itertools 0.11.0", "parking_lot", "proptest", + "rand 0.8.5", "rayon", "revm", "revm-inspectors", diff --git a/Cargo.toml b/Cargo.toml index 56593d6a3721..3c4d6f16cc9b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -145,14 +145,16 @@ ethers-solc = { version = "2.0", default-features = false } ## alloy alloy-consensus = { git = "https://github.com/alloy-rs/alloy" } -alloy-network = { git = "https://github.com/alloy-rs/alloy" } +alloy-eips = { git = "https://github.com/alloy-rs/alloy" } alloy-json-rpc = { git = "https://github.com/alloy-rs/alloy" } +alloy-network = { git = "https://github.com/alloy-rs/alloy" } +alloy-node-bindings = { git = "https://github.com/alloy-rs/alloy" } alloy-providers = { git = "https://github.com/alloy-rs/alloy" } alloy-pubsub = { git = "https://github.com/alloy-rs/alloy" } alloy-rpc-client = { git = "https://github.com/alloy-rs/alloy" } alloy-rpc-trace-types = { git = "https://github.com/alloy-rs/alloy" } alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy" } -alloy-eips = { git = "https://github.com/alloy-rs/alloy" } +alloy-signer = { git = "https://github.com/alloy-rs/alloy" } alloy-transport = { git = "https://github.com/alloy-rs/alloy" } alloy-transport-http = { git = "https://github.com/alloy-rs/alloy" } alloy-transport-ipc = { git = "https://github.com/alloy-rs/alloy" } diff --git a/crates/anvil/src/eth/backend/mem/mod.rs b/crates/anvil/src/eth/backend/mem/mod.rs index 81395f40d050..f3ae13126de2 100644 --- a/crates/anvil/src/eth/backend/mem/mod.rs +++ b/crates/anvil/src/eth/backend/mem/mod.rs @@ -74,7 +74,7 @@ use foundry_evm::{ }, }, traces::{TracingInspector, TracingInspectorConfig}, - utils::{eval_to_instruction_result, halt_to_instruction_result, u256_to_h256_be}, + utils::{eval_to_instruction_result, halt_to_instruction_result}, }; use futures::channel::mpsc::{unbounded, UnboundedSender}; use hash_db::HashDB; @@ -1757,7 +1757,7 @@ impl Backend { self.with_database_at(block_request, |db, _| { trace!(target: "backend", "get storage for {:?} at {:?}", address, index); let val = db.storage_ref(address, index)?; - Ok(u256_to_h256_be(val.to_ethers()).to_alloy()) + Ok(val.into()) }) .await? } diff --git a/crates/evm/core/Cargo.toml b/crates/evm/core/Cargo.toml index 750403cf5d98..97b9f77a40f2 100644 --- a/crates/evm/core/Cargo.toml +++ b/crates/evm/core/Cargo.toml @@ -20,7 +20,11 @@ foundry-macros.workspace = true alloy-dyn-abi = { workspace = true, features = ["arbitrary", "eip712"] } alloy-json-abi.workspace = true alloy-primitives = { workspace = true, features = ["serde", "getrandom", "arbitrary", "rlp"] } +alloy-providers.workspace = true +alloy-rpc-types.workspace = true alloy-sol-types.workspace = true +alloy-transport.workspace = true + revm = { workspace = true, default-features = false, features = [ "std", "serde", @@ -32,9 +36,6 @@ revm = { workspace = true, default-features = false, features = [ "optimism", ] } revm-inspectors.workspace = true -alloy-providers = { workspace = true } -alloy-transport = { workspace = true } -alloy-rpc-types = { workspace = true } ethers-core.workspace = true ethers-providers.workspace = true diff --git a/crates/evm/core/src/fork/multi.rs b/crates/evm/core/src/fork/multi.rs index acf509547186..483686980833 100644 --- a/crates/evm/core/src/fork/multi.rs +++ b/crates/evm/core/src/fork/multi.rs @@ -6,7 +6,6 @@ use crate::fork::{BackendHandler, BlockchainDb, BlockchainDbMeta, CreateFork, SharedBackend}; use alloy_providers::provider::Provider; use alloy_transport::BoxTransport; -use ethers_core::types::BlockNumber; use foundry_common::provider::alloy::ProviderBuilder; use foundry_config::Config; use futures::{ @@ -18,7 +17,7 @@ use futures::{ use revm::primitives::Env; use std::{ collections::HashMap, - fmt, + fmt::{self, Write}, pin::Pin, sync::{ atomic::AtomicUsize, @@ -34,7 +33,18 @@ use std::{ pub struct ForkId(pub String); impl ForkId { - /// Returns the identifier of the fork + /// Returns the identifier for a Fork from a URL and block number. + pub fn new(url: &str, num: Option) -> Self { + let mut id = url.to_string(); + id.push('@'); + match num { + Some(n) => write!(id, "{n:#x}").unwrap(), + None => id.push_str("latest"), + } + ForkId(id) + } + + /// Returns the identifier of the fork. pub fn as_str(&self) -> &str { &self.0 } @@ -245,7 +255,7 @@ impl MultiForkHandler { } fn create_fork(&mut self, fork: CreateFork, sender: CreateSender) { - let fork_id = create_fork_id(&fork.url, fork.evm_opts.fork_block_number); + let fork_id = ForkId::new(&fork.url, fork.evm_opts.fork_block_number); trace!(?fork_id, "created new forkId"); if let Some(fork) = self.forks.get(&fork_id).cloned() { @@ -470,12 +480,6 @@ impl Drop for ShutDownMultiFork { } } -/// Returns the identifier for a Fork which consists of the url and the block number -fn create_fork_id(url: &str, num: Option) -> ForkId { - let num = num.map(|num| BlockNumber::Number(num.into())).unwrap_or(BlockNumber::Latest); - ForkId(format!("{url}@{num}")) -} - /// Creates a new fork /// /// This will establish a new `Provider` to the endpoint and return the Fork Backend diff --git a/crates/evm/core/src/utils.rs b/crates/evm/core/src/utils.rs index aad717afb133..e0f0f1ee80f4 100644 --- a/crates/evm/core/src/utils.rs +++ b/crates/evm/core/src/utils.rs @@ -1,9 +1,8 @@ use alloy_json_abi::{Function, JsonAbi}; -use alloy_primitives::FixedBytes; +use alloy_primitives::{FixedBytes, U256}; use alloy_rpc_types::{Block, Transaction}; -use ethers_core::types::{Chain, H256, U256}; use eyre::ContextCompat; -use foundry_common::types::ToAlloy; +use foundry_config::NamedChain; use revm::{ interpreter::InstructionResult, primitives::{Eval, Halt, SpecId, TransactTo}, @@ -14,34 +13,6 @@ pub use revm::primitives::State as StateChangeset; pub use crate::ic::*; -/// Small helper function to convert [U256] into [H256]. -#[inline] -pub fn u256_to_h256_le(u: U256) -> H256 { - let mut h = H256::default(); - u.to_little_endian(h.as_mut()); - h -} - -/// Small helper function to convert [U256] into [H256]. -#[inline] -pub fn u256_to_h256_be(u: U256) -> H256 { - let mut h = H256::default(); - u.to_big_endian(h.as_mut()); - h -} - -/// Small helper function to convert [H256] into [U256]. -#[inline] -pub fn h256_to_u256_be(storage: H256) -> U256 { - U256::from_big_endian(storage.as_bytes()) -} - -/// Small helper function to convert [H256] into [U256]. -#[inline] -pub fn h256_to_u256_le(storage: H256) -> U256 { - U256::from_little_endian(storage.as_bytes()) -} - /// Small helper function to convert an Eval into an InstructionResult #[inline] pub fn eval_to_instruction_result(eval: Eval) -> InstructionResult { @@ -84,11 +55,11 @@ pub fn halt_to_instruction_result(halt: Halt) -> InstructionResult { /// This checks for: /// - prevrandao mixhash after merge pub fn apply_chain_and_block_specific_env_changes(env: &mut revm::primitives::Env, block: &Block) { - if let Ok(chain) = Chain::try_from(env.cfg.chain_id) { + if let Ok(chain) = NamedChain::try_from(env.cfg.chain_id) { let block_number = block.header.number.unwrap_or_default(); match chain { - Chain::Mainnet => { + NamedChain::Mainnet => { // after merge difficulty is supplanted with prevrandao EIP-4399 if block_number.to::() >= 15_537_351u64 { env.block.difficulty = env.block.prevrandao.unwrap_or_default().into(); @@ -96,15 +67,15 @@ pub fn apply_chain_and_block_specific_env_changes(env: &mut revm::primitives::En return; } - Chain::Arbitrum | - Chain::ArbitrumGoerli | - Chain::ArbitrumNova | - Chain::ArbitrumTestnet => { + NamedChain::Arbitrum | + NamedChain::ArbitrumGoerli | + NamedChain::ArbitrumNova | + NamedChain::ArbitrumTestnet => { // on arbitrum `block.number` is the L1 block which is included in the // `l1BlockNumber` field if let Some(l1_block_number) = block.other.get("l1BlockNumber").cloned() { if let Ok(l1_block_number) = serde_json::from_value::(l1_block_number) { - env.block.number = l1_block_number.to_alloy(); + env.block.number = l1_block_number; } } } diff --git a/crates/evm/evm/Cargo.toml b/crates/evm/evm/Cargo.toml index dddf79e2a18b..0ad1d709e05f 100644 --- a/crates/evm/evm/Cargo.toml +++ b/crates/evm/evm/Cargo.toml @@ -36,7 +36,7 @@ revm = { workspace = true, default-features = false, features = [ "arbitrary", ] } revm-inspectors.workspace = true -ethers-core.workspace = true + ethers-signers.workspace = true itertools.workspace = true @@ -47,3 +47,4 @@ proptest = "1" thiserror = "1" tracing = "0.1" rayon = "1" +rand.workspace = true diff --git a/crates/evm/evm/src/executors/invariant/error.rs b/crates/evm/evm/src/executors/invariant/error.rs index 1f4c87c8d592..7dd67289a5be 100644 --- a/crates/evm/evm/src/executors/invariant/error.rs +++ b/crates/evm/evm/src/executors/invariant/error.rs @@ -2,7 +2,6 @@ use super::{BasicTxDetails, InvariantContract}; use crate::executors::{Executor, RawCallResult}; use alloy_json_abi::Function; use alloy_primitives::{Address, Bytes, Log}; -use ethers_core::rand::{seq, thread_rng, Rng}; use eyre::Result; use foundry_common::contracts::{ContractsByAddress, ContractsByArtifact}; use foundry_evm_core::{constants::CALLER, decode::decode_revert}; @@ -11,6 +10,7 @@ use foundry_evm_traces::{load_contracts, CallTraceArena, TraceKind, Traces}; use itertools::Itertools; use parking_lot::RwLock; use proptest::test_runner::TestError; +use rand::{seq, thread_rng, Rng}; use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; use revm::primitives::U256; use std::sync::Arc;