More descriptive interpreter errors
This commit is contained in:
parent
dedf340381
commit
7e5de5f5c7
@ -19,9 +19,17 @@ pub enum Error {
|
||||
BadInstruction,
|
||||
/// `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(/*wanted*/usize, /*on_stack*/usize),
|
||||
StackUnderflow {
|
||||
instruction: &'static str,
|
||||
wanted: usize,
|
||||
on_stack: usize
|
||||
},
|
||||
/// When execution would exceed defined Stack Limit
|
||||
OutOfStack(/*wanted*/usize, /*stack_limit*/usize),
|
||||
OutOfStack {
|
||||
instruction: &'static str,
|
||||
wanted: usize,
|
||||
limit: usize
|
||||
},
|
||||
/// Returned on evm internal error. Should never be ignored during development.
|
||||
/// Likely to cause consensus issues.
|
||||
Internal,
|
||||
|
@ -15,7 +15,7 @@ impl Factory {
|
||||
/// Returns native rust evm
|
||||
#[cfg(not(feature = "jit"))]
|
||||
pub fn create() -> Box<Evm> {
|
||||
Box::new(super::interpreter::Interpreter::new())
|
||||
Box::new(super::interpreter::Interpreter)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -626,9 +626,17 @@ impl Interpreter {
|
||||
stack_limit: usize,
|
||||
stack: &Stack<U256>) -> Result<(), evm::Error> {
|
||||
if !stack.has(info.args) {
|
||||
Err(evm::Error::StackUnderflow(info.args, stack.size()))
|
||||
Err(evm::Error::StackUnderflow {
|
||||
instruction: info.name,
|
||||
wanted: info.args,
|
||||
on_stack: stack.size()
|
||||
})
|
||||
} else if stack.size() - info.args + info.ret > stack_limit {
|
||||
Err(evm::Error::OutOfStack(info.ret - info.args, stack_limit))
|
||||
Err(evm::Error::OutOfStack {
|
||||
instruction: info.name,
|
||||
wanted: info.ret - info.args,
|
||||
limit: stack_limit
|
||||
})
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
@ -112,9 +112,9 @@ fn test_stack_underflow() {
|
||||
};
|
||||
|
||||
match err {
|
||||
evm::Error::StackUnderflow(wanted, stack) => {
|
||||
evm::Error::StackUnderflow {instruction: _, wanted, on_stack} => {
|
||||
assert_eq!(wanted, 2);
|
||||
assert_eq!(stack, 0);
|
||||
assert_eq!(on_stack, 0);
|
||||
}
|
||||
_ => {
|
||||
assert!(false, "Expected StackUndeflow")
|
||||
|
@ -221,8 +221,8 @@ impl<'a> Executive<'a> {
|
||||
Err(evm::Error::OutOfGas)
|
||||
| Err(evm::Error::BadJumpDestination)
|
||||
| Err(evm::Error::BadInstruction)
|
||||
| Err(evm::Error::StackUnderflow(_, _))
|
||||
| Err(evm::Error::OutOfStack(_, _)) => {
|
||||
| Err(evm::Error::StackUnderflow {instruction: _, wanted: _, on_stack: _})
|
||||
| Err(evm::Error::OutOfStack {instruction: _, wanted: _, limit: _}) => {
|
||||
*self.state = backup;
|
||||
Ok(Executed {
|
||||
gas: t.gas,
|
||||
|
Loading…
Reference in New Issue
Block a user