1use crate::errors::{CanBeAbortion, InvokeError, RuntimeError, SelfError, VmError};
2use crate::internal_prelude::*;
3use crate::system::system_modules::costing::FeeReserveError;
4use crate::transaction::AbortReason;
5
6#[derive(Debug, PartialEq, Eq, Clone, Sbor)]
8pub enum PrepareError {
9 DeserializationError,
12 ValidationError(String),
15 SerializationError,
17 StartFunctionNotAllowed,
19 InvalidImport(InvalidImport),
21 InvalidMemory(InvalidMemory),
23 InvalidTable(InvalidTable),
25 InvalidExportName(String),
27 TooManyTargetsInBrTable,
29 TooManyFunctions,
31 TooManyFunctionParams,
33 TooManyFunctionLocals { max: u32, actual: u32 },
35 TooManyGlobals { max: u32, current: u32 },
37 NoExportSection,
39 MissingExport { export_name: String },
41 NoScryptoAllocExport,
43 NoScryptoFreeExport,
45 RejectedByInstructionMetering { reason: String },
47 RejectedByStackMetering { reason: String },
49 NotInstantiatable { reason: String },
51 NotCompilable,
53 ModuleInfoError(String),
56 WasmParserError(String),
59 Overflow,
61}
62
63#[derive(Debug, PartialEq, Eq, Clone, Sbor)]
64pub enum InvalidImport {
65 ImportNotAllowed(String),
67 ProtocolVersionMismatch {
69 name: String,
70 current_version: u64,
71 expected_version: u64,
72 },
73 InvalidFunctionType(String),
74}
75
76#[derive(Debug, PartialEq, Eq, Clone, Sbor)]
77pub enum InvalidMemory {
78 MissingMemorySection,
80 NoMemoryDefinition,
82 TooManyMemoryDefinition,
84 MemorySizeLimitExceeded,
86 MemoryNotExported,
88}
89
90#[derive(Debug, PartialEq, Eq, Clone, Sbor)]
91pub enum InvalidTable {
92 MoreThanOneTable,
94 InitialTableSizeLimitExceeded,
96}
97
98#[derive(Debug, Clone, PartialEq, Eq, ScryptoSbor)]
100pub enum WasmRuntimeError {
101 UnknownExport(String),
103
104 MemoryAccessError,
106
107 InvalidWasmPointer,
109
110 ExecutionError(String),
112
113 NotImplemented,
115
116 BufferNotFound(BufferId),
118
119 InvalidAddress(DecodeError),
120
121 InvalidString,
123
124 InvalidNodeId,
126
127 InvalidGlobalAddressReservation,
128
129 InvalidReferenceType(u32),
131
132 InvalidAttachedModuleId(u32),
134
135 InvalidObjectStates(DecodeError),
137
138 InvalidAccessRule(DecodeError),
140
141 InvalidModules(DecodeError),
143
144 InvalidTemplateArgs(DecodeError),
145
146 InvalidKeyValueStoreSchema(DecodeError),
147
148 InvalidLockFlags,
150
151 InvalidLogLevel(DecodeError),
153
154 FeeReserveError(FeeReserveError),
156
157 InvalidEventFlags(u32),
158
159 InvalidPackageAddress,
160
161 TooManyBuffers,
162
163 InvalidBlsPublicKey(DecodeError),
164 InvalidBlsSignature(DecodeError),
165 InvalidBlsPublicKeyOrMessage(DecodeError),
166
167 InputDataEmpty,
168
169 InvalidEd25519PublicKey(ParseEd25519PublicKeyError),
170 InvalidEd25519Signature(ParseEd25519SignatureError),
171
172 InvalidSecp256k1PublicKey(ParseSecp256k1PublicKeyError),
173 InvalidSecp256k1Signature(ParseSecp256k1SignatureError),
174
175 InvalidHash(ParseHashError),
176 Secp256k1KeyRecoveryError,
177}
178
179impl SelfError for WasmRuntimeError {
180 fn into_runtime_error(self) -> RuntimeError {
181 RuntimeError::VmError(VmError::Wasm(self))
182 }
183}
184
185impl CanBeAbortion for WasmRuntimeError {
186 fn abortion(&self) -> Option<&AbortReason> {
187 match self {
188 WasmRuntimeError::FeeReserveError(err) => err.abortion(),
189 _ => None,
190 }
191 }
192}
193
194impl fmt::Display for WasmRuntimeError {
195 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
196 write!(f, "{:?}", self)
197 }
198}
199
200#[cfg(not(feature = "alloc"))]
201impl std::error::Error for WasmRuntimeError {}
202
203impl fmt::Display for InvokeError<WasmRuntimeError> {
204 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
205 write!(f, "{:?}", self)
206 }
207}
208
209#[cfg(not(feature = "alloc"))]
210impl std::error::Error for InvokeError<WasmRuntimeError> {}