Skip to content

Commit

Permalink
refactor: modularize foundry-evm
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Oct 26, 2023
1 parent 000f38c commit 1ed5fa7
Show file tree
Hide file tree
Showing 149 changed files with 2,042 additions and 2,400 deletions.
107 changes: 100 additions & 7 deletions Cargo.lock

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

14 changes: 8 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,18 @@ foundry-common = { path = "crates/common" }
foundry-cheatcodes = { path = "crates/cheatcodes" }
foundry-config = { path = "crates/config" }
foundry-evm = { path = "crates/evm" }
foundry-evm-coverage = { path = "crates/evm-coverage" }
foundry-evm-executors = { path = "crates/evm-executors" }
foundry-evm-fuzz = { path = "crates/evm-fuzz" }
foundry-evm-traces = { path = "crates/evm-traces" }
foundry-macros = { path = "crates/macros" }
foundry-test-utils = { path = "crates/test-utils" }
foundry-utils = { path = "crates/utils" }
foundry-debugger = { path = "crates/debugger" }

foundry-compilers = { version = "0.1", default-features = false }
foundry-block-explorers = { version = "0.1", default-features = false }

## revm
# no default features to avoid c-kzg
revm = { version = "3", default-features = false } #
Expand All @@ -159,11 +166,6 @@ alloy-json-abi = "0.4.1"
alloy-sol-types = "0.4.1"
syn-solidity = "0.4.1"

# solc utils
foundry-compilers = { version = "0.1", default-features = false }
# block explorer utils
foundry-block-explorers = { version = "0.1", default-features = false }

solang-parser = "=0.3.2"

## misc
Expand Down Expand Up @@ -204,7 +206,7 @@ ethers-etherscan = { git = "https://github.com/gakonst/ethers-rs", rev = "9754f2
ethers-solc = { git = "https://github.com/gakonst/ethers-rs", rev = "9754f22d06a2defe5608c4c9b809cc361443a3dc" }

foundry-compilers = { git = "https://github.com/foundry-rs/compilers" }
foundry-block-explorers = { git = "https://github.com/foundry-rs/block-explorers"}
foundry-block-explorers = { git = "https://github.com/foundry-rs/block-explorers" }

alloy-dyn-abi = { git = "https://github.com/alloy-rs/core/" }
alloy-primitives = { git = "https://github.com/alloy-rs/core/" }
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/core/src/eth/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl fmt::Display for SubscriptionId {
}

impl fmt::Debug for SubscriptionId {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
SubscriptionId::Number(num) => num.fmt(f),
SubscriptionId::String(s) => s.fmt(f),
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/core/src/eth/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use ethers_core::{
rlp::{Decodable, DecoderError, Encodable, Rlp, RlpStream},
},
};
use foundry_evm::trace::CallTraceArena;
use foundry_evm::traces::CallTraceArena;
use foundry_utils::types::ToAlloy;
use revm::{
interpreter::InstructionResult,
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl<'a> serde::Deserialize<'a> for Index {
impl<'a> serde::de::Visitor<'a> for IndexVisitor {
type Value = Index;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(formatter, "hex-encoded or decimal index")
}

Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/rpc/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl RpcError {
}

impl fmt::Display for RpcError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}: {}", self.code.message(), self.message)
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/anvil/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ use foundry_common::{
};
use foundry_config::Config;
use foundry_evm::{
executor::{
executors::{
fork::{BlockchainDb, BlockchainDbMeta, SharedBackend},
inspector::DEFAULT_CREATE2_DEPLOYER,
DEFAULT_CREATE2_DEPLOYER,
},
revm,
revm::primitives::{BlockEnv, CfgEnv, SpecId, TxEnv, U256 as rU256},
Expand Down
3 changes: 2 additions & 1 deletion crates/anvil/src/eth/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ use ethers::{
};
use foundry_common::ProviderBuilder;
use foundry_evm::{
executor::{backend::DatabaseError, DatabaseRef},
executors::backend::DatabaseError,
revm::{
db::DatabaseRef,
interpreter::{return_ok, return_revert, InstructionResult},
primitives::BlockEnv,
},
Expand Down
9 changes: 4 additions & 5 deletions crates/anvil/src/eth/backend/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ use ethers::{
};
use foundry_common::errors::FsPathError;
use foundry_evm::{
executor::{
backend::{snapshot::StateSnapshot, DatabaseError, DatabaseResult, MemDb},
executors::{
backend::{DatabaseError, DatabaseResult, MemDb, StateSnapshot},
fork::BlockchainDb,
DatabaseRef,
},
hashbrown::HashMap,
revm::{
db::{CacheDB, DbAccount},
db::{CacheDB, DatabaseRef, DbAccount},
primitives::{Bytecode, KECCAK_EMPTY},
Database, DatabaseCommit,
},
HashMap,
};
use foundry_utils::types::ToAlloy;
use hash_db::HashDB;
Expand Down
4 changes: 2 additions & 2 deletions crates/anvil/src/eth/backend/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ use ethers::{
utils::rlp,
};
use foundry_evm::{
executor::backend::DatabaseError,
executors::backend::DatabaseError,
revm,
revm::{
interpreter::InstructionResult,
primitives::{BlockEnv, CfgEnv, EVMError, Env, ExecutionResult, Output, SpecId},
},
trace::{node::CallTraceNode, CallTraceArena},
traces::{node::CallTraceNode, CallTraceArena},
utils::{eval_to_instruction_result, halt_to_instruction_result},
};
use foundry_utils::types::{ToAlloy, ToEthers};
Expand Down
8 changes: 4 additions & 4 deletions crates/anvil/src/eth/backend/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use ethers::{
types::{Address, H256},
};
use foundry_evm::{
executor::{
backend::{snapshot::StateSnapshot, DatabaseError, DatabaseResult},
DatabaseRef,
executors::backend::{DatabaseError, DatabaseResult, StateSnapshot},
revm::{
db::DatabaseRef,
primitives::{AccountInfo, Bytecode, KECCAK_EMPTY},
},
revm::primitives::{AccountInfo, Bytecode, KECCAK_EMPTY},
};
use foundry_utils::types::{ToAlloy, ToEthers};
use parking_lot::Mutex;
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/src/eth/backend/mem/cache.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::config::anvil_tmp_dir;
use ethers::prelude::H256;
use foundry_evm::executor::backend::snapshot::StateSnapshot;
use foundry_evm::executors::backend::StateSnapshot;
use std::{
io,
path::{Path, PathBuf},
Expand Down
7 changes: 4 additions & 3 deletions crates/anvil/src/eth/backend/mem/fork_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ use crate::{
Address, U256,
};
use ethers::{prelude::H256, types::BlockId};
pub use foundry_evm::executor::fork::database::ForkedDatabase;
use foundry_evm::{
executor::{
backend::{snapshot::StateSnapshot, DatabaseResult},
executors::{
backend::{DatabaseResult, StateSnapshot},
fork::{database::ForkDbSnapshot, BlockchainDb},
},
revm::Database,
};
use foundry_utils::types::{ToAlloy, ToEthers};

pub use foundry_evm::executors::fork::database::ForkedDatabase;

/// Implement the helper for the fork database
impl Db for ForkedDatabase {
fn insert_account(&mut self, address: Address, account: AccountInfo) {
Expand Down
16 changes: 8 additions & 8 deletions crates/anvil/src/eth/backend/mem/in_memory_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@ use crate::{
AsHashDB, Db, MaybeForkedDatabase, MaybeHashDatabase, SerializableAccountRecord,
SerializableState, StateDb,
},
mem::state::{state_merkle_trie_root, trie_hash_db},
mem::state::{state_merkle_trie_root, storage_trie_db, trie_hash_db},
revm::primitives::AccountInfo,
Address, U256,
};
use ethers::{prelude::H256, types::BlockId};
use foundry_evm::executors::{
backend::{DatabaseResult, StateSnapshot},
fork::BlockchainDb,
};
use foundry_utils::types::{ToAlloy, ToEthers};
use tracing::{trace, warn};

// reexport for convenience
use crate::mem::state::storage_trie_db;
pub use foundry_evm::executor::{backend::MemDb, DatabaseRef};
use foundry_evm::executor::{
backend::{snapshot::StateSnapshot, DatabaseResult},
fork::BlockchainDb,
};
pub use foundry_evm::{executors::backend::MemDb, revm::db::DatabaseRef};

impl Db for MemDb {
fn insert_account(&mut self, address: Address, account: AccountInfo) {
Expand Down Expand Up @@ -135,6 +134,7 @@ impl MaybeForkedDatabase for MemDb {

#[cfg(test)]
mod tests {
use super::*;
use crate::{
eth::backend::db::{Db, SerializableAccountRecord, SerializableState},
revm::primitives::AccountInfo,
Expand All @@ -143,7 +143,7 @@ mod tests {
use alloy_primitives::{Bytes, U256 as rU256};
use ethers::types::U256;
use foundry_evm::{
executor::{backend::MemDb, DatabaseRef},
executors::backend::MemDb,
revm::primitives::{Bytecode, KECCAK_EMPTY},
};
use foundry_utils::types::ToAlloy;
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/src/eth/backend/mem/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ethers::types::Log;
use foundry_evm::{
call_inspectors,
decode::decode_console_logs,
executor::inspector::{LogCollector, Tracer},
inspectors::{LogCollector, Tracer},
revm,
revm::{
interpreter::{CallInputs, CreateInputs, Gas, InstructionResult, Interpreter},
Expand Down
Loading

0 comments on commit 1ed5fa7

Please sign in to comment.