cyfs_base_meta/
evm_def.rs

1use std::borrow::Cow;
2use primitive_types::H256;
3use cyfs_base::ObjectId;
4
5/// Exit reason.
6#[derive(Clone, Debug, Eq, PartialEq)]
7pub enum ExitReason {
8    /// Machine has succeeded.
9    Succeed(ExitSucceed),
10    /// Machine returns a normal EVM error.
11    Error(ExitError),
12    /// Machine encountered an explict revert.
13    Revert(ExitRevert),
14    /// Machine encountered an error that is not supposed to be normal EVM
15    /// errors, such as requiring too much memory to execute.
16    Fatal(ExitFatal),
17}
18
19impl ExitReason {
20    /// Whether the exit is succeeded.
21    pub fn is_succeed(&self) -> bool {
22        match self {
23            Self::Succeed(_) => true,
24            _ => false,
25        }
26    }
27
28    /// Whether the exit is error.
29    pub fn is_error(&self) -> bool {
30        match self {
31            Self::Error(_) => true,
32            _ => false,
33        }
34    }
35
36    /// Whether the exit is revert.
37    pub fn is_revert(&self) -> bool {
38        match self {
39            Self::Revert(_) => true,
40            _ => false,
41        }
42    }
43
44    /// Whether the exit is fatal.
45    pub fn is_fatal(&self) -> bool {
46        match self {
47            Self::Fatal(_) => true,
48            _ => false,
49        }
50    }
51}
52
53/// Exit succeed reason.
54#[derive(Clone, Copy, Debug, Eq, PartialEq)]
55#[cfg_attr(feature = "with-codec", derive(codec::Encode, codec::Decode))]
56#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
57pub enum ExitSucceed {
58    /// Machine encountered an explict stop.
59    Stopped,
60    /// Machine encountered an explict return.
61    Returned,
62    /// Machine encountered an explict suicide.
63    Suicided,
64}
65
66impl From<ExitSucceed> for ExitReason {
67    fn from(s: ExitSucceed) -> Self {
68        Self::Succeed(s)
69    }
70}
71
72/// Exit revert reason.
73#[derive(Clone, Copy, Debug, Eq, PartialEq)]
74pub enum ExitRevert {
75    /// Machine encountered an explict revert.
76    Reverted,
77}
78
79impl From<ExitRevert> for ExitReason {
80    fn from(s: ExitRevert) -> Self {
81        Self::Revert(s)
82    }
83}
84
85/// Exit error reason.
86#[derive(Clone, Debug, Eq, PartialEq)]
87#[cfg_attr(feature = "with-codec", derive(codec::Encode, codec::Decode))]
88#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
89pub enum ExitError {
90    /// Trying to pop from an empty stack.
91    StackUnderflow,
92    /// Trying to push into a stack over stack limit.
93    StackOverflow,
94    /// Jump destination is invalid.
95    InvalidJump,
96    /// An opcode accesses memory region, but the region is invalid.
97    InvalidRange,
98    /// Encountered the designated invalid opcode.
99    DesignatedInvalid,
100    /// Call stack is too deep (runtime).
101    CallTooDeep,
102    /// Create opcode encountered collision (runtime).
103    CreateCollision,
104    /// Create init code exceeds limit (runtime).
105    CreateContractLimit,
106
107    ///	An opcode accesses external information, but the request is off offset
108    ///	limit (runtime).
109    OutOfOffset,
110    /// Execution runs out of gas (runtime).
111    OutOfGas,
112    /// Not enough fund to start the execution (runtime).
113    OutOfFund,
114
115    /// PC underflowed (unused).
116    PCUnderflow,
117    /// Attempt to create an empty account (runtime, unused).
118    CreateEmpty,
119
120    /// Other normal errors.
121    Other(Cow<'static, str>),
122}
123
124impl From<ExitError> for ExitReason {
125    fn from(s: ExitError) -> Self {
126        Self::Error(s)
127    }
128}
129
130/// Exit fatal reason.
131#[derive(Clone, Debug, Eq, PartialEq)]
132#[cfg_attr(feature = "with-codec", derive(codec::Encode, codec::Decode))]
133#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
134pub enum ExitFatal {
135    /// The operation is not supported.
136    NotSupported,
137    /// The trap (interrupt) is unhandled.
138    UnhandledInterrupt,
139    /// The environment explictly set call errors as fatal error.
140    CallErrorAsFatal(ExitError),
141
142    /// Other fatal errors.
143    Other(Cow<'static, str>),
144}
145
146impl From<ExitFatal> for ExitReason {
147    fn from(s: ExitFatal) -> Self {
148        Self::Fatal(s)
149    }
150}
151
152extern crate alloc;
153
154pub type Bytes = alloc::vec::Vec<u8>;
155
156#[derive(Clone, Debug, PartialEq, Eq)]
157pub struct Log {
158    pub address: ObjectId,
159    pub topics: Vec<H256>,
160    pub data: Bytes,
161}