Skip to content

Commit 69b520d

Browse files
decofezerosnacks
andcommitted
fix(cast): detect OP Stack chains early in cast run
`cast run` on OP Stack chains (Base, Optimism) fails with: `data did not match any variant of untagged enum BlockTransactions` Root cause: the generic `FoundryEvmNetwork` refactor (PR #14121) changed `cast run` from using `AnyNetwork` to dispatching via `FEN::Network`. Non-Tempo chains use `EthEvmNetwork` whose `Network = Ethereum`, which cannot deserialize OP deposit transactions (type 0x7e). Fix: decouple the RPC provider network type from the EVM factory by making `run_with_provider` generic over both `FEN` (EVM factory) and `N` (provider network). The dispatch in `run()` now detects OP Stack chains early via `is_optimism()` and uses `FoundryNetwork` as the provider network, which supports all transaction types including OP deposits. Co-Authored-By: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
1 parent 4028d1a commit 69b520d

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cast/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ foundry-compilers.workspace = true
2828
foundry-config.workspace = true
2929
foundry-debugger.workspace = true
3030
foundry-evm.workspace = true
31+
foundry-primitives.workspace = true
3132
foundry-wallets.workspace = true
3233
forge-fmt.workspace = true
3334

crates/cast/src/cmd/run.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
use alloy_consensus::{BlockHeader, Transaction, transaction::SignerRecoverable};
66

77
use alloy_evm::FromRecoveredTx;
8-
use alloy_network::{BlockResponse, TransactionResponse};
8+
use alloy_network::{BlockResponse, Network, TransactionResponse};
99
use alloy_primitives::{
1010
Address, Bytes, U256,
1111
map::{AddressSet, HashMap},
@@ -38,6 +38,7 @@ use foundry_evm::{
3838
opts::EvmOpts,
3939
traces::{InternalTraceMode, TraceMode, Traces},
4040
};
41+
use foundry_primitives::FoundryNetwork;
4142
use futures::TryFutureExt;
4243
use revm::{DatabaseRef, context::Block};
4344

@@ -138,13 +139,26 @@ impl RunArgs {
138139
evm_opts.infer_network_from_fork().await;
139140

140141
if evm_opts.networks.is_tempo() {
141-
self.run_with_evm::<TempoEvmNetwork>().await
142+
self.run_with_provider::<TempoEvmNetwork, <TempoEvmNetwork as FoundryEvmNetwork>::Network>().await
143+
} else if evm_opts.networks.is_optimism() {
144+
// OP Stack chains include deposit transactions (type 0x7e) that the
145+
// `Ethereum` network type cannot deserialize. Use `FoundryNetwork` as the
146+
// provider network, which supports all transaction types.
147+
self.run_with_provider::<EthEvmNetwork, FoundryNetwork>().await
142148
} else {
143-
self.run_with_evm::<EthEvmNetwork>().await
149+
self.run_with_provider::<EthEvmNetwork, <EthEvmNetwork as FoundryEvmNetwork>::Network>().await
144150
}
145151
}
146152

147-
async fn run_with_evm<FEN: FoundryEvmNetwork>(self) -> Result<()> {
153+
async fn run_with_provider<FEN, N>(self) -> Result<()>
154+
where
155+
FEN: FoundryEvmNetwork,
156+
N: Network,
157+
N::TransactionResponse: TransactionResponse + AsRef<N::TxEnvelope>,
158+
N::TxEnvelope: SignerRecoverable,
159+
N::BlockResponse: BlockResponse<Header: BlockHeader>,
160+
TxEnvFor<FEN>: FromRecoveredTx<N::TxEnvelope>,
161+
{
148162
let figment = self.rpc.clone().into_figment(self.with_local_artifacts).merge(&self);
149163
let evm_opts = figment.extract::<EvmOpts>()?;
150164
let mut config = Config::from_provider(figment)?.sanitized();
@@ -157,7 +171,7 @@ impl RunArgs {
157171
let compute_units_per_second =
158172
if self.no_rate_limit { Some(u64::MAX) } else { self.compute_units_per_second };
159173

160-
let provider = ProviderBuilder::<FEN::Network>::from_config(&config)?
174+
let provider = ProviderBuilder::<N>::from_config(&config)?
161175
.compute_units_per_second_opt(compute_units_per_second)
162176
.build()?;
163177

@@ -217,7 +231,7 @@ impl RunArgs {
217231
evm_version = Some(EvmVersion::Prague);
218232
}
219233
}
220-
apply_chain_and_block_specific_env_changes::<FEN::Network, _, _>(
234+
apply_chain_and_block_specific_env_changes::<N, _, _>(
221235
&mut evm_env,
222236
block,
223237
config.networks,

0 commit comments

Comments
 (0)