Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
more breaking changes
  • Loading branch information
mattsse committed Nov 10, 2023
commit ccf9b3a6eaa4c30ab5fb39f096881994d8618a16
36 changes: 14 additions & 22 deletions crates/anvil/src/eth/backend/mem/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use foundry_evm::{
revm::{
interpreter::{CallInputs, CreateInputs, Gas, InstructionResult, Interpreter},
primitives::{Address, Bytes, B256},
EVMData,
EvmContext,
},
};

Expand Down Expand Up @@ -48,29 +48,27 @@ impl Inspector {

impl<DB: Database> revm::Inspector<DB> for Inspector {
#[inline]
fn initialize_interp(
&mut self,
interp: &mut Interpreter,
data: &mut EVMData<'_, DB>,
) -> InstructionResult {
fn initialize_interp(&mut self, interp: &mut Interpreter, data: &mut EvmContext<'_, DB>) {
call_inspectors!([&mut self.tracer], |inspector| {
inspector.initialize_interp(interp, data);
});
InstructionResult::Continue
}

#[inline]
fn step(&mut self, interp: &mut Interpreter, data: &mut EVMData<'_, DB>) -> InstructionResult {
fn step(
&mut self,
interp: &mut Interpreter,
data: &mut EvmContext<'_, DB>,
) -> InstructionResult {
call_inspectors!([&mut self.tracer], |inspector| {
inspector.step(interp, data);
});
InstructionResult::Continue
}

#[inline]
fn log(
&mut self,
evm_data: &mut EVMData<'_, DB>,
evm_data: &mut EvmContext<'_, DB>,
address: &Address,
topics: &[B256],
data: &Bytes,
Expand All @@ -81,22 +79,16 @@ impl<DB: Database> revm::Inspector<DB> for Inspector {
}

#[inline]
fn step_end(
&mut self,
interp: &mut Interpreter,
data: &mut EVMData<'_, DB>,
eval: InstructionResult,
) -> InstructionResult {
fn step_end(&mut self, interp: &mut Interpreter, data: &mut EvmContext<'_, DB>) {
call_inspectors!([&mut self.tracer], |inspector| {
inspector.step_end(interp, data, eval);
inspector.step_end(interp, data);
});
eval
}

#[inline]
fn call(
&mut self,
data: &mut EVMData<'_, DB>,
data: &mut EvmContext<'_, DB>,
call: &mut CallInputs,
) -> (InstructionResult, Gas, Bytes) {
call_inspectors!([&mut self.tracer, Some(&mut self.log_collector)], |inspector| {
Expand All @@ -109,7 +101,7 @@ impl<DB: Database> revm::Inspector<DB> for Inspector {
#[inline]
fn call_end(
&mut self,
data: &mut EVMData<'_, DB>,
data: &mut EvmContext<'_, DB>,
inputs: &CallInputs,
remaining_gas: Gas,
ret: InstructionResult,
Expand All @@ -124,7 +116,7 @@ impl<DB: Database> revm::Inspector<DB> for Inspector {
#[inline]
fn create(
&mut self,
data: &mut EVMData<'_, DB>,
data: &mut EvmContext<'_, DB>,
call: &mut CreateInputs,
) -> (InstructionResult, Option<Address>, Gas, Bytes) {
call_inspectors!([&mut self.tracer], |inspector| {
Expand All @@ -137,7 +129,7 @@ impl<DB: Database> revm::Inspector<DB> for Inspector {
#[inline]
fn create_end(
&mut self,
data: &mut EVMData<'_, DB>,
data: &mut EvmContext<'_, DB>,
inputs: &CreateInputs,
status: InstructionResult,
address: Option<Address>,
Expand Down
4 changes: 2 additions & 2 deletions crates/cheatcodes/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use foundry_evm_core::backend::DatabaseExt;
use foundry_utils::types::ToAlloy;
use revm::{
primitives::{Account, Bytecode, SpecId, KECCAK_EMPTY},
EVMData,
EvmContext,
};
use std::{collections::HashMap, path::Path};

Expand Down Expand Up @@ -397,7 +397,7 @@ fn read_callers(state: &Cheatcodes, default_sender: &Address) -> Result {

/// Ensures the `Account` is loaded and touched.
pub(super) fn journaled_account<'a, DB: DatabaseExt>(
data: &'a mut EVMData<'_, DB>,
data: &'a mut EvmContext<'_, DB>,
addr: Address,
) -> Result<&'a mut Account> {
data.journaled_state.load_account(addr, data.db)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/cheatcodes/src/evm/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub(crate) fn step(mapping_slots: &mut HashMap<Address, MappingSlots>, interpret
if interpreter.stack.peek(1) == Ok(U256::from(0x40)) {
let address = interpreter.contract.address;
let offset = interpreter.stack.peek(0).expect("stack size > 1").saturating_to();
let data = interpreter.memory.slice(offset, 0x40);
let data = interpreter.shared_memory.slice(offset, 0x40);
let low = B256::from_slice(&data[..0x20]);
let high = B256::from_slice(&data[0x20..]);
let result = keccak256(data);
Expand Down
59 changes: 28 additions & 31 deletions crates/cheatcodes/src/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use itertools::Itertools;
use revm::{
interpreter::{opcode, CallInputs, CreateInputs, Gas, InstructionResult, Interpreter},
primitives::{BlockEnv, CreateScheme, TransactTo},
EVMData, Inspector,
EvmContext, Inspector,
};
use serde_json::Value;
use std::{
Expand Down Expand Up @@ -211,7 +211,7 @@ impl Cheatcodes {

fn apply_cheatcode<DB: DatabaseExt>(
&mut self,
data: &mut EVMData<'_, DB>,
data: &mut EvmContext<'_, DB>,
call: &CallInputs,
) -> Result {
// decode the cheatcode call
Expand All @@ -231,7 +231,7 @@ impl Cheatcodes {
/// automatically we need to determine the new address
fn allow_cheatcodes_on_create<DB: DatabaseExt>(
&self,
data: &mut EVMData<'_, DB>,
data: &mut EvmContext<'_, DB>,
inputs: &CreateInputs,
) {
if data.journaled_state.depth > 1 && !data.db.has_cheatcode_access(inputs.caller) {
Expand All @@ -255,7 +255,7 @@ impl Cheatcodes {
///
/// Cleanup any previously applied cheatcodes that altered the state in such a way that revm's
/// revert would run into issues.
pub fn on_revert<DB: DatabaseExt>(&mut self, data: &mut EVMData<'_, DB>) {
pub fn on_revert<DB: DatabaseExt>(&mut self, data: &mut EvmContext<'_, DB>) {
trace!(deals = ?self.eth_deals.len(), "rolling back deals");

// Delay revert clean up until expected revert is handled, if set.
Expand All @@ -281,11 +281,7 @@ impl Cheatcodes {

impl<DB: DatabaseExt> Inspector<DB> for Cheatcodes {
#[inline]
fn initialize_interp(
&mut self,
_: &mut Interpreter,
data: &mut EVMData<'_, DB>,
) -> InstructionResult {
fn initialize_interp(&mut self, _: &mut Interpreter, data: &mut EvmContext<'_, DB>) {
// When the first interpreter is initialized we've circumvented the balance and gas checks,
// so we apply our actual block data with the correct fees and all.
if let Some(block) = self.block.take() {
Expand All @@ -294,15 +290,9 @@ impl<DB: DatabaseExt> Inspector<DB> for Cheatcodes {
if let Some(gas_price) = self.gas_price.take() {
data.env.tx.gas_price = gas_price;
}

InstructionResult::Continue
}

fn step(
&mut self,
interpreter: &mut Interpreter,
data: &mut EVMData<'_, DB>,
) -> InstructionResult {
fn step(&mut self, interpreter: &mut Interpreter, data: &mut EvmContext<'_, DB>) {
self.pc = interpreter.program_counter();

// reset gas if gas metering is turned off
Expand Down Expand Up @@ -448,7 +438,7 @@ impl<DB: DatabaseExt> Inspector<DB> for Cheatcodes {
// If the offset being loaded is >= than the memory size, the
// memory is being expanded. If none of the allowed ranges contain
// [offset, offset + 32), memory has been unexpectedly mutated.
if offset >= interpreter.memory.len() as u64 && !ranges.iter().any(|range| {
if offset >= interpreter.shared_memory.len() as u64 && !ranges.iter().any(|range| {
range.contains(&offset) && range.contains(&(offset + 31))
}) {
disallowed_mem_write(offset, 32, interpreter, ranges);
Expand All @@ -475,7 +465,7 @@ impl<DB: DatabaseExt> Inspector<DB> for Cheatcodes {
range.contains(&(dest_offset + size.saturating_sub(1)))
}) && ($writes ||
[dest_offset, (dest_offset + size).saturating_sub(1)].into_iter().any(|offset| {
offset >= interpreter.memory.len() as u64
offset >= interpreter.shared_memory.len() as u64
})
);

Expand Down Expand Up @@ -519,11 +509,15 @@ impl<DB: DatabaseExt> Inspector<DB> for Cheatcodes {
if let Some(mapping_slots) = &mut self.mapping_slots {
mapping::step(mapping_slots, interpreter);
}

InstructionResult::Continue
}

fn log(&mut self, _: &mut EVMData<'_, DB>, address: &Address, topics: &[B256], data: &Bytes) {
fn log(
&mut self,
_: &mut EvmContext<'_, DB>,
address: &Address,
topics: &[B256],
data: &Bytes,
) {
if !self.expected_emits.is_empty() {
expect::handle_expect_emit(self, address, topics, data);
}
Expand All @@ -540,7 +534,7 @@ impl<DB: DatabaseExt> Inspector<DB> for Cheatcodes {

fn call(
&mut self,
data: &mut EVMData<'_, DB>,
data: &mut EvmContext<'_, DB>,
call: &mut CallInputs,
) -> (InstructionResult, Gas, Bytes) {
let gas = Gas::new(call.gas_limit);
Expand Down Expand Up @@ -694,7 +688,7 @@ impl<DB: DatabaseExt> Inspector<DB> for Cheatcodes {

fn call_end(
&mut self,
data: &mut EVMData<'_, DB>,
data: &mut EvmContext<'_, DB>,
call: &CallInputs,
remaining_gas: Gas,
status: InstructionResult,
Expand Down Expand Up @@ -891,7 +885,7 @@ impl<DB: DatabaseExt> Inspector<DB> for Cheatcodes {

fn create(
&mut self,
data: &mut EVMData<'_, DB>,
data: &mut EvmContext<'_, DB>,
call: &mut CreateInputs,
) -> (InstructionResult, Option<Address>, Gas, Bytes) {
let gas = Gas::new(call.gas_limit);
Expand Down Expand Up @@ -970,7 +964,7 @@ impl<DB: DatabaseExt> Inspector<DB> for Cheatcodes {

fn create_end(
&mut self,
data: &mut EVMData<'_, DB>,
data: &mut EvmContext<'_, DB>,
_: &CreateInputs,
status: InstructionResult,
address: Option<Address>,
Expand Down Expand Up @@ -1046,17 +1040,17 @@ fn disallowed_mem_write(
/// Expands memory, stores a revert string, and sets the return range to the revert
/// string's location in memory.
fn mstore_revert_string(interpreter: &mut Interpreter, bytes: &[u8]) {
let starting_offset = interpreter.memory.len();
interpreter.memory.resize(starting_offset + bytes.len());
interpreter.memory.set_data(starting_offset, 0, bytes.len(), bytes);
let starting_offset = interpreter.shared_memory.len();
interpreter.shared_memory.resize(starting_offset + bytes.len());
interpreter.shared_memory.set_data(starting_offset, 0, bytes.len(), bytes);
interpreter.return_offset = starting_offset;
interpreter.return_len = interpreter.memory.len() - starting_offset
interpreter.return_len = interpreter.shared_memory.len() - starting_offset
}

fn process_create<DB: DatabaseExt>(
broadcast_sender: Address,
bytecode: Bytes,
data: &mut EVMData<'_, DB>,
data: &mut EvmContext<'_, DB>,
call: &mut CreateInputs,
) -> Result<(Bytes, Option<Address>, u64), DB::Error> {
match call.scheme {
Expand Down Expand Up @@ -1094,7 +1088,10 @@ fn process_create<DB: DatabaseExt>(

// Determines if the gas limit on a given call was manually set in the script and should therefore
// not be overwritten by later estimations
fn check_if_fixed_gas_limit<DB: DatabaseExt>(data: &EVMData<'_, DB>, call_gas_limit: u64) -> bool {
fn check_if_fixed_gas_limit<DB: DatabaseExt>(
data: &EvmContext<'_, DB>,
call_gas_limit: u64,
) -> bool {
// If the gas limit was not set in the source code it is set to the estimated gas left at the
// time of the call, which should be rather close to configured gas limit.
// TODO: Find a way to reliably make this determination.
Expand Down
4 changes: 2 additions & 2 deletions crates/cheatcodes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern crate tracing;

use alloy_primitives::Address;
use foundry_evm_core::backend::DatabaseExt;
use revm::EVMData;
use revm::EvmContext;
use tracing::Level;

pub use defs::{CheatcodeDef, Vm};
Expand Down Expand Up @@ -95,7 +95,7 @@ pub(crate) struct CheatsCtxt<'a, 'b, 'c, DB: DatabaseExt> {
/// The cheatcodes inspector state.
pub(crate) state: &'a mut Cheatcodes,
/// The EVM data.
pub(crate) data: &'b mut EVMData<'c, DB>,
pub(crate) data: &'b mut EvmContext<'c, DB>,
/// The original `msg.sender`.
pub(crate) caller: Address,
}
Expand Down
4 changes: 2 additions & 2 deletions crates/evm/core/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub struct DebugStep {
/// Stack *prior* to running the associated opcode
pub stack: Vec<U256>,
/// Memory *prior* to running the associated opcode
pub memory: Vec<u8>,
pub memory: SharedMemory,
/// Opcode to be executed
pub instruction: Instruction,
/// Optional bytes that are being pushed onto the stack
Expand All @@ -132,7 +132,7 @@ impl Default for DebugStep {
fn default() -> Self {
Self {
stack: vec![],
memory: Vec::new(),
memory: Default::default(),
instruction: Instruction::OpCode(revm::interpreter::opcode::INVALID),
push_bytes: None,
pc: 0,
Expand Down
18 changes: 3 additions & 15 deletions crates/evm/coverage/src/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{HitMap, HitMaps};
use alloy_primitives::Bytes;
use revm::{
interpreter::{InstructionResult, Interpreter},
Database, EVMData, Inspector,
Database, EvmContext, Inspector,
};

#[derive(Clone, Default, Debug)]
Expand All @@ -13,30 +13,18 @@ pub struct CoverageCollector {

impl<DB: Database> Inspector<DB> for CoverageCollector {
#[inline]
fn initialize_interp(
&mut self,
interpreter: &mut Interpreter,
_: &mut EVMData<'_, DB>,
) -> InstructionResult {
fn initialize_interp(&mut self, interpreter: &mut Interpreter, _: &mut EvmContext<'_, DB>) {
let hash = interpreter.contract.hash;
self.maps.entry(hash).or_insert_with(|| {
HitMap::new(Bytes::copy_from_slice(
interpreter.contract.bytecode.original_bytecode_slice(),
))
});

InstructionResult::Continue
}

#[inline]
fn step(
&mut self,
interpreter: &mut Interpreter,
_: &mut EVMData<'_, DB>,
) -> InstructionResult {
fn step(&mut self, interpreter: &mut Interpreter, _: &mut EvmContext<'_, DB>) {
let hash = interpreter.contract.hash;
self.maps.entry(hash).and_modify(|map| map.hit(interpreter.program_counter()));

InstructionResult::Continue
}
}
2 changes: 1 addition & 1 deletion crates/evm/evm/src/executors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use foundry_evm_coverage::HitMaps;
use foundry_evm_traces::CallTraceArena;
use revm::{
db::{DatabaseCommit, DatabaseRef},
interpreter::{return_ok, CreateScheme, InstructionResult, Memory, Stack},
interpreter::{return_ok, CreateScheme, InstructionResult, SharedMemory, Stack},
primitives::{
BlockEnv, Bytecode, Env, ExecutionResult, Output, ResultAndState, SpecId, TransactTo, TxEnv,
},
Expand Down
Loading