Skip to content

Commit 37b1114

Browse files
committed
Merge branch 'master' into no-fuzz-proptest
2 parents c70c6d7 + cb8f3bf commit 37b1114

File tree

8 files changed

+50
-74
lines changed

8 files changed

+50
-74
lines changed

crates/anvil/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ foundry-evm.workspace = true
3030
foundry-evm-core.workspace = true
3131

3232
# alloy
33-
alloy-evm.workspace = true
33+
alloy-evm = { workspace = true, features = ["call-util"] }
3434
alloy-op-evm.workspace = true
3535
alloy-primitives = { workspace = true, features = ["serde"] }
3636
alloy-consensus = { workspace = true, features = ["k256", "kzg"] }

crates/anvil/src/config.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ use tokio::sync::RwLock as TokioRwLock;
6565
use yansi::Paint;
6666

6767
pub use foundry_common::version::SHORT_VERSION as VERSION_MESSAGE;
68+
use foundry_evm::traces::{CallTraceDecoderBuilder, identifier::SignaturesIdentifier};
6869

6970
/// Default port the rpc will open
7071
pub const NODE_PORT: u16 = 8545;
@@ -1102,6 +1103,15 @@ impl NodeConfig {
11021103
genesis_init: self.genesis.clone(),
11031104
};
11041105

1106+
let mut decoder_builder = CallTraceDecoderBuilder::new();
1107+
if self.print_traces {
1108+
// if traces should get printed we configure the decoder with the signatures cache
1109+
if let Ok(identifier) = SignaturesIdentifier::new(false) {
1110+
debug!(target: "node", "using signature identifier");
1111+
decoder_builder = decoder_builder.with_signature_identifier(identifier);
1112+
}
1113+
}
1114+
11051115
// only memory based backend for now
11061116
let backend = mem::Backend::with_genesis(
11071117
db,
@@ -1112,6 +1122,7 @@ impl NodeConfig {
11121122
self.enable_steps_tracing,
11131123
self.print_logs,
11141124
self.print_traces,
1125+
Arc::new(decoder_builder.build()),
11151126
self.odyssey,
11161127
self.prune_history,
11171128
self.max_persisted_states,

crates/anvil/src/eth/api.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use alloy_consensus::{
3535
};
3636
use alloy_dyn_abi::TypedData;
3737
use alloy_eips::eip2718::Encodable2718;
38+
use alloy_evm::overrides::OverrideBlockHashes;
3839
use alloy_network::{
3940
AnyRpcBlock, AnyRpcTransaction, BlockResponse, Ethereum, NetworkWallet, TransactionBuilder,
4041
TransactionResponse, eip2718::Decodable2718,
@@ -2965,7 +2966,7 @@ impl EthApi {
29652966
)?;
29662967
}
29672968
if let Some(block_overrides) = overrides.block {
2968-
state::apply_block_overrides(*block_overrides, &mut cache_db, &mut block);
2969+
cache_db.apply_block_overrides(*block_overrides, &mut block);
29692970
}
29702971
this.do_estimate_gas_with_state(request, &cache_db as &dyn DatabaseRef, block)
29712972
})

crates/anvil/src/eth/backend/executor.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ use anvil_core::eth::{
2424
DepositReceipt, PendingTransaction, TransactionInfo, TypedReceipt, TypedTransaction,
2525
},
2626
};
27-
use foundry_evm::{backend::DatabaseError, traces::CallTraceNode};
27+
use foundry_evm::{
28+
backend::DatabaseError,
29+
traces::{CallTraceDecoder, CallTraceNode},
30+
};
2831
use foundry_evm_core::either_evm::EitherEvm;
2932
use op_revm::{L1BlockInfo, OpContext, precompiles::OpPrecompiles};
3033
use revm::{
@@ -119,6 +122,8 @@ pub struct TransactionExecutor<'a, Db: ?Sized, V: TransactionValidator> {
119122
pub optimism: bool,
120123
pub print_logs: bool,
121124
pub print_traces: bool,
125+
/// Recorder used for decoding traces, used together with print_traces
126+
pub call_trace_decoder: Arc<CallTraceDecoder>,
122127
/// Precompiles to inject to the EVM.
123128
pub precompile_factory: Option<Arc<dyn PrecompileFactory>>,
124129
pub blob_params: BlobParams,
@@ -367,7 +372,7 @@ impl<DB: Db + ?Sized, V: TransactionValidator> Iterator for &mut TransactionExec
367372
};
368373

369374
if self.print_traces {
370-
inspector.print_traces();
375+
inspector.print_traces(self.call_trace_decoder.clone());
371376
}
372377
inspector.print_logs();
373378

crates/anvil/src/eth/backend/mem/inspector.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use revm::{
1919
interpreter::EthInterpreter,
2020
},
2121
};
22+
use std::sync::Arc;
2223

2324
/// The [`revm::Inspector`] used when transacting in the evm
2425
#[derive(Clone, Debug, Default)]
@@ -40,17 +41,17 @@ impl AnvilInspector {
4041
}
4142

4243
/// Consumes the type and prints the traces.
43-
pub fn into_print_traces(mut self) {
44+
pub fn into_print_traces(mut self, decoder: Arc<CallTraceDecoder>) {
4445
if let Some(a) = self.tracer.take() {
45-
print_traces(a)
46+
print_traces(a, decoder);
4647
}
4748
}
4849

4950
/// Called after the inspecting the evm
5051
/// This will log all traces
51-
pub fn print_traces(&self) {
52+
pub fn print_traces(&self, decoder: Arc<CallTraceDecoder>) {
5253
if let Some(a) = self.tracer.clone() {
53-
print_traces(a)
54+
print_traces(a, decoder);
5455
}
5556
}
5657

@@ -60,6 +61,7 @@ impl AnvilInspector {
6061
self
6162
}
6263

64+
/// Configures the `TracingInspector` [`revm::Inspector`]
6365
pub fn with_tracing_config(mut self, config: TracingInspectorConfig) -> Self {
6466
self.tracer = Some(TracingInspector::new(config));
6567
self
@@ -91,11 +93,10 @@ impl AnvilInspector {
9193
/// # Panics
9294
///
9395
/// If called outside tokio runtime
94-
fn print_traces(tracer: TracingInspector) {
96+
fn print_traces(tracer: TracingInspector, decoder: Arc<CallTraceDecoder>) {
9597
let arena = tokio::task::block_in_place(move || {
9698
tokio::runtime::Handle::current().block_on(async move {
9799
let mut arena = tracer.into_traces();
98-
let decoder = CallTraceDecoder::new();
99100
decoder.populate_traces(arena.nodes_mut()).await;
100101
arena
101102
})

crates/anvil/src/eth/backend/mem/mod.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! In-memory blockchain backend.
22
33
use self::state::trie_storage;
4+
use super::executor::new_evm_with_inspector_ref;
45
use crate::{
56
ForkChoice, NodeConfig, PrecompileFactory,
67
config::PruneStateHistoryConfig,
@@ -40,7 +41,9 @@ use alloy_consensus::{
4041
transaction::Recovered,
4142
};
4243
use alloy_eips::{eip1559::BaseFeeParams, eip4844::kzg_to_versioned_hash, eip7840::BlobParams};
43-
use alloy_evm::{Database, Evm, eth::EthEvmContext, precompiles::PrecompilesMap};
44+
use alloy_evm::{
45+
Database, Evm, eth::EthEvmContext, overrides::OverrideBlockHashes, precompiles::PrecompilesMap,
46+
};
4447
use alloy_network::{
4548
AnyHeader, AnyRpcBlock, AnyRpcHeader, AnyRpcTransaction, AnyTxEnvelope, AnyTxType,
4649
EthereumWallet, UnknownTxEnvelope, UnknownTypedTransaction,
@@ -89,7 +92,7 @@ use foundry_evm::{
8992
constants::DEFAULT_CREATE2_DEPLOYER_RUNTIME_CODE,
9093
decode::RevertDecoder,
9194
inspectors::AccessListInspector,
92-
traces::TracingInspectorConfig,
95+
traces::{CallTraceDecoder, TracingInspectorConfig},
9396
utils::{get_blob_base_fee_update_fraction, get_blob_base_fee_update_fraction_by_spec_id},
9497
};
9598
use foundry_evm_core::either_evm::EitherEvm;
@@ -125,8 +128,6 @@ use std::{
125128
use storage::{Blockchain, DEFAULT_HISTORY_LIMIT, MinedTransaction};
126129
use tokio::sync::RwLock as AsyncRwLock;
127130

128-
use super::executor::new_evm_with_inspector_ref;
129-
130131
pub mod cache;
131132
pub mod fork_db;
132133
pub mod in_memory_db;
@@ -226,6 +227,8 @@ pub struct Backend {
226227
enable_steps_tracing: bool,
227228
print_logs: bool,
228229
print_traces: bool,
230+
/// Recorder used for decoding traces, used together with print_traces
231+
call_trace_decoder: Arc<CallTraceDecoder>,
229232
odyssey: bool,
230233
/// How to keep history state
231234
prune_state_history_config: PruneStateHistoryConfig,
@@ -255,6 +258,7 @@ impl Backend {
255258
enable_steps_tracing: bool,
256259
print_logs: bool,
257260
print_traces: bool,
261+
call_trace_decoder: Arc<CallTraceDecoder>,
258262
odyssey: bool,
259263
prune_state_history_config: PruneStateHistoryConfig,
260264
max_persisted_states: Option<usize>,
@@ -360,6 +364,7 @@ impl Backend {
360364
enable_steps_tracing,
361365
print_logs,
362366
print_traces,
367+
call_trace_decoder,
363368
odyssey,
364369
prune_state_history_config,
365370
transaction_block_keeper,
@@ -1211,7 +1216,7 @@ impl Backend {
12111216
inspector.print_logs();
12121217

12131218
if self.print_traces {
1214-
inspector.print_traces();
1219+
inspector.print_traces(self.call_trace_decoder.clone());
12151220
}
12161221

12171222
Ok((exit_reason, out, gas_used, state, logs.unwrap_or_default()))
@@ -1254,6 +1259,7 @@ impl Backend {
12541259
enable_steps_tracing: self.enable_steps_tracing,
12551260
print_logs: self.print_logs,
12561261
print_traces: self.print_traces,
1262+
call_trace_decoder: self.call_trace_decoder.clone(),
12571263
precompile_factory: self.precompile_factory.clone(),
12581264
odyssey: self.odyssey,
12591265
optimism: self.is_optimism(),
@@ -1340,6 +1346,7 @@ impl Backend {
13401346
enable_steps_tracing: self.enable_steps_tracing,
13411347
print_logs: self.print_logs,
13421348
print_traces: self.print_traces,
1349+
call_trace_decoder: self.call_trace_decoder.clone(),
13431350
odyssey: self.odyssey,
13441351
precompile_factory: self.precompile_factory.clone(),
13451352
optimism: self.is_optimism(),
@@ -1477,7 +1484,7 @@ impl Backend {
14771484
state::apply_state_overrides(state_overrides.into_iter().collect(), &mut cache_db)?;
14781485
}
14791486
if let Some(block_overrides) = overrides.block {
1480-
state::apply_block_overrides(*block_overrides, &mut cache_db, &mut block);
1487+
cache_db.apply_block_overrides(*block_overrides, &mut block);
14811488
}
14821489
self.call_with_state(&cache_db as &dyn DatabaseRef, request, fee_details, block)
14831490
}?;
@@ -1656,7 +1663,7 @@ impl Backend {
16561663
state::apply_state_overrides(state_overrides, &mut cache_db)?;
16571664
}
16581665
if let Some(block_overrides) = block_overrides {
1659-
state::apply_block_overrides(block_overrides, &mut cache_db, &mut block_env);
1666+
cache_db.apply_block_overrides(block_overrides, &mut block_env);
16601667
}
16611668

16621669
// execute all calls in that block
@@ -1862,7 +1869,7 @@ impl Backend {
18621869
inspector.print_logs();
18631870

18641871
if self.print_traces {
1865-
inspector.into_print_traces();
1872+
inspector.into_print_traces(self.call_trace_decoder.clone());
18661873
}
18671874

18681875
Ok((exit_reason, out, gas_used as u128, state))
@@ -1887,7 +1894,7 @@ impl Backend {
18871894
state::apply_state_overrides(state_overrides, &mut cache_db)?;
18881895
}
18891896
if let Some(block_overrides) = block_overrides {
1890-
state::apply_block_overrides(block_overrides, &mut cache_db, &mut block);
1897+
cache_db.apply_block_overrides(block_overrides, &mut block);
18911898
}
18921899

18931900
if let Some(tracer) = tracer {

crates/anvil/src/eth/backend/mem/state.rs

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
use crate::eth::error::BlockchainError;
44
use alloy_primitives::{Address, B256, U256, keccak256, map::HashMap};
55
use alloy_rlp::Encodable;
6-
use alloy_rpc_types::{BlockOverrides, state::StateOverride};
6+
use alloy_rpc_types::state::StateOverride;
77
use alloy_trie::{HashBuilder, Nibbles};
88
use foundry_evm::backend::DatabaseError;
99
use revm::{
1010
bytecode::Bytecode,
11-
context::BlockEnv,
1211
database::{CacheDB, DatabaseRef, DbAccount},
1312
state::AccountInfo,
1413
};
@@ -121,51 +120,3 @@ where
121120
}
122121
Ok(())
123122
}
124-
125-
/// Applies the given block overrides to the env and updates overridden block hashes in the db.
126-
pub fn apply_block_overrides<DB>(
127-
overrides: BlockOverrides,
128-
cache_db: &mut CacheDB<DB>,
129-
env: &mut BlockEnv,
130-
) {
131-
let BlockOverrides {
132-
number,
133-
difficulty,
134-
time,
135-
gas_limit,
136-
coinbase,
137-
random,
138-
base_fee,
139-
block_hash,
140-
} = overrides;
141-
142-
if let Some(block_hashes) = block_hash {
143-
// override block hashes
144-
cache_db
145-
.cache
146-
.block_hashes
147-
.extend(block_hashes.into_iter().map(|(num, hash)| (U256::from(num), hash)))
148-
}
149-
150-
if let Some(number) = number {
151-
env.number = number.saturating_to();
152-
}
153-
if let Some(difficulty) = difficulty {
154-
env.difficulty = difficulty;
155-
}
156-
if let Some(time) = time {
157-
env.timestamp = U256::from(time);
158-
}
159-
if let Some(gas_limit) = gas_limit {
160-
env.gas_limit = gas_limit;
161-
}
162-
if let Some(coinbase) = coinbase {
163-
env.beneficiary = coinbase;
164-
}
165-
if let Some(random) = random {
166-
env.prevrandao = Some(random);
167-
}
168-
if let Some(base_fee) = base_fee {
169-
env.basefee = base_fee.saturating_to();
170-
}
171-
}

crates/evm/traces/src/decoder/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,18 +410,18 @@ impl CallTraceDecoder {
410410
None
411411
};
412412

413-
if let Some(func) = functions.first() {
414-
return DecodedCallTrace {
413+
return if let Some(func) = functions.first() {
414+
DecodedCallTrace {
415415
label,
416416
call_data: Some(self.decode_function_input(trace, func)),
417417
return_data,
418-
};
418+
}
419419
} else {
420-
return DecodedCallTrace {
420+
DecodedCallTrace {
421421
label,
422422
call_data: self.fallback_call_data(trace),
423423
return_data,
424-
};
424+
}
425425
};
426426
}
427427

0 commit comments

Comments
 (0)