Adding instruction name to BadInstruction

This commit is contained in:
Tomusdrw 2016-01-14 02:36:48 +01:00
parent e9cc821969
commit 4d41c3352e
3 changed files with 17 additions and 7 deletions

View File

@ -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 {

View File

@ -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
})
}
}

View File

@ -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;