Skip to content

Commit

Permalink
chore: Patch revm to current head commit (paradigmxyz#5109)
Browse files Browse the repository at this point in the history
Co-authored-by: clabby <[email protected]>
Co-authored-by: rakita <[email protected]>
  • Loading branch information
3 people authored Oct 20, 2023
1 parent fafcabf commit 14f2b90
Show file tree
Hide file tree
Showing 24 changed files with 221 additions and 393 deletions.
231 changes: 128 additions & 103 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ reth-eth-wire = { path = "./crates/net/eth-wire" }
reth-ecies = { path = "./crates/net/ecies" }
reth-tracing = { path = "./crates/tracing" }
# revm
revm = "3.5.0"
revm-primitives = "1.3.0"
revm = { git = "https://github.com/bluealloy/revm", rev = "df44297bc3949dc9e0cec06594c62dd946708b2a" }
revm-primitives = { git = "https://github.com/bluealloy/revm", rev = "df44297bc3949dc9e0cec06594c62dd946708b2a" }

## eth
alloy-primitives = "0.4"
Expand All @@ -130,7 +130,7 @@ boa_gc = "0.17"
## misc
aquamarine = "0.3"
bytes = "1.5"
bitflags = "2.3"
bitflags = "2.4"
clap = "4"
eyre = "0.6"
tracing = "0.1.0"
Expand Down
20 changes: 10 additions & 10 deletions crates/payload/builder/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<'a, DB: DatabaseRef> Database for CachedReadsDbMut<'a, DB> {
let basic = match self.cached.accounts.entry(address) {
Entry::Occupied(entry) => entry.get().info.clone(),
Entry::Vacant(entry) => {
entry.insert(CachedAccount::new(self.db.basic(address)?)).info.clone()
entry.insert(CachedAccount::new(self.db.basic_ref(address)?)).info.clone()
}
};
Ok(basic)
Expand All @@ -71,7 +71,7 @@ impl<'a, DB: DatabaseRef> Database for CachedReadsDbMut<'a, DB> {
fn code_by_hash(&mut self, code_hash: B256) -> Result<Bytecode, Self::Error> {
let code = match self.cached.contracts.entry(code_hash) {
Entry::Occupied(entry) => entry.get().clone(),
Entry::Vacant(entry) => entry.insert(self.db.code_by_hash(code_hash)?).clone(),
Entry::Vacant(entry) => entry.insert(self.db.code_by_hash_ref(code_hash)?).clone(),
};
Ok(code)
}
Expand All @@ -83,17 +83,17 @@ impl<'a, DB: DatabaseRef> Database for CachedReadsDbMut<'a, DB> {
match acc_entry.storage.entry(index) {
Entry::Occupied(entry) => Ok(*entry.get()),
Entry::Vacant(entry) => {
let slot = self.db.storage(address, index)?;
let slot = self.db.storage_ref(address, index)?;
entry.insert(slot);
Ok(slot)
}
}
}
Entry::Vacant(acc_entry) => {
// acc needs to be loaded for us to access slots.
let info = self.db.basic(address)?;
let info = self.db.basic_ref(address)?;
let (account, value) = if info.is_some() {
let value = self.db.storage(address, index)?;
let value = self.db.storage_ref(address, index)?;
let mut account = CachedAccount::new(info);
account.storage.insert(index, value);
(account, value)
Expand All @@ -109,7 +109,7 @@ impl<'a, DB: DatabaseRef> Database for CachedReadsDbMut<'a, DB> {
fn block_hash(&mut self, number: U256) -> Result<B256, Self::Error> {
let code = match self.cached.block_hashes.entry(number) {
Entry::Occupied(entry) => *entry.get(),
Entry::Vacant(entry) => *entry.insert(self.db.block_hash(number)?),
Entry::Vacant(entry) => *entry.insert(self.db.block_hash_ref(number)?),
};
Ok(code)
}
Expand All @@ -127,19 +127,19 @@ pub struct CachedReadsDBRef<'a, DB> {
impl<'a, DB: DatabaseRef> DatabaseRef for CachedReadsDBRef<'a, DB> {
type Error = <DB as DatabaseRef>::Error;

fn basic(&self, address: Address) -> Result<Option<AccountInfo>, Self::Error> {
fn basic_ref(&self, address: Address) -> Result<Option<AccountInfo>, Self::Error> {
self.inner.borrow_mut().basic(address)
}

fn code_by_hash(&self, code_hash: B256) -> Result<Bytecode, Self::Error> {
fn code_by_hash_ref(&self, code_hash: B256) -> Result<Bytecode, Self::Error> {
self.inner.borrow_mut().code_by_hash(code_hash)
}

fn storage(&self, address: Address, index: U256) -> Result<U256, Self::Error> {
fn storage_ref(&self, address: Address, index: U256) -> Result<U256, Self::Error> {
self.inner.borrow_mut().storage(address, index)
}

fn block_hash(&self, number: U256) -> Result<B256, Self::Error> {
fn block_hash_ref(&self, number: U256) -> Result<B256, Self::Error> {
self.inner.borrow_mut().block_hash(number)
}
}
Expand Down
105 changes: 0 additions & 105 deletions crates/primitives/src/contract.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ mod block;
mod chain;
mod compression;
pub mod constants;
pub mod contract;
pub mod eip4844;
mod forkid;
pub mod fs;
Expand Down
10 changes: 2 additions & 8 deletions crates/revm/revm-inspectors/src/access_list.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use reth_primitives::{AccessList, AccessListItem, Address, B256};
use revm::{
interpreter::{opcode, InstructionResult, Interpreter},
interpreter::{opcode, Interpreter},
Database, EVMData, Inspector,
};
use std::collections::{BTreeSet, HashMap, HashSet};
Expand Down Expand Up @@ -61,11 +61,7 @@ impl<DB> Inspector<DB> for AccessListInspector
where
DB: Database,
{
fn step(
&mut self,
interpreter: &mut Interpreter,
_data: &mut EVMData<'_, DB>,
) -> InstructionResult {
fn step(&mut self, interpreter: &mut Interpreter<'_>, _data: &mut EVMData<'_, DB>) {
match interpreter.current_opcode() {
opcode::SLOAD | opcode::SSTORE => {
if let Ok(slot) = interpreter.stack().peek(0) {
Expand Down Expand Up @@ -98,7 +94,5 @@ where
}
_ => (),
}

InstructionResult::Continue
}
}
31 changes: 6 additions & 25 deletions crates/revm/revm-inspectors/src/stack/maybe_owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,18 @@ where
DB: Database,
INSP: Inspector<DB>,
{
fn initialize_interp(
&mut self,
interp: &mut Interpreter,
data: &mut EVMData<'_, DB>,
) -> InstructionResult {
fn initialize_interp(&mut self, interp: &mut Interpreter<'_>, data: &mut EVMData<'_, DB>) {
match self {
MaybeOwnedInspector::Owned(insp) => {
return insp.borrow_mut().initialize_interp(interp, data)
}
MaybeOwnedInspector::Owned(insp) => insp.borrow_mut().initialize_interp(interp, data),
MaybeOwnedInspector::Stacked(_) => {}
}

InstructionResult::Continue
}

fn step(&mut self, interp: &mut Interpreter, data: &mut EVMData<'_, DB>) -> InstructionResult {
fn step(&mut self, interp: &mut Interpreter<'_>, data: &mut EVMData<'_, DB>) {
match self {
MaybeOwnedInspector::Owned(insp) => return insp.borrow_mut().step(interp, data),
MaybeOwnedInspector::Owned(insp) => insp.borrow_mut().step(interp, data),
MaybeOwnedInspector::Stacked(_) => {}
}

InstructionResult::Continue
}

fn log(
Expand All @@ -108,20 +98,11 @@ where
}
}

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 EVMData<'_, DB>) {
match self {
MaybeOwnedInspector::Owned(insp) => {
return insp.borrow_mut().step_end(interp, data, eval)
}
MaybeOwnedInspector::Owned(insp) => insp.borrow_mut().step_end(interp, data),
MaybeOwnedInspector::Stacked(_) => {}
}

InstructionResult::Continue
}

fn call(
Expand Down
46 changes: 6 additions & 40 deletions crates/revm/revm-inspectors/src/stack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,38 +100,16 @@ impl<DB> Inspector<DB> for InspectorStack
where
DB: Database,
{
fn initialize_interp(
&mut self,
interpreter: &mut Interpreter,
data: &mut EVMData<'_, DB>,
) -> InstructionResult {
fn initialize_interp(&mut self, interpreter: &mut Interpreter<'_>, data: &mut EVMData<'_, DB>) {
call_inspectors!(inspector, [&mut self.custom_print_tracer], {
let status = inspector.initialize_interp(interpreter, data);

// Allow inspectors to exit early
if status != InstructionResult::Continue {
return status
}
inspector.initialize_interp(interpreter, data);
});

InstructionResult::Continue
}

fn step(
&mut self,
interpreter: &mut Interpreter,
data: &mut EVMData<'_, DB>,
) -> InstructionResult {
fn step(&mut self, interpreter: &mut Interpreter<'_>, data: &mut EVMData<'_, DB>) {
call_inspectors!(inspector, [&mut self.custom_print_tracer], {
let status = inspector.step(interpreter, data);

// Allow inspectors to exit early
if status != InstructionResult::Continue {
return status
}
inspector.step(interpreter, data);
});

InstructionResult::Continue
}

fn log(
Expand All @@ -146,22 +124,10 @@ where
});
}

fn step_end(
&mut self,
interpreter: &mut Interpreter,
data: &mut EVMData<'_, DB>,
eval: InstructionResult,
) -> InstructionResult {
fn step_end(&mut self, interpreter: &mut Interpreter<'_>, data: &mut EVMData<'_, DB>) {
call_inspectors!(inspector, [&mut self.custom_print_tracer], {
let status = inspector.step_end(interpreter, data, eval);

// Allow inspectors to exit early
if status != InstructionResult::Continue {
return status
}
inspector.step_end(interpreter, data);
});

InstructionResult::Continue
}

fn call(
Expand Down
6 changes: 3 additions & 3 deletions crates/revm/revm-inspectors/src/tracing/builder/geth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl GethTraceBuilder {
if !is_diff {
let mut prestate = PreStateMode::default();
for (addr, changed_acc) in account_diffs {
let db_acc = db.basic(addr)?.unwrap_or_default();
let db_acc = db.basic_ref(addr)?.unwrap_or_default();
let mut pre_state = AccountState::from_account_info(
db_acc.nonce,
db_acc.balance,
Expand All @@ -212,7 +212,7 @@ impl GethTraceBuilder {
let mut state_diff = DiffMode::default();
let mut account_change_kinds = HashMap::with_capacity(account_diffs.len());
for (addr, changed_acc) in account_diffs {
let db_acc = db.basic(addr)?.unwrap_or_default();
let db_acc = db.basic_ref(addr)?.unwrap_or_default();
let db_code = db_acc.code.as_ref();
let db_code_hash = db_acc.code_hash;

Expand All @@ -225,7 +225,7 @@ impl GethTraceBuilder {
if db_code_hash == KECCAK_EMPTY {
None
} else {
db.code_by_hash(db_code_hash).ok().map(|code| code.original_bytes())
db.code_by_hash_ref(db_code_hash).ok().map(|code| code.original_bytes())
}
})
.map(Into::into);
Expand Down
Loading

0 comments on commit 14f2b90

Please sign in to comment.