From 5ee78b508f93dc50e8f9c6ee4b0bfcbd750f42a8 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Tue, 9 Jan 2024 17:04:08 +0100 Subject: [PATCH] chore(evm): use method instead of get_create_address util --- crates/cheatcodes/src/inspector.rs | 3 +-- crates/evm/core/src/utils.rs | 10 ---------- crates/evm/evm/src/inspectors/debugger.rs | 4 ++-- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/crates/cheatcodes/src/inspector.rs b/crates/cheatcodes/src/inspector.rs index eae7af5f2c14..854397480cba 100644 --- a/crates/cheatcodes/src/inspector.rs +++ b/crates/cheatcodes/src/inspector.rs @@ -23,7 +23,6 @@ use foundry_common::{evm::Breakpoints, provider::alloy::RpcUrl, types::ToEthers} use foundry_evm_core::{ backend::{DatabaseError, DatabaseExt, RevertDiagnostic}, constants::{CHEATCODE_ADDRESS, DEFAULT_CREATE2_DEPLOYER, HARDHAT_CONSOLE_ADDRESS, MAGIC_SKIP}, - utils::get_create_address, }; use itertools::Itertools; use revm::{ @@ -258,7 +257,7 @@ impl Cheatcodes { .get(&inputs.caller) .map(|acc| acc.info.nonce) .unwrap_or_default(); - let created_address = get_create_address(inputs, old_nonce); + let created_address = inputs.created_address(old_nonce); if data.journaled_state.depth > 1 && !data.db.has_cheatcode_access(inputs.caller) { // we only grant cheat code access for new contracts if the caller also has diff --git a/crates/evm/core/src/utils.rs b/crates/evm/core/src/utils.rs index 996408198caf..cbce9fc9984d 100644 --- a/crates/evm/core/src/utils.rs +++ b/crates/evm/core/src/utils.rs @@ -268,16 +268,6 @@ pub fn configure_tx_env(env: &mut revm::primitives::Env, tx: &Transaction) { env.tx.transact_to = tx.to.map(TransactTo::Call).unwrap_or_else(TransactTo::create) } -/// Get the address of a contract creation -pub fn get_create_address(call: &CreateInputs, nonce: u64) -> Address { - match call.scheme { - CreateScheme::Create => call.caller.create(nonce), - CreateScheme::Create2 { salt } => { - call.caller.create2_from_code(B256::from(salt), &call.init_code) - } - } -} - /// Get the gas used, accounting for refunds pub fn gas_used(spec: SpecId, spent: u64, refunded: u64) -> u64 { let refund_quotient = if SpecId::enabled(spec, SpecId::LONDON) { 5 } else { 2 }; diff --git a/crates/evm/evm/src/inspectors/debugger.rs b/crates/evm/evm/src/inspectors/debugger.rs index c61a7f859dd0..32345256ed07 100644 --- a/crates/evm/evm/src/inspectors/debugger.rs +++ b/crates/evm/evm/src/inspectors/debugger.rs @@ -4,7 +4,7 @@ use foundry_evm_core::{ backend::DatabaseExt, constants::CHEATCODE_ADDRESS, debug::{DebugArena, DebugNode, DebugStep, Instruction}, - utils::{gas_used, get_create_address, CallKind}, + utils::{gas_used, CallKind}, }; use revm::{ interpreter::{ @@ -133,7 +133,7 @@ impl Inspector for Debugger { let nonce = data.journaled_state.account(call.caller).info.nonce; self.enter( data.journaled_state.depth() as usize, - get_create_address(call, nonce), + call.created_address(nonce), CallKind::Create, );