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
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions crates/context/interface/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ pub enum EVMError<DBError, TransactionError = InvalidTransaction> {
///
/// Useful for handler registers where custom logic would want to return their own custom error.
Custom(String),
/// Precompile error
Precompile(String),
}

impl<DBError: DBErrorMarker, TX> From<DBError> for EVMError<DBError, TX> {
Expand Down Expand Up @@ -236,7 +234,6 @@ impl<DBError, TransactionValidationErrorT> EVMError<DBError, TransactionValidati
Self::Transaction(e) => 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),
}
}
Expand All @@ -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,
}
}
}
Expand All @@ -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),
}
}
}
Expand Down
23 changes: 13 additions & 10 deletions crates/handler/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -82,7 +81,7 @@ where
InterpreterTypes = EthInterpreter,
>,
>,
ERROR: From<ContextTrDbError<EVM::Context>> + From<PrecompileError> + FromStringError,
ERROR: From<ContextTrDbError<EVM::Context>> + FromStringError,
{
type Evm = EVM;
type FrameInit = FrameInput;
Expand Down Expand Up @@ -151,7 +150,8 @@ where
Precompiles: PrecompileProvider<EVM::Context, Output = InterpreterResult>,
Instructions: InstructionProvider,
>,
ERROR: From<ContextTrDbError<EVM::Context>> + From<PrecompileError>,
ERROR: From<ContextTrDbError<EVM::Context>>,
ERROR: FromStringError,
{
/// Make call frame
#[inline]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -522,7 +525,7 @@ where
InterpreterTypes = EthInterpreter,
>,
>,
ERROR: From<ContextTrDbError<EVM::Context>> + From<PrecompileError> + FromStringError,
ERROR: From<ContextTrDbError<EVM::Context>> + FromStringError,
{
pub fn init_first(
evm: &mut EVM,
Expand Down
3 changes: 0 additions & 3 deletions crates/handler/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<EVM: EvmTr>:
From<InvalidTransaction>
+ From<InvalidHeader>
+ From<<<EVM::Context as ContextTr>::Db as Database>::Error>
+ From<PrecompileError>
+ FromStringError
{
}
Expand All @@ -29,7 +27,6 @@ impl<
T: From<InvalidTransaction>
+ From<InvalidHeader>
+ From<<<EVM::Context as ContextTr>::Db as Database>::Error>
+ From<PrecompileError>
+ FromStringError,
> EvmTrError<EVM> for T
{
Expand Down
9 changes: 4 additions & 5 deletions crates/handler/src/precompile_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CTX: ContextTr> {
Expand All @@ -20,7 +21,7 @@ pub trait PrecompileProvider<CTX: ContextTr> {
address: &Address,
bytes: &Bytes,
gas_limit: u64,
) -> Result<Option<Self::Output>, PrecompileError>;
) -> Result<Option<Self::Output>, String>;

/// Get the warm addresses.
fn warm_addresses(&self) -> Box<impl Iterator<Item = Address>>;
Expand Down Expand Up @@ -76,7 +77,7 @@ impl<CTX: ContextTr> PrecompileProvider<CTX> for EthPrecompiles {
address: &Address,
bytes: &Bytes,
gas_limit: u64,
) -> Result<Option<InterpreterResult>, PrecompileError> {
) -> Result<Option<InterpreterResult>, String> {
let Some(precompile) = self.precompiles.get(address) else {
return Ok(None);
};
Expand All @@ -94,10 +95,8 @@ impl<CTX: ContextTr> PrecompileProvider<CTX> 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 {
Expand Down
2 changes: 0 additions & 2 deletions crates/inspector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -52,7 +51,6 @@ std = [
"database-interface/std",
"handler/std",
"interpreter/std",
"precompile/std",
"primitives/std",
"state/std",
]
Expand Down
3 changes: 1 addition & 2 deletions crates/inspector/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use interpreter::{
interpreter::EthInterpreter, FrameInput, Interpreter, InterpreterAction, InterpreterResult,
InterpreterTypes,
};
use precompile::PrecompileError;

/// Inspector EVM trait.
pub trait InspectorEvmTr: EvmTr {
Expand Down Expand Up @@ -86,7 +85,7 @@ where
InterpreterTypes = EthInterpreter,
>,
> + InspectorEvmTr,
ERROR: From<ContextTrDbError<EVM::Context>> + From<PrecompileError> + FromStringError,
ERROR: From<ContextTrDbError<EVM::Context>> + FromStringError,
{
type IT = EthInterpreter;

Expand Down
4 changes: 2 additions & 2 deletions crates/optimism/src/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -100,7 +100,7 @@ where
address: &Address,
bytes: &Bytes,
gas_limit: u64,
) -> Result<Option<Self::Output>, PrecompileError> {
) -> Result<Option<Self::Output>, String> {
self.inner.run(context, address, bytes, gas_limit)
}

Expand Down
2 changes: 0 additions & 2 deletions crates/precompile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ all = "warn"
[dependencies]
# revm
primitives.workspace = true
context-interface.workspace = true

# static precompile sets.
once_cell = { workspace = true, features = ["alloc"] }
Expand Down Expand Up @@ -90,7 +89,6 @@ std = [
"libsecp256k1?/std",
"aurora-engine-modexp/std",
"p256?/std",
"context-interface/std",
"serde/std",
"serde_json/std"
]
Expand Down
9 changes: 1 addition & 8 deletions crates/precompile/src/interface.rs
Original file line number Diff line number Diff line change
@@ -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
///
Expand Down Expand Up @@ -66,12 +65,6 @@ impl PrecompileError {
}
}

impl<DB, TXERROR> From<PrecompileError> for EVMError<DB, TXERROR> {
fn from(value: PrecompileError) -> Self {
Self::Precompile(value.to_string())
}
}

impl core::error::Error for PrecompileError {}

impl fmt::Display for PrecompileError {
Expand Down
6 changes: 1 addition & 5 deletions examples/erc20_gas/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -84,10 +83,7 @@ pub fn token_operation<CTX, ERROR>(
) -> Result<(), ERROR>
where
CTX: ContextTr,
ERROR: From<InvalidTransaction>
+ From<InvalidHeader>
+ From<<CTX::Db as Database>::Error>
+ From<PrecompileError>,
ERROR: From<InvalidTransaction> + From<InvalidHeader> + From<<CTX::Db as Database>::Error>,
{
let sender_balance_slot = erc_address_storage(sender);
let sender_balance = context.journal().sload(TOKEN, sender_balance_slot)?.data;
Expand Down
Loading