diff --git a/crates/interpreter/src/instruction_result.rs b/crates/interpreter/src/instruction_result.rs index 27e84d5f39a..124583da1ec 100644 --- a/crates/interpreter/src/instruction_result.rs +++ b/crates/interpreter/src/instruction_result.rs @@ -1,4 +1,4 @@ -use crate::primitives::{Eval, Halt, OutOfGasError}; +use crate::primitives::{HaltReason, OutOfGasError, SuccessReason}; #[repr(u8)] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] @@ -49,44 +49,44 @@ pub enum InstructionResult { FatalExternalError, } -impl From for InstructionResult { - fn from(value: Eval) -> Self { +impl From for InstructionResult { + fn from(value: SuccessReason) -> Self { match value { - Eval::Return => InstructionResult::Return, - Eval::Stop => InstructionResult::Stop, - Eval::SelfDestruct => InstructionResult::SelfDestruct, + SuccessReason::Return => InstructionResult::Return, + SuccessReason::Stop => InstructionResult::Stop, + SuccessReason::SelfDestruct => InstructionResult::SelfDestruct, } } } -impl From for InstructionResult { - fn from(value: Halt) -> Self { +impl From for InstructionResult { + fn from(value: HaltReason) -> Self { match value { - Halt::OutOfGas(OutOfGasError::BasicOutOfGas) => Self::OutOfGas, - Halt::OutOfGas(OutOfGasError::InvalidOperand) => Self::InvalidOperandOOG, - Halt::OutOfGas(OutOfGasError::Memory) => Self::MemoryOOG, - Halt::OutOfGas(OutOfGasError::MemoryLimit) => Self::MemoryLimitOOG, - Halt::OutOfGas(OutOfGasError::Precompile) => Self::PrecompileOOG, - Halt::OpcodeNotFound => Self::OpcodeNotFound, - Halt::InvalidFEOpcode => Self::InvalidFEOpcode, - Halt::InvalidJump => Self::InvalidJump, - Halt::NotActivated => Self::NotActivated, - Halt::StackOverflow => Self::StackOverflow, - Halt::StackUnderflow => Self::StackUnderflow, - Halt::OutOfOffset => Self::OutOfOffset, - Halt::CreateCollision => Self::CreateCollision, - Halt::PrecompileError => Self::PrecompileError, - Halt::NonceOverflow => Self::NonceOverflow, - Halt::CreateContractSizeLimit => Self::CreateContractSizeLimit, - Halt::CreateContractStartingWithEF => Self::CreateContractStartingWithEF, - Halt::CreateInitCodeSizeLimit => Self::CreateInitCodeSizeLimit, - Halt::OverflowPayment => Self::OverflowPayment, - Halt::StateChangeDuringStaticCall => Self::StateChangeDuringStaticCall, - Halt::CallNotAllowedInsideStatic => Self::CallNotAllowedInsideStatic, - Halt::OutOfFund => Self::OutOfFund, - Halt::CallTooDeep => Self::CallTooDeep, + HaltReason::OutOfGas(OutOfGasError::BasicOutOfGas) => Self::OutOfGas, + HaltReason::OutOfGas(OutOfGasError::InvalidOperand) => Self::InvalidOperandOOG, + HaltReason::OutOfGas(OutOfGasError::Memory) => Self::MemoryOOG, + HaltReason::OutOfGas(OutOfGasError::MemoryLimit) => Self::MemoryLimitOOG, + HaltReason::OutOfGas(OutOfGasError::Precompile) => Self::PrecompileOOG, + HaltReason::OpcodeNotFound => Self::OpcodeNotFound, + HaltReason::InvalidFEOpcode => Self::InvalidFEOpcode, + HaltReason::InvalidJump => Self::InvalidJump, + HaltReason::NotActivated => Self::NotActivated, + HaltReason::StackOverflow => Self::StackOverflow, + HaltReason::StackUnderflow => Self::StackUnderflow, + HaltReason::OutOfOffset => Self::OutOfOffset, + HaltReason::CreateCollision => Self::CreateCollision, + HaltReason::PrecompileError => Self::PrecompileError, + HaltReason::NonceOverflow => Self::NonceOverflow, + HaltReason::CreateContractSizeLimit => Self::CreateContractSizeLimit, + HaltReason::CreateContractStartingWithEF => Self::CreateContractStartingWithEF, + HaltReason::CreateInitCodeSizeLimit => Self::CreateInitCodeSizeLimit, + HaltReason::OverflowPayment => Self::OverflowPayment, + HaltReason::StateChangeDuringStaticCall => Self::StateChangeDuringStaticCall, + HaltReason::CallNotAllowedInsideStatic => Self::CallNotAllowedInsideStatic, + HaltReason::OutOfFund => Self::OutOfFund, + HaltReason::CallTooDeep => Self::CallTooDeep, #[cfg(feature = "optimism")] - Halt::FailedDeposit => Self::FatalExternalError, + HaltReason::FailedDeposit => Self::FatalExternalError, } } } @@ -157,9 +157,9 @@ impl InstructionResult { #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum SuccessOrHalt { - Success(Eval), + Success(SuccessReason), Revert, - Halt(Halt), + Halt(HaltReason), FatalExternalError, /// Internal instruction that signals Interpreter should continue running. InternalContinue, @@ -176,7 +176,7 @@ impl SuccessOrHalt { /// Returns the [Eval] value if this a successful result #[inline] - pub fn to_success(self) -> Option { + pub fn to_success(self) -> Option { match self { SuccessOrHalt::Success(eval) => Some(eval), _ => None, @@ -197,7 +197,7 @@ impl SuccessOrHalt { /// Returns the [Halt] value the EVM has experienced an exceptional halt #[inline] - pub fn to_halt(self) -> Option { + pub fn to_halt(self) -> Option { match self { SuccessOrHalt::Halt(halt) => Some(halt), _ => None, @@ -209,50 +209,54 @@ impl From for SuccessOrHalt { fn from(result: InstructionResult) -> Self { match result { InstructionResult::Continue => Self::InternalContinue, // used only in interpreter loop - InstructionResult::Stop => Self::Success(Eval::Stop), - InstructionResult::Return => Self::Success(Eval::Return), - InstructionResult::SelfDestruct => Self::Success(Eval::SelfDestruct), + InstructionResult::Stop => Self::Success(SuccessReason::Stop), + InstructionResult::Return => Self::Success(SuccessReason::Return), + InstructionResult::SelfDestruct => Self::Success(SuccessReason::SelfDestruct), InstructionResult::Revert => Self::Revert, InstructionResult::CallOrCreate => Self::InternalCallOrCreate, // used only in interpreter loop - InstructionResult::CallTooDeep => Self::Halt(Halt::CallTooDeep), // not gonna happen for first call - InstructionResult::OutOfFund => Self::Halt(Halt::OutOfFund), // Check for first call is done separately. - InstructionResult::OutOfGas => Self::Halt(Halt::OutOfGas( + InstructionResult::CallTooDeep => Self::Halt(HaltReason::CallTooDeep), // not gonna happen for first call + InstructionResult::OutOfFund => Self::Halt(HaltReason::OutOfFund), // Check for first call is done separately. + InstructionResult::OutOfGas => Self::Halt(HaltReason::OutOfGas( revm_primitives::OutOfGasError::BasicOutOfGas, )), - InstructionResult::MemoryLimitOOG => { - Self::Halt(Halt::OutOfGas(revm_primitives::OutOfGasError::MemoryLimit)) - } + InstructionResult::MemoryLimitOOG => Self::Halt(HaltReason::OutOfGas( + revm_primitives::OutOfGasError::MemoryLimit, + )), InstructionResult::MemoryOOG => { - Self::Halt(Halt::OutOfGas(revm_primitives::OutOfGasError::Memory)) - } - InstructionResult::PrecompileOOG => { - Self::Halt(Halt::OutOfGas(revm_primitives::OutOfGasError::Precompile)) + Self::Halt(HaltReason::OutOfGas(revm_primitives::OutOfGasError::Memory)) } - InstructionResult::InvalidOperandOOG => Self::Halt(Halt::OutOfGas( + InstructionResult::PrecompileOOG => Self::Halt(HaltReason::OutOfGas( + revm_primitives::OutOfGasError::Precompile, + )), + InstructionResult::InvalidOperandOOG => Self::Halt(HaltReason::OutOfGas( revm_primitives::OutOfGasError::InvalidOperand, )), - InstructionResult::OpcodeNotFound => Self::Halt(Halt::OpcodeNotFound), + InstructionResult::OpcodeNotFound => Self::Halt(HaltReason::OpcodeNotFound), InstructionResult::CallNotAllowedInsideStatic => { - Self::Halt(Halt::CallNotAllowedInsideStatic) + Self::Halt(HaltReason::CallNotAllowedInsideStatic) } // first call is not static call InstructionResult::StateChangeDuringStaticCall => { - Self::Halt(Halt::StateChangeDuringStaticCall) + Self::Halt(HaltReason::StateChangeDuringStaticCall) + } + InstructionResult::InvalidFEOpcode => Self::Halt(HaltReason::InvalidFEOpcode), + InstructionResult::InvalidJump => Self::Halt(HaltReason::InvalidJump), + InstructionResult::NotActivated => Self::Halt(HaltReason::NotActivated), + InstructionResult::StackUnderflow => Self::Halt(HaltReason::StackUnderflow), + InstructionResult::StackOverflow => Self::Halt(HaltReason::StackOverflow), + InstructionResult::OutOfOffset => Self::Halt(HaltReason::OutOfOffset), + InstructionResult::CreateCollision => Self::Halt(HaltReason::CreateCollision), + InstructionResult::OverflowPayment => Self::Halt(HaltReason::OverflowPayment), // Check for first call is done separately. + InstructionResult::PrecompileError => Self::Halt(HaltReason::PrecompileError), + InstructionResult::NonceOverflow => Self::Halt(HaltReason::NonceOverflow), + InstructionResult::CreateContractSizeLimit => { + Self::Halt(HaltReason::CreateContractSizeLimit) } - InstructionResult::InvalidFEOpcode => Self::Halt(Halt::InvalidFEOpcode), - InstructionResult::InvalidJump => Self::Halt(Halt::InvalidJump), - InstructionResult::NotActivated => Self::Halt(Halt::NotActivated), - InstructionResult::StackUnderflow => Self::Halt(Halt::StackUnderflow), - InstructionResult::StackOverflow => Self::Halt(Halt::StackOverflow), - InstructionResult::OutOfOffset => Self::Halt(Halt::OutOfOffset), - InstructionResult::CreateCollision => Self::Halt(Halt::CreateCollision), - InstructionResult::OverflowPayment => Self::Halt(Halt::OverflowPayment), // Check for first call is done separately. - InstructionResult::PrecompileError => Self::Halt(Halt::PrecompileError), - InstructionResult::NonceOverflow => Self::Halt(Halt::NonceOverflow), - InstructionResult::CreateContractSizeLimit => Self::Halt(Halt::CreateContractSizeLimit), InstructionResult::CreateContractStartingWithEF => { - Self::Halt(Halt::CreateContractSizeLimit) + Self::Halt(HaltReason::CreateContractSizeLimit) + } + InstructionResult::CreateInitCodeSizeLimit => { + Self::Halt(HaltReason::CreateInitCodeSizeLimit) } - InstructionResult::CreateInitCodeSizeLimit => Self::Halt(Halt::CreateInitCodeSizeLimit), InstructionResult::FatalExternalError => Self::FatalExternalError, } } diff --git a/crates/primitives/src/result.rs b/crates/primitives/src/result.rs index 649a9ce95cf..705f90e74d3 100644 --- a/crates/primitives/src/result.rs +++ b/crates/primitives/src/result.rs @@ -23,7 +23,7 @@ pub struct ResultAndState { pub enum ExecutionResult { /// Returned successfully Success { - reason: Eval, + reason: SuccessReason, gas_used: u64, gas_refunded: u64, logs: Vec, @@ -33,7 +33,7 @@ pub enum ExecutionResult { Revert { gas_used: u64, output: Bytes }, /// Reverted for various reasons and spend all gas. Halt { - reason: Halt, + reason: HaltReason, /// Halting will spend all the gas, and will be equal to gas_limit. gas_used: u64, }, @@ -355,7 +355,7 @@ impl fmt::Display for InvalidHeader { /// Reason a transaction successfully completed. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub enum Eval { +pub enum SuccessReason { Stop, Return, SelfDestruct, @@ -365,7 +365,7 @@ pub enum Eval { /// immediately end with all gas being consumed. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub enum Halt { +pub enum HaltReason { OutOfGas(OutOfGasError), OpcodeNotFound, InvalidFEOpcode,