From 4d41c3352ecf0365f931f983ecd9120dea91a262 Mon Sep 17 00:00:00 2001 From: Tomusdrw Date: Thu, 14 Jan 2016 02:36:48 +0100 Subject: [PATCH] Adding instruction name to BadInstruction --- src/evm/evm.rs | 8 ++++++-- src/evm/interpreter.rs | 12 +++++++++--- src/executive.rs | 4 ++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/evm/evm.rs b/src/evm/evm.rs index fd87efd32..7f442b9c1 100644 --- a/src/evm/evm.rs +++ b/src/evm/evm.rs @@ -14,9 +14,13 @@ pub enum Error { OutOfGas, /// `BadJumpDestination` is returned when execution tried to move /// to position that wasn't marked with JUMPDEST instruction - BadJumpDestination, + BadJumpDestination { + destination: usize + }, /// `BadInstructions` is returned when given instruction is not supported - BadInstruction, + BadInstruction { + instruction: &'static str, + }, /// `StackUnderflow` when there is not enough stack elements to execute instruction /// First parameter says how many elements were needed and the second how many were actually on Stack StackUnderflow { diff --git a/src/evm/interpreter.rs b/src/evm/interpreter.rs index 3753010f6..955d4a3cc 100644 --- a/src/evm/interpreter.rs +++ b/src/evm/interpreter.rs @@ -243,10 +243,14 @@ impl Interpreter { let info = instructions::get_info(instruction); if !schedule.have_delegate_call && instruction == instructions::DELEGATECALL { - return Err(evm::Error::BadInstruction); + return Err(evm::Error::BadInstruction { + instruction: info.name + }); } if info.tier == instructions::GasPriceTier::InvalidTier { - return Err(evm::Error::BadInstruction); + return Err(evm::Error::BadInstruction { + instruction: info.name + }); } try!(self.verify_instructions_requirements(&info, schedule.stack_limit, stack)); @@ -656,7 +660,9 @@ impl Interpreter { if valid_jump_destinations.contains(&jump) { Ok(jump) } else { - Err(evm::Error::BadJumpDestination) + Err(evm::Error::BadJumpDestination { + destination: jump + }) } } diff --git a/src/executive.rs b/src/executive.rs index ebf5aaf36..5d0e3789a 100644 --- a/src/executive.rs +++ b/src/executive.rs @@ -219,8 +219,8 @@ impl<'a> Executive<'a> { Err(evm::Error::Internal) => Err(ExecutionError::Internal), // TODO [ToDr] BadJumpDestination @debris - how to handle that? Err(evm::Error::OutOfGas) - | Err(evm::Error::BadJumpDestination) - | Err(evm::Error::BadInstruction) + | Err(evm::Error::BadJumpDestination { destination: _ }) + | Err(evm::Error::BadInstruction { instruction: _ }) | Err(evm::Error::StackUnderflow {instruction: _, wanted: _, on_stack: _}) | Err(evm::Error::OutOfStack {instruction: _, wanted: _, limit: _}) => { *self.state = backup;