Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions crates/core/src/evm/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use std::fmt::Display;

use revm::primitives::result::EVMError as RevmError;
use thiserror::Error;

#[derive(Debug, Error)]
pub enum EvmError {
#[error("Invalid Transaction: {0}")]
Transaction(String),
#[error("Invalid Header: {0}")]
Header(String),
#[error("DB error: {0}")]
DB(String),
#[error("{0}")]
Custom(String),
#[error("{0}")]
Precompile(String),
}

impl<T: Display> From<RevmError<T>> for EvmError {
fn from(value: RevmError<T>) -> Self {
match value {
RevmError::Transaction(err) => EvmError::Transaction(err.to_string()),
RevmError::Header(err) => EvmError::Header(err.to_string()),
RevmError::Database(err) => EvmError::DB(err.to_string()),
RevmError::Custom(err) => EvmError::Custom(err),
RevmError::Precompile(err) => EvmError::Precompile(err),
}
}
}
8 changes: 5 additions & 3 deletions crates/core/src/evm/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod errors;
mod execution_result;

use crate::types::TxKind;
Expand All @@ -18,6 +19,7 @@ use revm::primitives::AccountInfo as RevmAccountInfo;
use revm::primitives::Address as RevmAddress;
use revm::primitives::TxKind as RevmTxKind;
// Export needed types
pub use errors::EvmError;
pub use execution_result::*;
pub use revm::primitives::SpecId;

Expand All @@ -26,7 +28,7 @@ pub fn execute_tx(
header: &BlockHeader,
pre: &HashMap<Address, Account>, // TODO: Modify this type when we have a defined State structure
spec_id: SpecId,
) -> ExecutionResult {
) -> Result<ExecutionResult, EvmError> {
let block_env = block_env(header);
let tx_env = tx_env(tx);
let cache_state = cache_state(pre);
Expand All @@ -43,8 +45,8 @@ pub fn execute_tx(
.with_external_context(TracerEip3155::new(Box::new(std::io::stderr())).without_summary())
.append_handler_register(inspector_handle_register)
.build();
let tx_result = evm.transact().unwrap();
tx_result.result.into()
let tx_result = evm.transact().map_err(EvmError::from)?;
Ok(tx_result.result.into())
}

fn cache_state(pre: &HashMap<Address, Account>) -> CacheState {
Expand Down
1 change: 1 addition & 0 deletions ef_tests/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ fn execute_test(test: &TestUnit) {
&pre,
SpecId::CANCUN,
)
.unwrap()
.is_success());
}

Expand Down