Skip to content

Commit

Permalink
chore: bump revm (#719)
Browse files Browse the repository at this point in the history
Based on foundry-rs/foundry#8305 to bump REVM 12.

Co-authored-by: Arsenii Kulikov <[email protected]>
Co-authored-by: rakita <[email protected]>
  • Loading branch information
3 people authored Oct 29, 2024
1 parent 86c3cf7 commit bbb9147
Show file tree
Hide file tree
Showing 13 changed files with 544 additions and 499 deletions.
880 changes: 456 additions & 424 deletions Cargo.lock

Large diffs are not rendered by default.

66 changes: 33 additions & 33 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -177,48 +177,48 @@ foundry-evm-traces = { path = "crates/foundry/evm/traces" }
# solc & compilation utilities
foundry-block-explorers = { version = "=0.2.7", default-features = false }
foundry-compilers = { version = "0.4.3", features = ["full"] }
foundry-fork-db = "=0.1.0"
foundry-fork-db = "=0.2.1"

## revm
# no default features to avoid c-kzg
revm = { version = "10.0.0", default-features = false }
revm-primitives = { version = "5.0.0", default-features = false }
revm-inspectors = { version = "=0.3.0", features = ["serde"] }
revm = { version = "=13.0.0", default-features = false }
revm-primitives = { version = "=8.0.0", default-features = false }
revm-inspectors = { version = "=0.5.6", features = ["serde"] }

## ethers
ethers-contract-abigen = { version = "2.0.14", default-features = false }

## alloy
alloy-consensus = { version = "0.1.2", default-features = false }
alloy-contract = { version = "0.1.2", default-features = false }
alloy-eips = { version = "0.1.2", default-features = false }
alloy-genesis = { version = "0.1.2", default-features = false }
alloy-json-rpc = { version = "0.1.2", default-features = false }
alloy-network = { version = "0.1.2", default-features = false }
alloy-node-bindings = { version = "0.1.2", default-features = false }
alloy-provider = { version = "0.1.2", default-features = false }
alloy-pubsub = { version = "0.1.2", default-features = false }
alloy-rpc-client = { version = "0.1.2", default-features = false }
alloy-rpc-types = { version = "0.1.2", default-features = false }
alloy-serde = { version = "0.1.2", default-features = false }
alloy-signer = { version = "0.1.2", default-features = false }
alloy-signer-aws = { version = "0.1.2", default-features = false }
alloy-signer-gcp = { version = "0.1.2", default-features = false }
alloy-signer-ledger = { version = "0.1.2", default-features = false }
alloy-signer-local = { version = "0.1.2", default-features = false }
alloy-signer-trezor = { version = "0.1.2", default-features = false }
alloy-transport = { version = "0.1.2", default-features = false }
alloy-transport-http = { version = "0.1.2", default-features = false }
alloy-transport-ipc = { version = "0.1.2", default-features = false }
alloy-transport-ws = { version = "0.1.2", default-features = false }
alloy-consensus = { version = "=0.2.0", default-features = false }
alloy-contract = { version = "=0.2.0", default-features = false }
alloy-eips = { version = "=0.2.0", default-features = false }
alloy-genesis = { version = "=0.2.0", default-features = false }
alloy-json-rpc = { version = "=0.2.0", default-features = false }
alloy-network = { version = "=0.2.0", default-features = false }
alloy-node-bindings = { version = "=0.2.0", default-features = false }
alloy-provider = { version = "=0.2.0", default-features = false }
alloy-pubsub = { version = "=0.2.0", default-features = false }
alloy-rpc-client = { version = "=0.2.0", default-features = false }
alloy-rpc-types = { version = "=0.2.0", default-features = false }
alloy-serde = { version = "=0.2.0", default-features = false }
alloy-signer = { version = "=0.2.0", default-features = false }
alloy-signer-aws = { version = "=0.2.0", default-features = false }
alloy-signer-gcp = { version = "=0.2.0", default-features = false }
alloy-signer-ledger = { version = "=0.2.0", default-features = false }
alloy-signer-local = { version = "=0.2.0", default-features = false }
alloy-signer-trezor = { version = "=0.2.0", default-features = false }
alloy-transport = { version = "=0.2.0", default-features = false }
alloy-transport-http = { version = "=0.2.0", default-features = false }
alloy-transport-ipc = { version = "=0.2.0", default-features = false }
alloy-transport-ws = { version = "=0.2.0", default-features = false }

alloy-dyn-abi = "0.7.3"
alloy-json-abi = "0.7.3"
alloy-primitives = { version = "0.7.3", features = ["getrandom", "rand"] }
alloy-sol-macro-expander = "0.7.3"
alloy-sol-macro-input = "0.7.3"
alloy-sol-types = "0.7.3"
syn-solidity = "0.7.3"
alloy-dyn-abi = "=0.7.7"
alloy-json-abi = "=0.7.7"
alloy-primitives = { version = "=0.7.7", features = ["getrandom", "rand"] }
alloy-sol-macro-expander = "=0.7.7"
alloy-sol-macro-input = "=0.7.7"
alloy-sol-types = "=0.7.7"
syn-solidity = "=0.7.7"

alloy-chains = "0.1"
alloy-rlp = "0.3.3"
Expand Down
12 changes: 8 additions & 4 deletions crates/foundry/cheatcodes/src/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ impl<DB: DatabaseExt> Inspector<DB> for Cheatcodes {
}
}

fn log(&mut self, _context: &mut EvmContext<DB>, log: &Log) {
fn log(&mut self, _interpreter: &mut Interpreter, _context: &mut EvmContext<DB>, log: &Log) {
if !self.expected_emits.is_empty() {
expect::handle_expect_emit(self, log);
}
Expand Down Expand Up @@ -926,10 +926,14 @@ impl<DB: DatabaseExt> Inspector<DB> for Cheatcodes {
old_balance = U256::ZERO;
}
let kind = match call.scheme {
CallScheme::Call => crate::Vm::AccountAccessKind::Call,
CallScheme::Call | CallScheme::ExtCall => crate::Vm::AccountAccessKind::Call,
CallScheme::CallCode => crate::Vm::AccountAccessKind::CallCode,
CallScheme::DelegateCall => crate::Vm::AccountAccessKind::DelegateCall,
CallScheme::StaticCall => crate::Vm::AccountAccessKind::StaticCall,
CallScheme::DelegateCall | CallScheme::ExtDelegateCall => {
crate::Vm::AccountAccessKind::DelegateCall
}
CallScheme::StaticCall | CallScheme::ExtStaticCall => {
crate::Vm::AccountAccessKind::StaticCall
}
};
// Record this call by pushing it to a new pending vector; all subsequent calls
// at that depth will be pushed to the same vector. When the call
Expand Down
8 changes: 7 additions & 1 deletion crates/foundry/evm/core/src/abi/fmt/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ impl UIfmt for AnyTransactionReceipt {
},
blob_gas_price,
blob_gas_used,
authorization_list,
},
other,
} = self;
Expand All @@ -209,7 +210,8 @@ transactionHash {}
transactionIndex {}
type {}
blobGasPrice {}
blobGasUsed {}",
blobGasUsed {}
authorizationList {}",
block_hash.pretty(),
block_number.pretty(),
contract_address.pretty(),
Expand All @@ -226,6 +228,10 @@ blobGasUsed {}",
transaction_type,
blob_gas_price.pretty(),
blob_gas_used.pretty(),
authorization_list
.as_ref()
.map(|l| serde_json::to_string(&l).unwrap())
.unwrap_or_default(),
);

if let Some(to) = to {
Expand Down
4 changes: 2 additions & 2 deletions crates/foundry/evm/core/src/backend/cow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ impl<'a> DatabaseRef for CowBackend<'a> {
DatabaseRef::storage_ref(self.backend.as_ref(), address, index)
}

fn block_hash_ref(&self, number: U256) -> Result<B256, Self::Error> {
fn block_hash_ref(&self, number: u64) -> Result<B256, Self::Error> {
DatabaseRef::block_hash_ref(self.backend.as_ref(), number)
}
}
Expand All @@ -302,7 +302,7 @@ impl<'a> Database for CowBackend<'a> {
DatabaseRef::storage_ref(self, address, index)
}

fn block_hash(&mut self, number: U256) -> Result<B256, Self::Error> {
fn block_hash(&mut self, number: u64) -> Result<B256, Self::Error> {
DatabaseRef::block_hash_ref(self, number)
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/foundry/evm/core/src/backend/in_memory_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl DatabaseRef for MemDb {
DatabaseRef::storage_ref(&self.inner, address, index)
}

fn block_hash_ref(&self, number: U256) -> Result<B256, Self::Error> {
fn block_hash_ref(&self, number: u64) -> Result<B256, Self::Error> {
DatabaseRef::block_hash_ref(&self.inner, number)
}
}
Expand All @@ -68,7 +68,7 @@ impl Database for MemDb {
Database::storage(&mut self.inner, address, index)
}

fn block_hash(&mut self, number: U256) -> Result<B256, Self::Error> {
fn block_hash(&mut self, number: u64) -> Result<B256, Self::Error> {
Database::block_hash(&mut self.inner, number)
}
}
Expand Down Expand Up @@ -118,7 +118,7 @@ impl DatabaseRef for EmptyDBWrapper {
Ok(self.0.storage_ref(address, index)?)
}

fn block_hash_ref(&self, number: U256) -> Result<B256, Self::Error> {
fn block_hash_ref(&self, number: u64) -> Result<B256, Self::Error> {
Ok(self.0.block_hash_ref(number)?)
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/foundry/evm/core/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,7 @@ impl DatabaseRef for Backend {
}
}

fn block_hash_ref(&self, number: U256) -> Result<B256, Self::Error> {
fn block_hash_ref(&self, number: u64) -> Result<B256, Self::Error> {
if let Some(db) = self.active_fork_db() {
db.block_hash_ref(number)
} else {
Expand Down Expand Up @@ -1555,7 +1555,7 @@ impl Database for Backend {
}
}

fn block_hash(&mut self, number: U256) -> Result<B256, Self::Error> {
fn block_hash(&mut self, number: u64) -> Result<B256, Self::Error> {
if let Some(db) = self.active_fork_db_mut() {
db.block_hash(number)
} else {
Expand Down
8 changes: 4 additions & 4 deletions crates/foundry/evm/core/src/fork/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl Database for ForkedDatabase {
Database::storage(&mut self.cache_db, address, index)
}

fn block_hash(&mut self, number: U256) -> Result<B256, Self::Error> {
fn block_hash(&mut self, number: u64) -> Result<B256, Self::Error> {
Database::block_hash(&mut self.cache_db, number)
}
}
Expand All @@ -203,7 +203,7 @@ impl DatabaseRef for ForkedDatabase {
DatabaseRef::storage_ref(&self.cache_db, address, index)
}

fn block_hash_ref(&self, number: U256) -> Result<B256, Self::Error> {
fn block_hash_ref(&self, number: u64) -> Result<B256, Self::Error> {
self.cache_db.block_hash_ref(number)
}
}
Expand Down Expand Up @@ -274,8 +274,8 @@ impl DatabaseRef for ForkDbSnapshot {
}
}

fn block_hash_ref(&self, number: U256) -> Result<B256, Self::Error> {
match self.snapshot.block_hashes.get(&number).copied() {
fn block_hash_ref(&self, number: u64) -> Result<B256, Self::Error> {
match self.snapshot.block_hashes.get(&U256::from(number)).copied() {
None => self.local.block_hash_ref(number),
Some(block_hash) => Ok(block_hash),
}
Expand Down
3 changes: 3 additions & 0 deletions crates/foundry/evm/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ pub trait InspectorExt<DB: Database>: Inspector<DB> {
) -> bool {
false
}

// Simulates `console.log` invocation.
fn console_log(&mut self, _input: String) {}
}

impl<DB: Database> InspectorExt<DB> for NoOpInspector {}
Expand Down
9 changes: 0 additions & 9 deletions crates/foundry/evm/core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,6 @@ pub fn configure_tx_env(env: &mut revm::primitives::Env, tx: &Transaction) {
.unwrap_or_default()
.0
.into_iter()
.map(|item| {
(
item.address,
item.storage_keys
.into_iter()
.map(|key| alloy_primitives::U256::from_be_bytes(key.0))
.collect(),
)
})
.collect();
env.tx.value = tx.value.to();
env.tx.data = alloy_primitives::Bytes(tx.input.0.clone());
Expand Down
21 changes: 8 additions & 13 deletions crates/foundry/evm/evm/src/executors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,18 +815,6 @@ impl std::ops::DerefMut for CallResult {
}
}

/// Calculates the initial gas stipend for a transaction
fn calc_stipend(calldata: &[u8], spec: SpecId) -> u64 {
let non_zero_data_cost = if SpecId::enabled(spec, SpecId::ISTANBUL) {
16
} else {
68
};
calldata.iter().fold(21000, |sum, byte| {
sum + if *byte == 0 { 4 } else { non_zero_data_cost }
})
}

/// Converts the data aggregated in the `inspector` and `call` to a
/// `RawCallResult`
fn convert_executed_result(
Expand Down Expand Up @@ -858,7 +846,14 @@ fn convert_executed_result(
}
ExecutionResult::Halt { reason, gas_used } => (reason.into(), 0_u64, gas_used, None),
};
let stipend = calc_stipend(&env.tx.data, env.handler_cfg.spec_id);

let stipend = revm::interpreter::gas::validate_initial_tx_gas(
env.spec_id(),
&env.tx.data,
env.tx.transact_to.is_create(),
&env.tx.access_list,
0,
);

let result = match &out {
Some(Output::Call(data)) => data.clone(),
Expand Down
17 changes: 15 additions & 2 deletions crates/foundry/evm/evm/src/inspectors/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ use foundry_evm_core::{
patch_hh_console_selector, Console, HardhatConsole,
},
constants::HARDHAT_CONSOLE_ADDRESS,
InspectorExt,
};
use revm::{
interpreter::{CallInputs, CallOutcome, Gas, InstructionResult, InterpreterResult},
interpreter::{
CallInputs, CallOutcome, Gas, InstructionResult, Interpreter, InterpreterResult,
},
Database, EvmContext, Inspector,
};

Expand Down Expand Up @@ -43,7 +46,7 @@ impl LogCollector {
}

impl<DB: Database> Inspector<DB> for LogCollector {
fn log(&mut self, _context: &mut EvmContext<DB>, log: &Log) {
fn log(&mut self, _interp: &mut Interpreter, _context: &mut EvmContext<DB>, log: &Log) {
self.logs.push(log.clone());
}

Expand Down Expand Up @@ -71,6 +74,16 @@ impl<DB: Database> Inspector<DB> for LogCollector {
}
}

impl<DB: Database> InspectorExt<DB> for LogCollector {
fn console_log(&mut self, input: String) {
self.logs.push(Log::new_unchecked(
HARDHAT_CONSOLE_ADDRESS,
vec![Console::log::SIGNATURE_HASH],
input.abi_encode().into(),
));
}
}

/// Converts a call to Hardhat's `console.log` to a `DSTest` `log(string)`
/// event.
fn convert_hh_log_to_event(call: HardhatConsole::HardhatConsoleCalls) -> Log {
Expand Down
5 changes: 3 additions & 2 deletions crates/foundry/evm/evm/src/inspectors/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ impl InspectorStack {
record_opcodes_filter: None,
exclude_precompile_calls: false,
record_logs: true,
record_immediate_bytes: false,
})
});
}
Expand Down Expand Up @@ -658,7 +659,7 @@ impl<DB: DatabaseExt + DatabaseCommit> Inspector<&mut DB> for InspectorStack {
);
}

fn log(&mut self, ecx: &mut EvmContext<&mut DB>, log: &Log) {
fn log(&mut self, interpreter: &mut Interpreter, ecx: &mut EvmContext<&mut DB>, log: &Log) {
call_inspectors_adjust_depth!(
#[no_ret]
[
Expand All @@ -667,7 +668,7 @@ impl<DB: DatabaseExt + DatabaseCommit> Inspector<&mut DB> for InspectorStack {
&mut self.cheatcodes,
&mut self.printer
],
|inspector| inspector.log(ecx, log),
|inspector| inspector.log(interpreter, ecx, log),
self,
ecx
);
Expand Down

0 comments on commit bbb9147

Please sign in to comment.