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

(#2) Alloy Migration: Migrate non-cheatcode inspectors #5770

Merged
merged 15 commits into from Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/anvil/src/eth/backend/mem/mod.rs
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
@@ -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(),
Evalir marked this conversation as resolved.
Show resolved Hide resolved
0,
identified_contracts,
self.sources.clone(),
Expand Down
8 changes: 4 additions & 4 deletions crates/debugger/src/lib.rs
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
@@ -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
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
@@ -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)
}
}