Skip to content

chore: revm bump #6275

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

Closed
wants to merge 4 commits into from
Closed
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
36 changes: 21 additions & 15 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,6 @@ alloy-dyn-abi = { git = "https://github.com/alloy-rs/core/" }
alloy-primitives = { git = "https://github.com/alloy-rs/core/" }
alloy-json-abi = { git = "https://github.com/alloy-rs/core/" }
alloy-sol-types = { git = "https://github.com/alloy-rs/core/" }

revm = { git = "https://github.com/bluealloy/revm", rev = "e17c529e51de83c938e606d7c79776fcc1a6381f" }
revm-primitives = { git = "https://github.com/bluealloy/revm", rev = "e17c529e51de83c938e606d7c79776fcc1a6381f" }
10 changes: 5 additions & 5 deletions crates/anvil/src/eth/backend/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub trait Db:
/// Deserialize and add all chain data to the backend storage
fn load_state(&mut self, state: SerializableState) -> DatabaseResult<bool> {
for (addr, account) in state.accounts.into_iter() {
let old_account_nonce = DatabaseRef::basic(self, addr.to_alloy())
let old_account_nonce = DatabaseRef::basic_ref(self, addr.to_alloy())
.ok()
.and_then(|acc| acc.map(|acc| acc.nonce))
.unwrap_or_default();
Expand Down Expand Up @@ -288,19 +288,19 @@ impl StateDb {

impl DatabaseRef for StateDb {
type Error = DatabaseError;
fn basic(&self, address: B160) -> DatabaseResult<Option<AccountInfo>> {
fn basic_ref(&self, address: B160) -> DatabaseResult<Option<AccountInfo>> {
self.0.basic(address)
}

fn code_by_hash(&self, code_hash: B256) -> DatabaseResult<Bytecode> {
fn code_by_hash_ref(&self, code_hash: B256) -> DatabaseResult<Bytecode> {
self.0.code_by_hash(code_hash)
}

fn storage(&self, address: B160, index: rU256) -> DatabaseResult<rU256> {
fn storage_ref(&self, address: B160, index: rU256) -> DatabaseResult<rU256> {
self.0.storage(address, index)
}

fn block_hash(&self, number: rU256) -> DatabaseResult<B256> {
fn block_hash_ref(&self, number: rU256) -> DatabaseResult<B256> {
self.0.block_hash(number)
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/src/eth/backend/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl ClientFork {
self.config.read().base_fee
}

pub fn block_hash(&self) -> H256 {
pub fn block_hash_ref(&self) -> H256 {
self.config.read().block_hash
}

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 @@ -103,21 +103,21 @@ pub(crate) struct AtGenesisStateDb<'a> {

impl<'a> DatabaseRef for AtGenesisStateDb<'a> {
type Error = DatabaseError;
fn basic(&self, address: aAddress) -> DatabaseResult<Option<AccountInfo>> {
fn basic_ref(&self, address: aAddress) -> DatabaseResult<Option<AccountInfo>> {
if let Some(acc) = self.accounts.get(&(address.to_ethers())).cloned() {
return Ok(Some(acc))
}
self.db.basic(address)
}

fn code_by_hash(&self, code_hash: B256) -> DatabaseResult<Bytecode> {
fn code_by_hash_ref(&self, code_hash: B256) -> DatabaseResult<Bytecode> {
if let Some((_, acc)) = self.accounts.iter().find(|(_, acc)| acc.code_hash == code_hash) {
return Ok(acc.code.clone().unwrap_or_default())
}
self.db.code_by_hash(code_hash)
}

fn storage(&self, address: aAddress, index: U256) -> DatabaseResult<U256> {
fn storage_ref(&self, address: aAddress, index: U256) -> DatabaseResult<U256> {
if let Some(acc) = self
.genesis
.as_ref()
Expand All @@ -133,7 +133,7 @@ impl<'a> DatabaseRef for AtGenesisStateDb<'a> {
self.db.storage(address, index)
}

fn block_hash(&self, number: U256) -> DatabaseResult<B256> {
fn block_hash_ref(&self, number: U256) -> DatabaseResult<B256> {
self.db.block_hash(number)
}
}
Expand Down
70 changes: 29 additions & 41 deletions crates/anvil/src/eth/backend/mem/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ use foundry_evm::{
inspectors::{LogCollector, Tracer},
revm,
revm::{
interpreter::{CallInputs, CreateInputs, Gas, InstructionResult, Interpreter},
interpreter::{
CallInputs, CreateInputs, Gas, InstructionResult, Interpreter, InterpreterResult,
},
primitives::{Address, Bytes, B256},
EVMData,
EvmContext,
},
};

Expand Down Expand Up @@ -48,29 +50,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 +81,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,45 +103,39 @@ impl<DB: Database> revm::Inspector<DB> for Inspector {
#[inline]
fn call_end(
&mut self,
data: &mut EVMData<'_, DB>,
inputs: &CallInputs,
remaining_gas: Gas,
ret: InstructionResult,
out: Bytes,
) -> (InstructionResult, Gas, Bytes) {
ctx: &mut EvmContext<'_, DB>,
result: InterpreterResult,
) -> InterpreterResult {
call_inspectors!([&mut self.tracer], |inspector| {
inspector.call_end(data, inputs, remaining_gas, ret, out.clone());
inspector.call_end(ctx, result.clone());
});
(ret, remaining_gas, out)
result
}

#[inline]
fn create(
&mut self,
data: &mut EVMData<'_, DB>,
call: &mut CreateInputs,
) -> (InstructionResult, Option<Address>, Gas, Bytes) {
ctx: &mut EvmContext<'_, DB>,
inputs: &mut CreateInputs,
) -> Option<(InterpreterResult, Option<Address>)> {
call_inspectors!([&mut self.tracer], |inspector| {
inspector.create(data, call);
inspector.create(ctx, inputs);
});

(InstructionResult::Continue, None, Gas::new(call.gas_limit), Bytes::new())
None
}

#[inline]
fn create_end(
&mut self,
data: &mut EVMData<'_, DB>,
inputs: &CreateInputs,
status: InstructionResult,
ctx: &mut EvmContext<'_, DB>,
result: InterpreterResult,
address: Option<Address>,
gas: Gas,
retdata: Bytes,
) -> (InstructionResult, Option<Address>, Gas, Bytes) {
) -> (InstructionResult, Option<Address>) {
call_inspectors!([&mut self.tracer], |inspector| {
inspector.create_end(data, inputs, status, address, gas, retdata.clone());
inspector.create_end(ctx, result.clone(), address);
});
(status, address, gas, retdata)
(status, 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
Loading