Skip to content

Commit

Permalink
feat(evm): Use latest revm main commit (foundry-rs#5669)
Browse files Browse the repository at this point in the history
* Revert "fix(`evm`): revert all revm changes (foundry-rs#5610)"

This reverts commit a0a31c3.

* upgrade revm

* fmt
  • Loading branch information
Evalir authored and mikelodder7 committed Sep 12, 2023
1 parent be2a09e commit 2cc4ed7
Show file tree
Hide file tree
Showing 19 changed files with 90 additions and 85 deletions.
29 changes: 28 additions & 1 deletion Cargo.lock

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

23 changes: 20 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resolver = "2"
[workspace.package]
version = "0.2.0"
edition = "2021"
rust-version = "1.71"
rust-version = "1.72"
authors = ["Foundry Contributors"]
license = "MIT OR Apache-2.0"
homepage = "https://github.com/foundry-rs/foundry"
Expand Down Expand Up @@ -42,13 +42,22 @@ scrypt.opt-level = 3
# forking
axum.opt-level = 3

# Optimized release profile
[profile.release]
opt-level = "s"
lto = "fat"
strip = true
panic = "abort"
codegen-units = 1

# Like release, but with full debug symbols and with stack unwinds. Useful for e.g. `perf`.
[profile.debug-fast]
inherits = "release"
debug = "full"
strip = "none"
panic = "unwind"
incremental = false

[profile.release.package]
# Optimize all non-workspace packages for speed
"*".opt-level = 3
Expand Down Expand Up @@ -123,7 +132,11 @@ foundry-evm = { path = "crates/evm" }
foundry-macros = { path = "crates/macros" }
foundry-test-utils = { path = "crates/test-utils" }
foundry-utils = { path = "crates/utils" }
ui = { path = "crates/ui" }
foundry-debugger = { path = "crates/debugger" }

## revm
revm = { version = "3", default-features = false }
revm-primitives = { version = "1", default-features = false }

ethers = { git = "https://github.com/gakonst/ethers-rs", default-features = false }
ethers-addressbook = { git = "https://github.com/gakonst/ethers-rs", default-features = false }
Expand All @@ -139,7 +152,8 @@ ethers-solc = { git = "https://github.com/gakonst/ethers-rs", default-features =
chrono = { version = "0.4", default-features = false, features = ["clock", "std"] }
hex = { package = "const-hex", version = "1.6", features = ["hex"] }
itertools = "0.11"
solang-parser = "=0.3.1"
solang-parser = "=0.3.2"
tikv-jemallocator = "0.5.4"

#[patch."https://github.com/gakonst/ethers-rs"]
#ethers = { path = "../ethers-rs/ethers" }
Expand All @@ -154,5 +168,8 @@ solang-parser = "=0.3.1"
#ethers-solc = { path = "../ethers-rs/ethers-solc" }

[patch.crates-io]
revm-interpreter = { git = "https://github.com/bluealloy/revm/", rev = "7eacc3a728b8a9cf3c15db609753e5d9f69e08ce" }
revm-precompile = { git = "https://github.com/bluealloy/revm/", rev = "7eacc3a728b8a9cf3c15db609753e5d9f69e08ce" }
revm-primitives = { git = "https://github.com/bluealloy/revm/", rev = "7eacc3a728b8a9cf3c15db609753e5d9f69e08ce" }
# revm = { git = "https://github.com/bluealloy/revm/", branch = "release/v25" }
revm = { path = "../revm/crates/revm" }
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
Loading

0 comments on commit 2cc4ed7

Please sign in to comment.