Skip to content
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

feat(evm): Use latest revm main commit #5669

Merged
merged 4 commits into from
Aug 21, 2023
Merged
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
37 changes: 32 additions & 5 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/", branch = "release/v25" }
revm = { git = "https://github.com/bluealloy/revm/", rev = "eb6a9f09e8ac2227bc1c353b698ad9e68a9574b2" }
21 changes: 6 additions & 15 deletions crates/anvil/src/eth/backend/mem/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,17 @@ 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, is_static);
inspector.initialize_interp(interp, data);
});
InstructionResult::Continue
}

#[inline]
fn step(
&mut self,
interp: &mut Interpreter,
data: &mut EVMData<'_, DB>,
is_static: bool,
) -> InstructionResult {
fn step(&mut self, interp: &mut Interpreter, data: &mut EVMData<'_, DB>) -> InstructionResult {
call_inspectors!([&mut self.tracer], |inspector| {
inspector.step(interp, data, is_static);
inspector.step(interp, data);
});
InstructionResult::Continue
}
Expand All @@ -92,11 +86,10 @@ 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, is_static, eval);
inspector.step_end(interp, data, eval);
});
eval
}
Expand All @@ -106,10 +99,9 @@ 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, is_static);
inspector.call(data, call);
});

(InstructionResult::Continue, Gas::new(call.gas_limit), Bytes::new())
Expand All @@ -123,10 +115,9 @@ 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(), is_static);
inspector.call_end(data, inputs, remaining_gas, ret, out.clone());
});
(ret, remaining_gas, out)
}
Expand Down
8 changes: 7 additions & 1 deletion crates/anvil/src/eth/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ 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 @@ -203,7 +206,7 @@ impl From<revm::primitives::InvalidTransaction> for InvalidTransactionError {
})
}
InvalidTransaction::RejectCallerWithCode => InvalidTransactionError::SenderNoEOA,
InvalidTransaction::LackOfFundForGasLimit { .. } => {
InvalidTransaction::LackOfFundForMaxFee { .. } => {
InvalidTransactionError::InsufficientFunds
}
InvalidTransaction::OverflowPaymentInTransaction => {
Expand All @@ -217,6 +220,9 @@ 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).unwrap_or(KECCAK_EMPTY),
code_hash: code.as_ref().map(|code| code.hash_slow()).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: 11 additions & 6 deletions crates/evm/src/executor/fork/cache.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! Cache related abstraction
use crate::executor::backend::snapshot::StateSnapshot;
use hashbrown::HashMap as Map;
use parking_lot::RwLock;
use revm::{
primitives::{Account, AccountInfo, B160, B256, KECCAK_EMPTY, U256},
primitives::{
Account, AccountInfo, AccountStatus, HashMap as Map, B160, B256, KECCAK_EMPTY, U256,
},
DatabaseCommit,
};
use serde::{ser::SerializeMap, Deserialize, Deserializer, Serialize, Serializer};
Expand Down Expand Up @@ -256,13 +257,17 @@ 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_destroyed {
if acc.is_empty() || acc.is_selfdestructed() {
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)
if let Some(code_hash) = acc
.info
.code
.as_ref()
.filter(|code| !code.is_empty())
.map(|code| code.hash_slow())
{
acc.info.code_hash = code_hash;
} else if acc.info.code_hash.is_zero() {
Expand All @@ -271,7 +276,7 @@ impl MemDb {
accounts.insert(add, acc.info);

let acc_storage = storage.entry(add).or_default();
if acc.storage_cleared {
if acc.status.contains(AccountStatus::Created) {
acc_storage.clear();
}
for (index, value) in acc.storage {
Expand Down
1 change: 0 additions & 1 deletion crates/evm/src/executor/inspector/access_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ 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::SHA3 => {
opcode::KECCAK256 => {
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
8 changes: 2 additions & 6 deletions crates/evm/src/executor/inspector/cheatcodes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ impl<DB: DatabaseExt> Inspector<DB> for Cheatcodes {
&mut self,
_: &mut Interpreter,
data: &mut EVMData<'_, DB>,
_: bool,
) -> InstructionResult {
// 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.
Expand All @@ -312,7 +311,6 @@ impl<DB: DatabaseExt> Inspector<DB> for Cheatcodes {
&mut self,
interpreter: &mut Interpreter,
data: &mut EVMData<'_, DB>,
_: bool,
) -> InstructionResult {
self.pc = interpreter.program_counter();

Expand Down Expand Up @@ -513,7 +511,7 @@ impl<DB: DatabaseExt> Inspector<DB> for Cheatcodes {
(CALLCODE, 5, 6, true),
(STATICCALL, 4, 5, true),
(DELEGATECALL, 4, 5, true),
(SHA3, 0, 1, false),
(KECCAK256, 0, 1, false),
(LOG0, 0, 1, false),
(LOG1, 0, 1, false),
(LOG2, 0, 1, false),
Expand Down Expand Up @@ -568,7 +566,6 @@ impl<DB: DatabaseExt> Inspector<DB> for Cheatcodes {
&mut self,
data: &mut EVMData<'_, DB>,
call: &mut CallInputs,
is_static: bool,
) -> (InstructionResult, Gas, bytes::Bytes) {
if call.contract == h160_to_b160(CHEATCODE_ADDRESS) {
let gas = Gas::new(call.gas_limit);
Expand Down Expand Up @@ -677,7 +674,7 @@ impl<DB: DatabaseExt> Inspector<DB> for Cheatcodes {
// because we only need the from, to, value, and data. We can later change this
// into 1559, in the cli package, relatively easily once we
// know the target chain supports EIP-1559.
if !is_static {
if !call.is_static {
if let Err(err) = data
.journaled_state
.load_account(h160_to_b160(broadcast.new_origin), data.db)
Expand Down Expand Up @@ -742,7 +739,6 @@ impl<DB: DatabaseExt> Inspector<DB> for Cheatcodes {
remaining_gas: Gas,
status: InstructionResult,
retdata: bytes::Bytes,
_: bool,
) -> (InstructionResult, Gas, bytes::Bytes) {
if call.contract == h160_to_b160(CHEATCODE_ADDRESS) ||
call.contract == h160_to_b160(HARDHAT_CONSOLE_ADDRESS)
Expand Down
1 change: 0 additions & 1 deletion crates/evm/src/executor/inspector/chisel_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ impl<DB: Database> Inspector<DB> for ChiselState {
&mut self,
interp: &mut Interpreter,
_: &mut revm::EVMData<'_, DB>,
_: bool,
eval: InstructionResult,
) -> InstructionResult {
// If we are at the final pc of the REPL contract execution, set the state.
Expand Down
6 changes: 2 additions & 4 deletions crates/evm/src/executor/inspector/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ impl<DB: Database> Inspector<DB> for CoverageCollector {
&mut self,
interpreter: &mut Interpreter,
_: &mut EVMData<'_, DB>,
_: bool,
) -> InstructionResult {
let hash = b256_to_h256(interpreter.contract.bytecode.hash());
let hash = b256_to_h256(interpreter.contract.bytecode.clone().unlock().hash_slow());
self.maps.entry(hash).or_insert_with(|| {
HitMap::new(Bytes::copy_from_slice(
interpreter.contract.bytecode.original_bytecode_slice(),
Expand All @@ -37,9 +36,8 @@ impl<DB: Database> Inspector<DB> for CoverageCollector {
&mut self,
interpreter: &mut Interpreter,
_: &mut EVMData<'_, DB>,
_: bool,
) -> InstructionResult {
let hash = b256_to_h256(interpreter.contract.bytecode.hash());
let hash = b256_to_h256(interpreter.contract.bytecode.clone().unlock().hash_slow());
self.maps.entry(hash).and_modify(|map| map.hit(interpreter.program_counter()));

InstructionResult::Continue
Expand Down
3 changes: 0 additions & 3 deletions crates/evm/src/executor/inspector/debugger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ impl<DB: DatabaseExt> Inspector<DB> for Debugger {
&mut self,
interpreter: &mut Interpreter,
data: &mut EVMData<'_, DB>,
_: bool,
) -> InstructionResult {
let pc = interpreter.program_counter();
let op = interpreter.contract.bytecode.bytecode()[pc];
Expand Down Expand Up @@ -98,7 +97,6 @@ impl<DB: DatabaseExt> Inspector<DB> for Debugger {
&mut self,
data: &mut EVMData<'_, DB>,
call: &mut CallInputs,
_: bool,
) -> (InstructionResult, Gas, Bytes) {
self.enter(
data.journaled_state.depth() as usize,
Expand Down Expand Up @@ -126,7 +124,6 @@ impl<DB: DatabaseExt> Inspector<DB> for Debugger {
gas: Gas,
status: InstructionResult,
retdata: Bytes,
_: bool,
) -> (InstructionResult, Gas, Bytes) {
self.exit();

Expand Down
Loading