diff --git a/src/evm/evm.rs b/src/evm/evm.rs index 7f442b9c1..9d5195469 100644 --- a/src/evm/evm.rs +++ b/src/evm/evm.rs @@ -19,7 +19,7 @@ pub enum Error { }, /// `BadInstructions` is returned when given instruction is not supported BadInstruction { - instruction: &'static str, + instruction: u8, }, /// `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 diff --git a/src/evm/instructions.rs b/src/evm/instructions.rs index d30c4ed3a..4325ae0fc 100644 --- a/src/evm/instructions.rs +++ b/src/evm/instructions.rs @@ -242,7 +242,7 @@ pub fn get_info (instruction: Instruction) -> InstructionInfo { RETURN => InstructionInfo::new("RETURN", 0, 2, 0, true, GasPriceTier::ZeroTier), DELEGATECALL => InstructionInfo::new("DELEGATECALL", 0, 6, 1, true, GasPriceTier::SpecialTier), SUICIDE => InstructionInfo::new("SUICIDE", 0, 1, 0, true, GasPriceTier::ZeroTier), - _ => panic!(format!("Undefined instruction: {}", instruction)) + _ => InstructionInfo::new("INVALID_INSTRUCTION", 0, 0, 0, false, GasPriceTier::InvalidTier) } } diff --git a/src/evm/interpreter.rs b/src/evm/interpreter.rs index 955d4a3cc..e3d3511cd 100644 --- a/src/evm/interpreter.rs +++ b/src/evm/interpreter.rs @@ -244,12 +244,12 @@ impl Interpreter { if !schedule.have_delegate_call && instruction == instructions::DELEGATECALL { return Err(evm::Error::BadInstruction { - instruction: info.name + instruction: instruction }); } if info.tier == instructions::GasPriceTier::InvalidTier { return Err(evm::Error::BadInstruction { - instruction: info.name + instruction: instruction }); } @@ -608,7 +608,7 @@ impl Interpreter { stack.push(ext.env_info().gas_limit.clone()); }, _ => { - self.exec_stack_instruction(instruction, stack); + try!(self.exec_stack_instruction(instruction, stack)); } }; Ok(InstructionResult::AdditionalGasCost(U256::zero())) @@ -678,7 +678,7 @@ impl Interpreter { } } - fn exec_stack_instruction(&self, instruction: Instruction, stack : &mut Stack) { + fn exec_stack_instruction(&self, instruction: Instruction, stack : &mut Stack) -> Result<(), evm::Error> { match instruction { instructions::DUP1...instructions::DUP16 => { let position = instructions::get_dup_position(instruction); @@ -772,8 +772,13 @@ impl Interpreter { // TODO instructions::ADDMOD => {}, // TODO instructions::MULMOD => {}, // TODO instructions::SIGNEXTEND => {}, - _ => panic!(format!("Unknown stack instruction: {:x}", instruction)) + _ => { + return Err(evm::Error::BadInstruction { + instruction: instruction + }); + } } + Ok(()) } fn find_jump_destinations(&self, code : &Bytes) -> HashSet {