Skip to content

Commit

Permalink
Revert "feat(evm): Use latest revm main commit (foundry-rs#5669)" (fo…
Browse files Browse the repository at this point in the history
…undry-rs#5695)

* Revert "feat(`evm`): Use latest `revm` main commit (foundry-rs#5669)"

This reverts commit efedf1f.

* test: add basic coverage test

* bump
  • Loading branch information
DaniPopes authored Aug 22, 2023
1 parent 6676e81 commit f8a07c3
Show file tree
Hide file tree
Showing 21 changed files with 106 additions and 87 deletions.
61 changes: 17 additions & 44 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,4 @@ solang-parser = "=0.3.1"
#ethers-solc = { path = "../ethers-rs/ethers-solc" }

[patch.crates-io]
revm = { git = "https://github.com/bluealloy/revm/", rev = "eb6a9f09e8ac2227bc1c353b698ad9e68a9574b2" }
revm = { git = "https://github.com/bluealloy/revm/", branch = "release/v25" }
21 changes: 15 additions & 6 deletions crates/anvil/src/eth/backend/mem/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,23 @@ impl<DB: Database> revm::Inspector<DB> for Inspector {
&mut self,
interp: &mut Interpreter,
data: &mut EVMData<'_, DB>,
is_static: bool,
) -> InstructionResult {
call_inspectors!([&mut self.tracer], |inspector| {
inspector.initialize_interp(interp, data);
inspector.initialize_interp(interp, data, is_static);
});
InstructionResult::Continue
}

#[inline]
fn step(&mut self, interp: &mut Interpreter, data: &mut EVMData<'_, DB>) -> InstructionResult {
fn step(
&mut self,
interp: &mut Interpreter,
data: &mut EVMData<'_, DB>,
is_static: bool,
) -> InstructionResult {
call_inspectors!([&mut self.tracer], |inspector| {
inspector.step(interp, data);
inspector.step(interp, data, is_static);
});
InstructionResult::Continue
}
Expand All @@ -86,10 +92,11 @@ impl<DB: Database> revm::Inspector<DB> for Inspector {
&mut self,
interp: &mut Interpreter,
data: &mut EVMData<'_, DB>,
is_static: bool,
eval: InstructionResult,
) -> InstructionResult {
call_inspectors!([&mut self.tracer], |inspector| {
inspector.step_end(interp, data, eval);
inspector.step_end(interp, data, is_static, eval);
});
eval
}
Expand All @@ -99,9 +106,10 @@ impl<DB: Database> revm::Inspector<DB> for Inspector {
&mut self,
data: &mut EVMData<'_, DB>,
call: &mut CallInputs,
is_static: bool,
) -> (InstructionResult, Gas, Bytes) {
call_inspectors!([&mut self.tracer, Some(&mut self.log_collector)], |inspector| {
inspector.call(data, call);
inspector.call(data, call, is_static);
});

(InstructionResult::Continue, Gas::new(call.gas_limit), Bytes::new())
Expand All @@ -115,9 +123,10 @@ impl<DB: Database> revm::Inspector<DB> for Inspector {
remaining_gas: Gas,
ret: InstructionResult,
out: Bytes,
is_static: bool,
) -> (InstructionResult, Gas, Bytes) {
call_inspectors!([&mut self.tracer], |inspector| {
inspector.call_end(data, inputs, remaining_gas, ret, out.clone());
inspector.call_end(data, inputs, remaining_gas, ret, out.clone(), is_static);
});
(ret, remaining_gas, out)
}
Expand Down
8 changes: 1 addition & 7 deletions crates/anvil/src/eth/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,6 @@ pub enum InvalidTransactionError {
/// Thrown when a legacy tx was signed for a different chain
#[error("Incompatible EIP-155 transaction, signed for another chain")]
IncompatibleEIP155,
/// Thrown when an access list is used before the berlin hard fork.
#[error("Access lists are not supported before the Berlin hardfork")]
AccessListNotSupported,
}

impl From<revm::primitives::InvalidTransaction> for InvalidTransactionError {
Expand All @@ -206,7 +203,7 @@ impl From<revm::primitives::InvalidTransaction> for InvalidTransactionError {
})
}
InvalidTransaction::RejectCallerWithCode => InvalidTransactionError::SenderNoEOA,
InvalidTransaction::LackOfFundForMaxFee { .. } => {
InvalidTransaction::LackOfFundForGasLimit { .. } => {
InvalidTransactionError::InsufficientFunds
}
InvalidTransaction::OverflowPaymentInTransaction => {
Expand All @@ -220,9 +217,6 @@ impl From<revm::primitives::InvalidTransaction> for InvalidTransactionError {
}
InvalidTransaction::NonceTooHigh { .. } => InvalidTransactionError::NonceTooHigh,
InvalidTransaction::NonceTooLow { .. } => InvalidTransactionError::NonceTooLow,
InvalidTransaction::AccessListNotSupported => {
InvalidTransactionError::AccessListNotSupported
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl From<GenesisAccount> for AccountInfo {
AccountInfo {
balance: balance.into(),
nonce: nonce.unwrap_or_default(),
code_hash: code.as_ref().map(|code| code.hash_slow()).unwrap_or(KECCAK_EMPTY),
code_hash: code.as_ref().map(|code| code.hash).unwrap_or(KECCAK_EMPTY),
code,
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/src/executor/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ impl DatabaseExt for Backend {
// prevent issues in the new journalstate, e.g. assumptions that accounts are loaded
// if the account is not touched, we reload it, if it's touched we clone it
for (addr, acc) in journaled_state.state.iter() {
if acc.is_touched() {
if acc.is_touched {
merge_journaled_state_data(
b160_to_h160(*addr),
journaled_state,
Expand Down
17 changes: 6 additions & 11 deletions crates/evm/src/executor/fork/cache.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//! Cache related abstraction
use crate::executor::backend::snapshot::StateSnapshot;
use hashbrown::HashMap as Map;
use parking_lot::RwLock;
use revm::{
primitives::{
Account, AccountInfo, AccountStatus, HashMap as Map, B160, B256, KECCAK_EMPTY, U256,
},
primitives::{Account, AccountInfo, B160, B256, KECCAK_EMPTY, U256},
DatabaseCommit,
};
use serde::{ser::SerializeMap, Deserialize, Deserializer, Serialize, Serializer};
Expand Down Expand Up @@ -257,17 +256,13 @@ impl MemDb {
let mut storage = self.storage.write();
let mut accounts = self.accounts.write();
for (add, mut acc) in changes {
if acc.is_empty() || acc.is_selfdestructed() {
if acc.is_empty() || acc.is_destroyed {
accounts.remove(&add);
storage.remove(&add);
} else {
// insert account
if let Some(code_hash) = acc
.info
.code
.as_ref()
.filter(|code| !code.is_empty())
.map(|code| code.hash_slow())
if let Some(code_hash) =
acc.info.code.as_ref().filter(|code| !code.is_empty()).map(|code| code.hash)
{
acc.info.code_hash = code_hash;
} else if acc.info.code_hash.is_zero() {
Expand All @@ -276,7 +271,7 @@ impl MemDb {
accounts.insert(add, acc.info);

let acc_storage = storage.entry(add).or_default();
if acc.status.contains(AccountStatus::Created) {
if acc.storage_cleared {
acc_storage.clear();
}
for (index, value) in acc.storage {
Expand Down
1 change: 1 addition & 0 deletions crates/evm/src/executor/inspector/access_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl<DB: Database> Inspector<DB> for AccessListTracer {
&mut self,
interpreter: &mut Interpreter,
_data: &mut EVMData<'_, DB>,
_is_static: bool,
) -> InstructionResult {
let pc = interpreter.program_counter();
let op = interpreter.contract.bytecode.bytecode()[pc];
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/src/executor/inspector/cheatcodes/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub fn on_evm_step<DB: Database>(
_data: &mut EVMData<'_, DB>,
) {
match interpreter.contract.bytecode.bytecode()[interpreter.program_counter()] {
opcode::KECCAK256 => {
opcode::SHA3 => {
if interpreter.stack.peek(1) == Ok(revm::primitives::U256::from(0x40)) {
let address = interpreter.contract.address;
let offset = interpreter.stack.peek(0).expect("stack size > 1").to::<usize>();
Expand Down
Loading

0 comments on commit f8a07c3

Please sign in to comment.