diff --git a/Cargo.lock b/Cargo.lock index 8d57c34cb5..a14b57fad5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3552,7 +3552,6 @@ dependencies = [ "revm-database-interface", "revm-handler", "revm-interpreter", - "revm-precompile", "revm-primitives", "revm-state", "serde", @@ -3588,7 +3587,6 @@ dependencies = [ "once_cell", "p256", "rand", - "revm-context-interface", "revm-primitives", "ripemd", "rstest", diff --git a/crates/context/interface/src/result.rs b/crates/context/interface/src/result.rs index 99bd6b4f4c..c8d79af110 100644 --- a/crates/context/interface/src/result.rs +++ b/crates/context/interface/src/result.rs @@ -200,8 +200,6 @@ pub enum EVMError { /// /// Useful for handler registers where custom logic would want to return their own custom error. Custom(String), - /// Precompile error - Precompile(String), } impl From for EVMError { @@ -236,7 +234,6 @@ impl EVMError EVMError::Transaction(e), Self::Header(e) => EVMError::Header(e), Self::Database(e) => EVMError::Database(op(e)), - Self::Precompile(e) => EVMError::Precompile(e), Self::Custom(e) => EVMError::Custom(e), } } @@ -253,7 +250,7 @@ where Self::Transaction(e) => Some(e), Self::Header(e) => Some(e), Self::Database(e) => Some(e), - Self::Precompile(_) | Self::Custom(_) => None, + Self::Custom(_) => None, } } } @@ -269,7 +266,7 @@ where Self::Transaction(e) => write!(f, "transaction validation error: {e}"), Self::Header(e) => write!(f, "header validation error: {e}"), Self::Database(e) => write!(f, "database error: {e}"), - Self::Precompile(e) | Self::Custom(e) => f.write_str(e), + Self::Custom(e) => f.write_str(e), } } } diff --git a/crates/handler/src/frame.rs b/crates/handler/src/frame.rs index 53a0f53bd1..79d07e00a3 100644 --- a/crates/handler/src/frame.rs +++ b/crates/handler/src/frame.rs @@ -20,7 +20,6 @@ use interpreter::{ CreateScheme, EOFCreateInputs, EOFCreateKind, FrameInput, Gas, InputsImpl, InstructionResult, Interpreter, InterpreterAction, InterpreterResult, InterpreterTypes, SharedMemory, }; -use precompile::PrecompileError; use primitives::{ constants::CALL_STACK_LIMIT, hardfork::SpecId::{self, HOMESTEAD, LONDON, OSAKA, SPURIOUS_DRAGON}, @@ -82,7 +81,7 @@ where InterpreterTypes = EthInterpreter, >, >, - ERROR: From> + From + FromStringError, + ERROR: From> + FromStringError, { type Evm = EVM; type FrameInit = FrameInput; @@ -151,7 +150,8 @@ where Precompiles: PrecompileProvider, Instructions: InstructionProvider, >, - ERROR: From> + From, + ERROR: From>, + ERROR: FromStringError, { /// Make call frame #[inline] @@ -204,12 +204,15 @@ where } let is_ext_delegate_call = inputs.scheme.is_ext_delegate_call(); if !is_ext_delegate_call { - if let Some(result) = precompiles.run( - context, - &inputs.bytecode_address, - &inputs.input, - inputs.gas_limit, - )? { + if let Some(result) = precompiles + .run( + context, + &inputs.bytecode_address, + &inputs.input, + inputs.gas_limit, + ) + .map_err(ERROR::from_string)? + { if result.result.is_ok() { context.journal().checkpoint_commit(); } else { @@ -522,7 +525,7 @@ where InterpreterTypes = EthInterpreter, >, >, - ERROR: From> + From + FromStringError, + ERROR: From> + FromStringError, { pub fn init_first( evm: &mut EVM, diff --git a/crates/handler/src/handler.rs b/crates/handler/src/handler.rs index 0ed60e2e20..4b5acb4c3c 100644 --- a/crates/handler/src/handler.rs +++ b/crates/handler/src/handler.rs @@ -12,14 +12,12 @@ use context_interface::{ Cfg, Database, JournalTr, Transaction, }; use interpreter::{FrameInput, Gas, InitialAndFloorGas}; -use precompile::PrecompileError; use std::{vec, vec::Vec}; pub trait EvmTrError: From + From + From<<::Db as Database>::Error> - + From + FromStringError { } @@ -29,7 +27,6 @@ impl< T: From + From + From<<::Db as Database>::Error> - + From + FromStringError, > EvmTrError for T { diff --git a/crates/handler/src/precompile_provider.rs b/crates/handler/src/precompile_provider.rs index a939efc426..b15ea7cb59 100644 --- a/crates/handler/src/precompile_provider.rs +++ b/crates/handler/src/precompile_provider.rs @@ -6,6 +6,7 @@ use precompile::PrecompileError; use precompile::{PrecompileSpecId, Precompiles}; use primitives::{hardfork::SpecId, Address, Bytes}; use std::boxed::Box; +use std::string::String; #[auto_impl(&mut, Box)] pub trait PrecompileProvider { @@ -20,7 +21,7 @@ pub trait PrecompileProvider { address: &Address, bytes: &Bytes, gas_limit: u64, - ) -> Result, PrecompileError>; + ) -> Result, String>; /// Get the warm addresses. fn warm_addresses(&self) -> Box>; @@ -76,7 +77,7 @@ impl PrecompileProvider for EthPrecompiles { address: &Address, bytes: &Bytes, gas_limit: u64, - ) -> Result, PrecompileError> { + ) -> Result, String> { let Some(precompile) = self.precompiles.get(address) else { return Ok(None); }; @@ -94,10 +95,8 @@ impl PrecompileProvider for EthPrecompiles { result.result = InstructionResult::Return; result.output = output.bytes; } + Err(PrecompileError::Fatal(e)) => return Err(e), Err(e) => { - if let PrecompileError::Fatal(_) = e { - return Err(e); - } result.result = if e.is_oog() { InstructionResult::PrecompileOOG } else { diff --git a/crates/inspector/Cargo.toml b/crates/inspector/Cargo.toml index e5e42d68ef..270e284362 100644 --- a/crates/inspector/Cargo.toml +++ b/crates/inspector/Cargo.toml @@ -26,7 +26,6 @@ all = "warn" context.workspace = true database-interface.workspace = true handler.workspace = true -precompile.workspace = true primitives.workspace = true state.workspace = true interpreter.workspace = true @@ -52,7 +51,6 @@ std = [ "database-interface/std", "handler/std", "interpreter/std", - "precompile/std", "primitives/std", "state/std", ] diff --git a/crates/inspector/src/traits.rs b/crates/inspector/src/traits.rs index d3cd6afc6c..b8af6efac1 100644 --- a/crates/inspector/src/traits.rs +++ b/crates/inspector/src/traits.rs @@ -8,7 +8,6 @@ use interpreter::{ interpreter::EthInterpreter, FrameInput, Interpreter, InterpreterAction, InterpreterResult, InterpreterTypes, }; -use precompile::PrecompileError; /// Inspector EVM trait. pub trait InspectorEvmTr: EvmTr { @@ -86,7 +85,7 @@ where InterpreterTypes = EthInterpreter, >, > + InspectorEvmTr, - ERROR: From> + From + FromStringError, + ERROR: From> + FromStringError, { type IT = EthInterpreter; diff --git a/crates/optimism/src/precompiles.rs b/crates/optimism/src/precompiles.rs index 5cd26c9d1e..9168b8bc41 100644 --- a/crates/optimism/src/precompiles.rs +++ b/crates/optimism/src/precompiles.rs @@ -12,7 +12,7 @@ use revm::{ primitives::{Address, Bytes}, }; use std::boxed::Box; - +use std::string::String; // Optimism precompile provider #[derive(Debug, Clone)] pub struct OpPrecompiles { @@ -100,7 +100,7 @@ where address: &Address, bytes: &Bytes, gas_limit: u64, - ) -> Result, PrecompileError> { + ) -> Result, String> { self.inner.run(context, address, bytes, gas_limit) } diff --git a/crates/precompile/Cargo.toml b/crates/precompile/Cargo.toml index 5fa9a836f3..8941f89c6e 100644 --- a/crates/precompile/Cargo.toml +++ b/crates/precompile/Cargo.toml @@ -24,7 +24,6 @@ all = "warn" [dependencies] # revm primitives.workspace = true -context-interface.workspace = true # static precompile sets. once_cell = { workspace = true, features = ["alloc"] } @@ -90,7 +89,6 @@ std = [ "libsecp256k1?/std", "aurora-engine-modexp/std", "p256?/std", - "context-interface/std", "serde/std", "serde_json/std" ] diff --git a/crates/precompile/src/interface.rs b/crates/precompile/src/interface.rs index a8709f013b..ce80df2cea 100644 --- a/crates/precompile/src/interface.rs +++ b/crates/precompile/src/interface.rs @@ -1,7 +1,6 @@ -use context_interface::result::EVMError; use core::fmt; use primitives::Bytes; -use std::string::{String, ToString}; +use std::string::String; /// A precompile operation result type /// @@ -66,12 +65,6 @@ impl PrecompileError { } } -impl From for EVMError { - fn from(value: PrecompileError) -> Self { - Self::Precompile(value.to_string()) - } -} - impl core::error::Error for PrecompileError {} impl fmt::Display for PrecompileError { diff --git a/examples/erc20_gas/src/main.rs b/examples/erc20_gas/src/main.rs index 047c10dfc8..cf621966bc 100644 --- a/examples/erc20_gas/src/main.rs +++ b/examples/erc20_gas/src/main.rs @@ -15,7 +15,6 @@ use revm::{ }, database::{AlloyDB, BlockId, CacheDB}, database_interface::WrapDatabaseAsync, - precompile::PrecompileError, primitives::{address, hardfork::SpecId, keccak256, Address, TxKind, KECCAK_EMPTY, U256}, state::AccountInfo, Context, Database, MainBuilder, MainContext, @@ -84,10 +83,7 @@ pub fn token_operation( ) -> Result<(), ERROR> where CTX: ContextTr, - ERROR: From - + From - + From<::Error> - + From, + ERROR: From + From + From<::Error>, { let sender_balance_slot = erc_address_storage(sender); let sender_balance = context.journal().sload(TOKEN, sender_balance_slot)?.data;