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

feat(evm): migrate to alloy-genesis, rm ethers-core #6880

Merged
merged 8 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
39 changes: 25 additions & 14 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ ethers-solc = { version = "2.0", default-features = false }
## alloy
alloy-consensus = { git = "https://github.com/alloy-rs/alloy" }
alloy-eips = { git = "https://github.com/alloy-rs/alloy" }
alloy-genesis = { 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" }
Expand Down
1 change: 1 addition & 0 deletions crates/cheatcodes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ foundry-evm-core.workspace = true
alloy-dyn-abi.workspace = true
alloy-json-abi.workspace = true
alloy-primitives.workspace = true
alloy-genesis.workspace = true
alloy-sol-types.workspace = true
alloy-providers.workspace = true
alloy-rpc-types.workspace = true
Expand Down
23 changes: 7 additions & 16 deletions crates/cheatcodes/src/evm.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
//! Implementations of [`Evm`](crate::Group::Evm) cheatcodes.

use crate::{Cheatcode, Cheatcodes, CheatsCtxt, Result, Vm::*};
use alloy_primitives::{Address, Bytes, U256};
use alloy_genesis::{Genesis, GenesisAccount};
use alloy_primitives::{Address, Bytes, B256, U256};
use alloy_sol_types::SolValue;
use ethers_core::{
types::H256,
utils::{Genesis, GenesisAccount},
};
use ethers_signers::Signer;
use foundry_common::{
fs::{read_json_file, write_json_file},
types::{ToAlloy, ToEthers},
types::ToAlloy,
};
use foundry_evm_core::{
backend::{DatabaseExt, RevertSnapshotAction},
Expand Down Expand Up @@ -81,7 +78,7 @@ impl Cheatcode for loadAllocsCall {

// Let's first assume we're reading a genesis.json file.
let allocs: HashMap<Address, GenesisAccount> = match read_json_file::<Genesis>(path) {
Ok(genesis) => genesis.alloc.into_iter().map(|(k, g)| (k.to_alloy(), g)).collect(),
Ok(genesis) => genesis.alloc.into_iter().collect(),
// If that fails, let's try reading a file with just the genesis accounts.
Err(_) => read_json_file(path)?,
};
Expand Down Expand Up @@ -121,18 +118,12 @@ impl Cheatcode for dumpStateCall {
key,
GenesisAccount {
nonce: Some(val.info.nonce),
balance: val.info.balance.to_ethers(),
code: Some(
val.info.code.clone().unwrap_or_default().original_bytes().to_ethers(),
),
balance: val.info.balance,
code: Some(val.info.code.clone().unwrap_or_default().original_bytes()),
storage: Some(
val.storage
.iter()
.map(|(k, v)| {
let key = k.to_be_bytes::<32>();
let val = v.present_value().to_be_bytes::<32>();
(H256::from_slice(&key), H256::from_slice(&val))
})
.map(|(k, v)| (B256::from(*k), B256::from(v.present_value())))
.collect(),
),
},
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ 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-genesis.workspace = true
alloy-providers.workspace = true
alloy-rpc-types.workspace = true
alloy-sol-types.workspace = true
Expand All @@ -37,7 +38,6 @@ revm = { workspace = true, default-features = false, features = [
] }
revm-inspectors.workspace = true

ethers-core.workspace = true
ethers-providers.workspace = true

derive_more.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/core/src/backend/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::{
},
fork::{CreateFork, ForkId},
};
use alloy_genesis::GenesisAccount;
use alloy_primitives::{Address, B256, U256};
use ethers_core::utils::GenesisAccount;
use revm::{
db::DatabaseRef,
primitives::{AccountInfo, Bytecode, Env, ResultAndState},
Expand Down
6 changes: 3 additions & 3 deletions crates/evm/core/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use crate::{
snapshot::Snapshots,
utils::configure_tx_env,
};
use alloy_genesis::GenesisAccount;
use alloy_primitives::{b256, keccak256, Address, B256, U256, U64};
use alloy_rpc_types::{Block, BlockNumberOrTag, BlockTransactions, Transaction};
use ethers_core::utils::GenesisAccount;
use foundry_common::{is_known_system_sender, types::ToAlloy, SYSTEM_TRANSACTION_TYPE};
use foundry_common::{is_known_system_sender, SYSTEM_TRANSACTION_TYPE};
use revm::{
db::{CacheDB, DatabaseRef},
inspectors::NoOpInspector,
Expand Down Expand Up @@ -1354,7 +1354,7 @@ impl DatabaseExt for Backend {
}
// Set the account's nonce and balance.
state_acc.info.nonce = acc.nonce.unwrap_or_default();
state_acc.info.balance = acc.balance.to_alloy();
state_acc.info.balance = acc.balance;

// Touch the account to ensure the loaded information persists if called in `setUp`.
journaled_state.touch(addr);
Expand Down
Loading