Skip to content

Commit

Permalink
(#2) Alloy Migration: Migrate non-cheatcode inspectors (#5770)
Browse files Browse the repository at this point in the history
* feat: migrate non-cheatcode inspectors

* fix: properly create both create and create2 addresses

* chore: clippy

* (#3) Alloy Migration: migrate fork-adjacent files to alloy primitives (#5771)

* chore: use create2_from_code

* borrow it brah

* chore: use from word

* chore: drop to_be_bytes

* fmt

* chore: use from_word on both palces
  • Loading branch information
Evalir authored Sep 15, 2023
1 parent 9ca8e48 commit ce4984f
Show file tree
Hide file tree
Showing 26 changed files with 209 additions and 207 deletions.
6 changes: 3 additions & 3 deletions crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1144,9 +1144,9 @@ impl Backend {

let mut tracer = AccessListTracer::new(
AccessList(request.access_list.clone().unwrap_or_default()),
from,
to,
self.precompiles(),
h160_to_b160(from),
h160_to_b160(to),
self.precompiles().into_iter().map(h160_to_b160).collect(),
);

let mut evm = revm::EVM::new();
Expand Down
4 changes: 2 additions & 2 deletions crates/debugger/src/debugger.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::Ui;
use foundry_common::{compile::ContractSources, evm::Breakpoints, get_contract_name};
use foundry_evm::{debug::DebugArena, trace::CallTraceDecoder};
use foundry_evm::{debug::DebugArena, trace::CallTraceDecoder, utils::b160_to_h160};
use tracing::trace;

use crate::{TUIExitReason, Tui};
Expand Down Expand Up @@ -35,7 +35,7 @@ impl DebuggerArgs<'_> {
.collect();

let tui = Tui::new(
flattened,
flattened.into_iter().map(|i| (b160_to_h160(i.0), i.1, i.2)).collect(),
0,
identified_contracts,
self.sources.clone(),
Expand Down
8 changes: 4 additions & 4 deletions crates/debugger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,19 +875,19 @@ Line::from(Span::styled("[t]: stack labels | [m]: memory decoding | [shift + j/k
let min_len = format!("{:x}", max_i * 32).len();

// color memory words based on write/read
let mut word = None;
let mut word: Option<usize> = None;
let mut color = None;
if let Instruction::OpCode(op) = debug_steps[current_step].instruction {
let stack_len = debug_steps[current_step].stack.len();
if stack_len > 0 {
let w = debug_steps[current_step].stack[stack_len - 1];
match op {
opcode::MLOAD => {
word = Some(w.as_usize());
word = Some(w.to());
color = Some(Color::Cyan);
}
opcode::MSTORE => {
word = Some(w.as_usize());
word = Some(w.to());
color = Some(Color::Red);
}
_ => {}
Expand All @@ -902,7 +902,7 @@ Line::from(Span::styled("[t]: stack labels | [m]: memory decoding | [shift + j/k
if let Instruction::OpCode(op) = debug_steps[prev_step].instruction {
if op == opcode::MSTORE {
let prev_top = debug_steps[prev_step].stack[stack_len - 1];
word = Some(prev_top.as_usize());
word = Some(prev_top.to());
color = Some(Color::Green);
}
}
Expand Down
6 changes: 4 additions & 2 deletions crates/evm/src/debug.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::{abi::HEVM_ABI, CallKind};
use ethers::types::{Address, U256};
use revm::interpreter::{Memory, OpCode};
use revm::{
interpreter::{Memory, OpCode},
primitives::{Address, U256},
};
use serde::{Deserialize, Serialize};
use std::fmt::Display;

Expand Down
4 changes: 2 additions & 2 deletions crates/evm/src/executor/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ impl Backend {
transaction: B256,
) -> eyre::Result<(U64, Block<Transaction>)> {
let fork = self.inner.get_fork_by_id(id)?;
let tx = fork.db.db.get_transaction(b256_to_h256(transaction))?;
let tx = fork.db.db.get_transaction(transaction)?;

// get the block number we need to fork
if let Some(tx_block) = tx.block_number {
Expand Down Expand Up @@ -1171,7 +1171,7 @@ impl DatabaseExt for Backend {
};

let fork = self.inner.get_fork_by_id_mut(id)?;
let tx = fork.db.db.get_transaction(b256_to_h256(transaction))?;
let tx = fork.db.db.get_transaction(transaction)?;

commit_transaction(tx, env, journaled_state, fork, &fork_id, cheatcodes_inspector)?;

Expand Down
14 changes: 5 additions & 9 deletions crates/evm/src/executor/builder.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
use super::{inspector::InspectorStackBuilder, Executor};
use crate::{
executor::backend::Backend,
utils::{ru256_to_u256, u256_to_ru256},
};
use ethers::types::U256;
use revm::primitives::{Env, SpecId};
use crate::executor::backend::Backend;
use revm::primitives::{Env, SpecId, U256};

/// The builder that allows to configure an evm [`Executor`] which a stack of optional
/// [`revm::Inspector`]s, such as [`Cheatcodes`].
Expand Down Expand Up @@ -70,8 +66,8 @@ impl ExecutorBuilder {
let Self { mut stack, gas_limit, spec_id } = self;
env.cfg.spec_id = spec_id;
stack.block = Some(env.block.clone());
stack.gas_price = Some(ru256_to_u256(env.tx.gas_price));
let gas_limit = gas_limit.unwrap_or(ru256_to_u256(env.block.gas_limit));
Executor::new(db, env, stack.build(), u256_to_ru256(gas_limit))
stack.gas_price = Some(env.tx.gas_price);
let gas_limit = gas_limit.unwrap_or(env.block.gas_limit);
Executor::new(db, env, stack.build(), gas_limit)
}
}
Loading

0 comments on commit ce4984f

Please sign in to comment.