fix: bytecode override (#14390)

This commit is contained in:
Matthias Seitz
2025-02-11 00:54:04 +01:00
committed by GitHub
parent 85f66ff7ac
commit ba8cec3550
2 changed files with 13 additions and 2 deletions

View File

@ -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<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 |

View File

@ -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;