From 5a12f779c92b9619cb01ee47ab38e9ba4794776a Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Tue, 12 Dec 2023 19:33:29 +0100 Subject: [PATCH] feat: add some conversions to InstructionResult --- crates/interpreter/src/instruction_result.rs | 44 +++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/crates/interpreter/src/instruction_result.rs b/crates/interpreter/src/instruction_result.rs index 0202d380de..9ddf33db39 100644 --- a/crates/interpreter/src/instruction_result.rs +++ b/crates/interpreter/src/instruction_result.rs @@ -1,4 +1,4 @@ -use crate::primitives::{Eval, Halt}; +use crate::primitives::{Eval, Halt, OutOfGasError}; #[repr(u8)] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] @@ -49,6 +49,48 @@ pub enum InstructionResult { FatalExternalError, } +impl From for InstructionResult { + fn from(value: Eval) -> Self { + match value { + Eval::Return => InstructionResult::Return, + Eval::Stop => InstructionResult::Stop, + Eval::SelfDestruct => InstructionResult::SelfDestruct, + } + } +} + +impl From for InstructionResult { + fn from(value: Halt) -> 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, + #[cfg(feature = "optimism")] + Halt::FailedDeposit => Self::FatalExternalError, + } + } +} + impl InstructionResult { /// Returns whether the result is a success. #[inline]