Skip to content

Commit

Permalink
feat: Add all internals results to Halt (bluealloy#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
rakita authored Mar 9, 2023
1 parent d8dc652 commit dd0e227
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
18 changes: 11 additions & 7 deletions crates/interpreter/src/instruction_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub enum SuccessOrHalt {
Halt(Halt),
FatalExternalError,
// this is internal opcode.
Internal,
InternalContinue,
}

impl SuccessOrHalt {
Expand Down Expand Up @@ -91,13 +91,13 @@ impl SuccessOrHalt {
impl From<InstructionResult> for SuccessOrHalt {
fn from(result: InstructionResult) -> Self {
match result {
InstructionResult::Continue => Self::Internal, // used only in interpreter loop
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::Revert => Self::Revert,
InstructionResult::CallTooDeep => Self::Internal, // not gonna happen for first call
InstructionResult::OutOfFund => Self::Internal, // Check for first call is done separately.
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(
revm_primitives::OutOfGasError::BasicOutOfGas,
)),
Expand All @@ -114,16 +114,20 @@ impl From<InstructionResult> for SuccessOrHalt {
revm_primitives::OutOfGasError::InvalidOperand,
)),
InstructionResult::OpcodeNotFound => Self::Halt(Halt::OpcodeNotFound),
InstructionResult::CallNotAllowedInsideStatic => Self::Internal, // first call is not static call
InstructionResult::StateChangeDuringStaticCall => Self::Internal,
InstructionResult::CallNotAllowedInsideStatic => {
Self::Halt(Halt::CallNotAllowedInsideStatic)
} // first call is not static call
InstructionResult::StateChangeDuringStaticCall => {
Self::Halt(Halt::StateChangeDuringStaticCall)
}
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::Internal, // Check for first call is done separately.
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),
Expand Down
8 changes: 7 additions & 1 deletion crates/primitives/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ pub enum Halt {
StackOverflow,
OutOfOffset,
CreateCollision,
OverflowPayment,
PrecompileError,
NonceOverflow,
/// Create init code size exceeds limit (runtime).
Expand All @@ -149,6 +148,13 @@ pub enum Halt {
CreateContractStartingWithEF,
/// EIP-3860: Limit and meter initcode. Initcode size limit exceeded.
CreateInitcodeSizeLimit,

/* Internal Halts that can be only found inside Inspector */
OverflowPayment,
StateChangeDuringStaticCall,
CallNotAllowedInsideStatic,
OutOfFund,
CallTooDeep,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/evm_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> Transact<DB::Error>
SuccessOrHalt::FatalExternalError => {
return Err(EVMError::Database(self.data.error.take().unwrap()))
}
SuccessOrHalt::Internal => {
SuccessOrHalt::InternalContinue => {
panic!("Internal return flags should remain internal {exit_reason:?}")
}
};
Expand Down

0 comments on commit dd0e227

Please sign in to comment.