From ba8cec3550cc10dbeb16e7526392e1c96c09fde6 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 11 Feb 2025 00:54:04 +0100 Subject: [PATCH] fix: bytecode override (#14390) --- crates/rpc/rpc-eth-types/src/error/mod.rs | 10 +++++++++- crates/rpc/rpc-eth-types/src/revm_utils.rs | 5 ++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/rpc/rpc-eth-types/src/error/mod.rs b/crates/rpc/rpc-eth-types/src/error/mod.rs index 9a62a7a1f..81c38fc07 100644 --- a/crates/rpc/rpc-eth-types/src/error/mod.rs +++ b/crates/rpc/rpc-eth-types/src/error/mod.rs @@ -132,6 +132,13 @@ pub enum EthApiError { /// Evm generic purpose error. #[error("Revm error: {0}")] EvmCustom(String), + /// Bytecode override is invalid. + /// + /// This can happen if bytecode provided in an + /// [`AccountOverride`](alloy_rpc_types_eth::state::AccountOverride) is malformed, e.g. invalid + /// 7702 bytecode. + #[error("Invalide bytecode: {0}")] + InvalidBytecode(String), /// Evm precompile error #[error("Revm precompile error: {0}")] EvmPrecompile(String), @@ -175,7 +182,8 @@ impl From for jsonrpsee_types::error::ErrorObject<'static> { EthApiError::Signing(_) | EthApiError::BothStateAndStateDiffInOverride(_) | EthApiError::InvalidTracerConfig | - EthApiError::TransactionConversionError => invalid_params_rpc_err(error.to_string()), + EthApiError::TransactionConversionError | + EthApiError::InvalidBytecode(_) => invalid_params_rpc_err(error.to_string()), EthApiError::InvalidTransaction(err) => err.into(), EthApiError::PoolError(err) => err.into(), EthApiError::PrevrandaoNotSet | diff --git a/crates/rpc/rpc-eth-types/src/revm_utils.rs b/crates/rpc/rpc-eth-types/src/revm_utils.rs index 3fe8e8237..70685c931 100644 --- a/crates/rpc/rpc-eth-types/src/revm_utils.rs +++ b/crates/rpc/rpc-eth-types/src/revm_utils.rs @@ -272,7 +272,10 @@ where account_info.nonce = nonce; } if let Some(code) = account_override.code { - account_info.code = Some(Bytecode::new_raw(code)); + account_info.code = Some( + Bytecode::new_raw_checked(code) + .map_err(|err| EthApiError::InvalidBytecode(err.to_string()))?, + ); } if let Some(balance) = account_override.balance { account_info.balance = balance;