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

chore(evm): rm more etherses #6823

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
4 changes: 2 additions & 2 deletions crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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?
}
Expand Down
7 changes: 4 additions & 3 deletions crates/evm/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand Down
24 changes: 14 additions & 10 deletions crates/evm/core/src/fork/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -18,7 +17,7 @@ use futures::{
use revm::primitives::Env;
use std::{
collections::HashMap,
fmt,
fmt::{self, Write},
pin::Pin,
sync::{
atomic::AtomicUsize,
Expand All @@ -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<u64>) -> 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
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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<u64>) -> 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
Expand Down
47 changes: 9 additions & 38 deletions crates/evm/core/src/utils.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -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 {
Expand Down Expand Up @@ -84,27 +55,27 @@ 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::<u64>() >= 15_537_351u64 {
env.block.difficulty = env.block.prevrandao.unwrap_or_default().into();
}

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::<U256>(l1_block_number) {
env.block.number = l1_block_number.to_alloy();
env.block.number = l1_block_number;
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/evm/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -47,3 +47,4 @@ proptest = "1"
thiserror = "1"
tracing = "0.1"
rayon = "1"
rand.workspace = true
2 changes: 1 addition & 1 deletion crates/evm/evm/src/executors/invariant/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;
Expand Down