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

fix(evm): revert all revm changes #5610

Merged
merged 2 commits into from
Aug 11, 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: 5 additions & 32 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 @@ -135,4 +135,4 @@ solang-parser = "=0.3.1"
#ethers-solc = { path = "../ethers-rs/ethers-solc" }

[patch.crates-io]
revm = { git = "https://github.com/bluealloy/revm/", rev = "bc4d203bf0b5f5c01868477c8e98d3abd6bb92ab" }
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 @@ -61,21 +61,27 @@ impl<DB: Database> revm::Inspector<DB> for Inspector {
&mut self,
interp: &mut Interpreter,
data: &mut EVMData<'_, DB>,
is_static: bool,
) -> InstructionResult {
call_inspectors!(
inspector,
[&mut self.gas.as_deref().map(|gas| gas.borrow_mut()), &mut self.tracer],
{ inspector.initialize_interp(interp, data) }
{ inspector.initialize_interp(interp, data, is_static) }
);
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>,
is_static: bool,
) -> InstructionResult {
call_inspectors!(
inspector,
[&mut self.gas.as_deref().map(|gas| gas.borrow_mut()), &mut self.tracer],
{
inspector.step(interp, data);
inspector.step(interp, data, is_static);
}
);
InstructionResult::Continue
Expand Down Expand Up @@ -105,13 +111,14 @@ 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!(
inspector,
[&mut self.gas.as_deref().map(|gas| gas.borrow_mut()), &mut self.tracer],
{
inspector.step_end(interp, data, eval);
inspector.step_end(interp, data, is_static, eval);
}
);
eval
Expand All @@ -121,6 +128,7 @@ 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!(
inspector,
Expand All @@ -130,7 +138,7 @@ impl<DB: Database> revm::Inspector<DB> for Inspector {
Some(&mut self.log_collector)
],
{
inspector.call(data, call);
inspector.call(data, call, is_static);
}
);

Expand All @@ -144,12 +152,13 @@ impl<DB: Database> revm::Inspector<DB> for Inspector {
remaining_gas: Gas,
ret: InstructionResult,
out: Bytes,
is_static: bool,
) -> (InstructionResult, Gas, Bytes) {
call_inspectors!(
inspector,
[&mut self.gas.as_deref().map(|gas| gas.borrow_mut()), &mut self.tracer],
{
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 @@ -179,9 +179,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 @@ -204,7 +201,7 @@ impl From<revm::primitives::InvalidTransaction> for InvalidTransactionError {
})
}
InvalidTransaction::RejectCallerWithCode => InvalidTransactionError::SenderNoEOA,
InvalidTransaction::LackOfFundForMaxFee { .. } => {
InvalidTransaction::LackOfFundForGasLimit { .. } => {
InvalidTransactionError::InsufficientFunds
}
InvalidTransaction::OverflowPaymentInTransaction => {
Expand All @@ -218,9 +215,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 @@ -251,17 +250,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 @@ -270,7 +265,7 @@ impl MemDb {
accounts.insert(add, acc.info);

let acc_storage = storage.entry(add).or_default();
if acc.status.contains(AccountStatus::Created) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this should be OK, it seems that the commit function might need some tweaking, as it seems it wasn't recording the accounts as it should. We tried matching revm's commit fn but the issues still persisted.

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 @@ -58,6 +58,7 @@ where
&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
8 changes: 6 additions & 2 deletions crates/evm/src/executor/inspector/cheatcodes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ where
&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 @@ -320,6 +321,7 @@ where
&mut self,
interpreter: &mut Interpreter,
data: &mut EVMData<'_, DB>,
_: bool,
) -> InstructionResult {
self.pc = interpreter.program_counter();

Expand Down Expand Up @@ -520,7 +522,7 @@ where
(CALLCODE, 5, 6, true),
(STATICCALL, 4, 5, true),
(DELEGATECALL, 4, 5, true),
(KECCAK256, 0, 1, false),
(SHA3, 0, 1, false),
(LOG0, 0, 1, false),
(LOG1, 0, 1, false),
(LOG2, 0, 1, false),
Expand Down Expand Up @@ -575,6 +577,7 @@ where
&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 @@ -683,7 +686,7 @@ where
// 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 !call.is_static {
if !is_static {
if let Err(err) = data
.journaled_state
.load_account(h160_to_b160(broadcast.new_origin), data.db)
Expand Down Expand Up @@ -748,6 +751,7 @@ where
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: 1 addition & 0 deletions crates/evm/src/executor/inspector/chisel_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ where
&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: 4 additions & 2 deletions crates/evm/src/executor/inspector/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ where
&mut self,
interpreter: &mut Interpreter,
_: &mut EVMData<'_, DB>,
_: bool,
) -> InstructionResult {
let hash = b256_to_h256(interpreter.contract.bytecode.clone().unlock().hash_slow());
let hash = b256_to_h256(interpreter.contract.bytecode.hash());
self.maps.entry(hash).or_insert_with(|| {
HitMap::new(Bytes::copy_from_slice(
interpreter.contract.bytecode.original_bytecode_slice(),
Expand All @@ -37,8 +38,9 @@ where
&mut self,
interpreter: &mut Interpreter,
_: &mut EVMData<'_, DB>,
_: bool,
) -> InstructionResult {
let hash = b256_to_h256(interpreter.contract.bytecode.clone().unlock().hash_slow());
let hash = b256_to_h256(interpreter.contract.bytecode.hash());
self.maps.entry(hash).and_modify(|map| map.hit(interpreter.program_counter()));

InstructionResult::Continue
Expand Down
Loading