1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
use action_params::ActionParams;
use ethereum_types::Address;
use ethtrie;
use std::fmt;
use ResumeCall;
use ResumeCreate;
#[derive(Debug)]
pub enum TrapKind {
Call(ActionParams),
Create(ActionParams, Address),
}
pub enum TrapError<Call, Create> {
Call(ActionParams, Call),
Create(ActionParams, Address, Create),
}
#[derive(Debug, Clone, PartialEq)]
pub enum Error {
OutOfGas,
BadJumpDestination {
destination: usize,
},
BadInstruction {
instruction: u8,
},
StackUnderflow {
instruction: &'static str,
wanted: usize,
on_stack: usize,
},
OutOfStack {
instruction: &'static str,
wanted: usize,
limit: usize,
},
SubStackUnderflow {
wanted: usize,
on_stack: usize,
},
OutOfSubStack {
wanted: usize,
limit: usize,
},
InvalidSubEntry,
BuiltIn(&'static str),
MutableCallInStaticContext,
InvalidCode,
Internal(String),
Wasm(String),
OutOfBounds,
Reverted,
}
impl From<Box<ethtrie::TrieError>> for Error {
fn from(err: Box<ethtrie::TrieError>) -> Self {
Error::Internal(format!("Internal error: {}", err))
}
}
impl From<ethtrie::TrieError> for Error {
fn from(err: ethtrie::TrieError) -> Self {
Error::Internal(format!("Internal error: {}", err))
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::Error::*;
match *self {
OutOfGas => write!(f, "Out of gas"),
BadJumpDestination { destination } => write!(
f,
"Bad jump destination {:x} (trimmed to usize)",
destination
),
BadInstruction { instruction } => write!(f, "Bad instruction {:x}", instruction),
StackUnderflow {
instruction,
wanted,
on_stack,
} => write!(f, "Stack underflow {} {}/{}", instruction, wanted, on_stack),
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"),
InvalidCode => write!(f, "Invalid code to deploy as a contract"),
Wasm(ref msg) => write!(f, "Internal error: {}", msg),
OutOfBounds => write!(f, "Out of bounds"),
Reverted => write!(f, "Reverted"),
}
}
}
pub type Result<T> = ::std::result::Result<T, Error>;
pub type TrapResult<T, Call, Create> = ::std::result::Result<Result<T>, TrapError<Call, Create>>;
pub type ExecTrapResult<T> = TrapResult<T, Box<dyn ResumeCall>, Box<dyn ResumeCreate>>;
pub type ExecTrapError = TrapError<Box<dyn ResumeCall>, Box<dyn ResumeCreate>>;