Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add some conversions to InstructionResult #910

Merged
merged 1 commit into from
Dec 14, 2023
Merged
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
44 changes: 43 additions & 1 deletion crates/interpreter/src/instruction_result.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -49,6 +49,48 @@ pub enum InstructionResult {
FatalExternalError,
}

impl From<Eval> for InstructionResult {
fn from(value: Eval) -> Self {
match value {
Eval::Return => InstructionResult::Return,
Eval::Stop => InstructionResult::Stop,
Eval::SelfDestruct => InstructionResult::SelfDestruct,
}
}
}

impl From<Halt> 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,
}
Comment on lines +88 to +89
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no equivalent for this

}
}

impl InstructionResult {
/// Returns whether the result is a success.
#[inline]
Expand Down
Loading