Skip to content

Commit

Permalink
fix: bytecode override (paradigmxyz#14390)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Feb 10, 2025
1 parent 85f66ff commit ba8cec3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 9 additions & 1 deletion crates/rpc/rpc-eth-types/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -175,7 +182,8 @@ impl From<EthApiError> 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 |
Expand Down
5 changes: 4 additions & 1 deletion crates/rpc/rpc-eth-types/src/revm_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ba8cec3

Please sign in to comment.