Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Custom message on invalid sub entry
Browse files Browse the repository at this point in the history
  • Loading branch information
adria0 committed May 29, 2020
1 parent 138dbfc commit ce6d1a3
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ethcore/evm/src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ impl<Cost: CostType> Interpreter<Cost> {
// ignore
},
instructions::BEGINSUB => {
return Err(vm::Error::OutOfGas);
return Err(vm::Error::InvalidSubEntry);
},
instructions::JUMPSUB => {
if self.return_stack.len() >= MAX_SUB_STACK_SIZE {
Expand Down
2 changes: 1 addition & 1 deletion ethcore/evm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ fn test_subs_walk_into_subroutine(factory: super::Factory) {
test_finalize(vm.exec(&mut ext).ok().unwrap())
};

let expected = Result::Err(vm::Error::OutOfGas);
let expected = Result::Err(vm::Error::InvalidSubEntry);
assert_eq!(current, expected);
}

Expand Down
1 change: 1 addition & 0 deletions ethcore/machine/src/executive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ impl<'a> CallCreateExecutive<'a> {
| Err(vm::Error::Reverted)
| Err(vm::Error::SubStackUnderflow {..})
| Err(vm::Error::OutOfSubStack {..})
| Err(vm::Error::InvalidSubEntry)
| Ok(FinalizationResult { apply_state: false, .. }) => {
if let Some(addr) = UNPRUNABLE_PRECOMPILE_ADDRESS {
if un_substate.touched.contains(&addr) {
Expand Down
6 changes: 6 additions & 0 deletions ethcore/trace/src/types/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub enum Error {
SubStackUnderflow,
/// When execution would exceed defined subroutine Stack Limit
OutOfSubStack,
/// When the code walks into a subroutine, that is not allowed
InvalidSubEntry,
/// When builtin contract failed on input data
BuiltIn,
/// Returned on evm internal error. Should never be ignored during development.
Expand All @@ -61,6 +63,7 @@ impl<'a> From<&'a VmError> for Error {
VmError::BadInstruction { .. } => Error::BadInstruction,
VmError::StackUnderflow { .. } => Error::StackUnderflow,
VmError::OutOfStack { .. } => Error::OutOfStack,
VmError::InvalidSubEntry { .. } => Error::InvalidSubEntry,
VmError::BuiltIn { .. } => Error::BuiltIn,
VmError::Wasm { .. } => Error::Wasm,
VmError::Internal(_) => Error::Internal,
Expand Down Expand Up @@ -88,6 +91,7 @@ impl fmt::Display for Error {
BadInstruction => "Bad instruction",
StackUnderflow => "Stack underflow",
OutOfStack => "Out of stack",
InvalidSubEntry => "Invalid subroutine entry",
BuiltIn => "Built-in failed",
Wasm => "Wasm runtime error",
Internal => "Internal error",
Expand Down Expand Up @@ -118,6 +122,7 @@ impl Encodable for Error {
Reverted => 10,
SubStackUnderflow => 11,
OutOfSubStack => 12,
InvalidSubEntry => 13,
};

s.append_internal(&value);
Expand All @@ -142,6 +147,7 @@ impl Decodable for Error {
10 => Ok(Reverted),
11 => Ok(SubStackUnderflow),
12 => Ok(OutOfSubStack),
13 => Ok(InvalidSubEntry),
_ => Err(DecoderError::Custom("Invalid error type")),
}
}
Expand Down
3 changes: 3 additions & 0 deletions ethcore/vm/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ pub enum Error {
/// What was the stack limit
limit: usize
},
/// When the code walks into a subroutine, that is not allowed
InvalidSubEntry,
/// Built-in contract failed on given input
BuiltIn(&'static str),
/// When execution tries to modify the state in static context
Expand Down Expand Up @@ -122,6 +124,7 @@ impl fmt::Display for Error {
OutOfStack { instruction, wanted, limit } => write!(f, "Out of stack {} {}/{}", instruction, wanted, limit),
SubStackUnderflow { wanted, on_stack } => write!(f, "Subroutine stack underflow {}/{}", wanted, on_stack),
OutOfSubStack { wanted, limit } => write!(f, "Out of subroutine stack {}/{}", wanted, limit),
InvalidSubEntry => write!(f,"Invalid subroutine entry"),
BuiltIn(name) => write!(f, "Built-in failed: {}", name),
Internal(ref msg) => write!(f, "Internal error: {}", msg),
MutableCallInStaticContext => write!(f, "Mutable call in static context"),
Expand Down

0 comments on commit ce6d1a3

Please sign in to comment.