sui_sdk_types/
execution_status.rs

1use super::Address;
2use super::Digest;
3use super::Identifier;
4
5/// The status of an executed Transaction
6///
7/// # BCS
8///
9/// The BCS serialized form for this type is defined by the following ABNF:
10///
11/// ```text
12/// execution-status = success / failure
13/// success = %x00
14/// failure = %x01 execution-error (option u64)
15/// ```
16#[derive(Eq, PartialEq, Clone, Debug)]
17#[cfg_attr(
18    feature = "serde",
19    derive(serde_derive::Serialize, serde_derive::Deserialize)
20)]
21#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
22pub enum ExecutionStatus {
23    /// The Transaction successfully executed.
24    Success,
25
26    /// The Transaction didn't execute successfully.
27    ///
28    /// Failed transactions are still committed to the blockchain but any intended effects are
29    /// rolled back to prior to this transaction executing with the caveat that gas objects are
30    /// still smashed and gas usage is still charged.
31    Failure {
32        /// The error encountered during execution.
33        error: ExecutionError,
34        /// The command, if any, during which the error occurred.
35        #[cfg_attr(feature = "proptest", map(|x: Option<u16>| x.map(Into::into)))]
36        command: Option<u64>,
37    },
38}
39
40/// An error that can occur during the execution of a transaction
41///
42/// # BCS
43///
44/// The BCS serialized form for this type is defined by the following ABNF:
45///
46/// ```text
47/// execution-error =  insufficient-gas
48///                 =/ invalid-gas-object
49///                 =/ invariant-violation
50///                 =/ feature-not-yet-supported
51///                 =/ object-too-big
52///                 =/ package-too-big
53///                 =/ circular-object-ownership
54///                 =/ insufficient-coin-balance
55///                 =/ coin-balance-overflow
56///                 =/ publish-error-non-zero-address
57///                 =/ sui-move-verification-error
58///                 =/ move-primitive-runtime-error
59///                 =/ move-abort
60///                 =/ vm-verification-or-deserialization-error
61///                 =/ vm-invariant-violation
62///                 =/ function-not-found
63///                 =/ arity-mismatch
64///                 =/ type-arity-mismatch
65///                 =/ non-entry-function-invoked
66///                 =/ command-argument-error
67///                 =/ type-argument-error
68///                 =/ unused-value-without-drop
69///                 =/ invalid-public-function-return-type
70///                 =/ invalid-transfer-object
71///                 =/ effects-too-large
72///                 =/ publish-upgrade-missing-dependency
73///                 =/ publish-upgrade-dependency-downgrade
74///                 =/ package-upgrade-error
75///                 =/ written-objects-too-large
76///                 =/ certificate-denied
77///                 =/ sui-move-verification-timedout
78///                 =/ consensus-object-operation-not-allowed
79///                 =/ input-object-deleted
80///                 =/ execution-canceled-due-to-consensus-object-congestion
81///                 =/ address-denied-for-coin
82///                 =/ coin-type-global-pause
83///                 =/ execution-canceled-due-to-randomness-unavailable
84///
85/// insufficient-gas                                    = %x00
86/// invalid-gas-object                                  = %x01
87/// invariant-violation                                 = %x02
88/// feature-not-yet-supported                           = %x03
89/// object-too-big                                      = %x04 u64 u64
90/// package-too-big                                     = %x05 u64 u64
91/// circular-object-ownership                           = %x06 address
92/// insufficient-coin-balance                           = %x07
93/// coin-balance-overflow                               = %x08
94/// publish-error-non-zero-address                      = %x09
95/// sui-move-verification-error                         = %x0a
96/// move-primitive-runtime-error                        = %x0b (option move-location)
97/// move-abort                                          = %x0c move-location u64
98/// vm-verification-or-deserialization-error            = %x0d
99/// vm-invariant-violation                              = %x0e
100/// function-not-found                                  = %x0f
101/// arity-mismatch                                      = %x10
102/// type-arity-mismatch                                 = %x11
103/// non-entry-function-invoked                          = %x12
104/// command-argument-error                              = %x13 u16 command-argument-error
105/// type-argument-error                                 = %x14 u16 type-argument-error
106/// unused-value-without-drop                           = %x15 u16 u16
107/// invalid-public-function-return-type                 = %x16 u16
108/// invalid-transfer-object                             = %x17
109/// effects-too-large                                   = %x18 u64 u64
110/// publish-upgrade-missing-dependency                  = %x19
111/// publish-upgrade-dependency-downgrade                = %x1a
112/// package-upgrade-error                               = %x1b package-upgrade-error
113/// written-objects-too-large                           = %x1c u64 u64
114/// certificate-denied                                  = %x1d
115/// sui-move-verification-timedout                      = %x1e
116/// consensus-object-operation-not-allowed                 = %x1f
117/// input-object-deleted                                = %x20
118/// execution-canceled-due-to-consensus-object-congestion = %x21 (vector address)
119/// address-denied-for-coin                             = %x22 address string
120/// coin-type-global-pause                              = %x23 string
121/// execution-canceled-due-to-randomness-unavailable   = %x24
122/// ```
123#[derive(Eq, PartialEq, Clone, Debug)]
124#[cfg_attr(
125    feature = "serde",
126    derive(serde_derive::Serialize, serde_derive::Deserialize)
127)]
128#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
129#[non_exhaustive]
130pub enum ExecutionError {
131    //
132    // General transaction errors
133    //
134    /// Insufficient Gas
135    InsufficientGas,
136    /// Invalid Gas Object.
137    InvalidGasObject,
138    /// Invariant Violation
139    InvariantViolation,
140    /// Attempted to used feature that is not supported yet
141    FeatureNotYetSupported,
142    /// Move object is larger than the maximum allowed size
143    ObjectTooBig {
144        object_size: u64,
145        max_object_size: u64,
146    },
147    /// Package is larger than the maximum allowed size
148    PackageTooBig {
149        object_size: u64,
150        max_object_size: u64,
151    },
152    /// Circular Object Ownership
153    CircularObjectOwnership { object: Address },
154
155    //
156    // Coin errors
157    //
158    /// Insufficient coin balance for requested operation
159    InsufficientCoinBalance,
160    /// Coin balance overflowed an u64
161    CoinBalanceOverflow,
162
163    //
164    // Publish/Upgrade errors
165    //
166    /// Publish Error, Non-zero Address.
167    /// The modules in the package must have their self-addresses set to zero.
168    PublishErrorNonZeroAddress,
169
170    /// Sui Move Bytecode Verification Error.
171    SuiMoveVerificationError,
172
173    //
174    // MoveVm Errors
175    //
176    /// Error from a non-abort instruction.
177    /// Possible causes:
178    ///     Arithmetic error, stack overflow, max value depth, etc."
179    MovePrimitiveRuntimeError { location: Option<MoveLocation> },
180    /// Move runtime abort
181    MoveAbort { location: MoveLocation, code: u64 },
182    /// Bytecode verification error.
183    VmVerificationOrDeserializationError,
184    /// MoveVm invariant violation
185    VmInvariantViolation,
186
187    //
188    // Programmable Transaction Errors
189    //
190    /// Function not found
191    FunctionNotFound,
192    /// Arity mismatch for Move function.
193    /// The number of arguments does not match the number of parameters
194    ArityMismatch,
195    /// Type arity mismatch for Move function.
196    /// Mismatch between the number of actual versus expected type arguments.
197    TypeArityMismatch,
198    /// Non Entry Function Invoked. Move Call must start with an entry function.
199    NonEntryFunctionInvoked,
200    /// Invalid command argument
201    CommandArgumentError {
202        argument: u16,
203        kind: CommandArgumentError,
204    },
205    /// Type argument error
206    TypeArgumentError {
207        /// Index of the problematic type argument
208        type_argument: u16,
209        kind: TypeArgumentError,
210    },
211    /// Unused result without the drop ability.
212    UnusedValueWithoutDrop { result: u16, subresult: u16 },
213    /// Invalid public Move function signature.
214    /// Unsupported return type for return value
215    InvalidPublicFunctionReturnType { index: u16 },
216    /// Invalid Transfer Object, object does not have public transfer.
217    InvalidTransferObject,
218
219    //
220    // Post-execution errors
221    //
222    /// Effects from the transaction are too large
223    EffectsTooLarge { current_size: u64, max_size: u64 },
224
225    /// Publish or Upgrade is missing dependency
226    PublishUpgradeMissingDependency,
227
228    /// Publish or Upgrade dependency downgrade.
229    ///
230    /// Indirect (transitive) dependency of published or upgraded package has been assigned an
231    /// on-chain version that is less than the version required by one of the package's
232    /// transitive dependencies.
233    PublishUpgradeDependencyDowngrade,
234
235    /// Invalid package upgrade
236    PackageUpgradeError { kind: PackageUpgradeError },
237
238    /// Indicates the transaction tried to write objects too large to storage
239    WrittenObjectsTooLarge {
240        object_size: u64,
241        max_object_size: u64,
242    },
243
244    /// Certificate is on the deny list
245    CertificateDenied,
246
247    /// Sui Move Bytecode verification timed out.
248    SuiMoveVerificationTimedout,
249
250    /// The requested consensus object operation is not allowed
251    ConsensusObjectOperationNotAllowed,
252
253    /// Requested consensus object has been deleted
254    InputObjectDeleted,
255
256    /// Certificate is canceled due to congestion on consensus objects
257    ExecutionCanceledDueToConsensusObjectCongestion {
258        #[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=1).lift()))]
259        congested_objects: Vec<Address>,
260    },
261
262    /// Address is denied for this coin type
263    AddressDeniedForCoin { address: Address, coin_type: String },
264
265    /// Coin type is globally paused for use
266    CoinTypeGlobalPause { coin_type: String },
267
268    /// Certificate is canceled because randomness could not be generated this epoch
269    ExecutionCanceledDueToRandomnessUnavailable,
270
271    /// Move vector element (passed to MakeMoveVec) with size {value_size} is larger \
272    /// than the maximum size {max_scaled_size}. Note that this maximum is scaled based on the \
273    /// type of the vector element.
274    MoveVectorElemTooBig {
275        value_size: u64,
276        max_scaled_size: u64,
277    },
278
279    /// Move value (possibly an upgrade ticket or a dev-inspect value) with size {value_size} \
280    /// is larger than the maximum size  {max_scaled_size}. Note that this maximum is scaled based \
281    /// on the type of the value.
282    MoveRawValueTooBig {
283        value_size: u64,
284        max_scaled_size: u64,
285    },
286
287    /// A valid linkage was unable to be determined for the transaction or one of its commands.
288    InvalidLinkage,
289
290    /// Insufficient funds for transaction withdrawal
291    InsufficientFundsForWithdraw,
292
293    /// An input object with non-exclusive write mutability was modified
294    NonExclusiveWriteInputObjectModified { object: Address },
295}
296
297/// Location in move bytecode where an error occurred
298///
299/// # BCS
300///
301/// The BCS serialized form for this type is defined by the following ABNF:
302///
303/// ```text
304/// move-location = address identifier u16 u16 (option identifier)
305/// ```
306#[derive(Eq, PartialEq, Clone, Debug)]
307#[cfg_attr(
308    feature = "serde",
309    derive(serde_derive::Serialize, serde_derive::Deserialize)
310)]
311#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
312pub struct MoveLocation {
313    /// The package id
314    pub package: Address,
315
316    /// The module name
317    pub module: Identifier,
318
319    /// The function index
320    pub function: u16,
321
322    /// Index into the code stream for a jump. The offset is relative to the beginning of
323    /// the instruction stream.
324    pub instruction: u16,
325
326    /// The name of the function if available
327    pub function_name: Option<Identifier>,
328}
329
330/// An error with an argument to a command
331///
332/// # BCS
333///
334/// The BCS serialized form for this type is defined by the following ABNF:
335///
336/// ```text
337/// command-argument-error =  type-mismatch
338///                        =/ invalid-bcs-bytes
339///                        =/ invalid-usage-of-pure-argument
340///                        =/ invalid-argument-to-private-entry-function
341///                        =/ index-out-of-bounds
342///                        =/ secondary-index-out-of-bound
343///                        =/ invalid-result-arity
344///                        =/ invalid-gas-coin-usage
345///                        =/ invalid-value-usage
346///                        =/ invalid-object-by-value
347///                        =/ invalid-object-by-mut-ref
348///                        =/ consensus-object-operation-not-allowed
349///
350/// type-mismatch                               = %x00
351/// invalid-bcs-bytes                           = %x01
352/// invalid-usage-of-pure-argument              = %x02
353/// invalid-argument-to-private-entry-function  = %x03
354/// index-out-of-bounds                         = %x04 u16
355/// secondary-index-out-of-bound                = %x05 u16 u16
356/// invalid-result-arity                        = %x06 u16
357/// invalid-gas-coin-usage                      = %x07
358/// invalid-value-usage                         = %x08
359/// invalid-object-by-value                     = %x09
360/// invalid-object-by-mut-ref                   = %x0a
361/// consensus-object-operation-not-allowed         = %x0b
362/// ```
363#[derive(Eq, PartialEq, Clone, Debug)]
364#[cfg_attr(
365    feature = "serde",
366    derive(serde_derive::Serialize, serde_derive::Deserialize)
367)]
368#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
369#[non_exhaustive]
370pub enum CommandArgumentError {
371    /// The type of the value does not match the expected type
372    TypeMismatch,
373
374    /// The argument cannot be deserialized into a value of the specified type
375    InvalidBcsBytes,
376
377    /// The argument cannot be instantiated from raw bytes
378    InvalidUsageOfPureArgument,
379
380    /// Invalid argument to private entry function.
381    /// Private entry functions cannot take arguments from other Move functions.
382    InvalidArgumentToPrivateEntryFunction,
383
384    /// Out of bounds access to input or results
385    IndexOutOfBounds { index: u16 },
386
387    /// Out of bounds access to subresult
388    SecondaryIndexOutOfBounds { result: u16, subresult: u16 },
389
390    /// Invalid usage of result.
391    /// Expected a single result but found either no return value or multiple.
392    InvalidResultArity { result: u16 },
393
394    /// Invalid usage of Gas coin.
395    /// The Gas coin can only be used by-value with a TransferObjects command.
396    InvalidGasCoinUsage,
397
398    /// Invalid usage of move value.
399    //     Mutably borrowed values require unique usage.
400    //     Immutably borrowed values cannot be taken or borrowed mutably.
401    //     Taken values cannot be used again.
402    InvalidValueUsage,
403
404    /// Immutable objects cannot be passed by-value.
405    InvalidObjectByValue,
406
407    /// Immutable objects cannot be passed by mutable reference, &mut.
408    InvalidObjectByMutRef,
409
410    /// consensus object operations such a wrapping, freezing, or converting to owned are not
411    /// allowed.
412    ConsensusObjectOperationNotAllowed,
413
414    /// Invalid argument arity. Expected a single argument but found a result that expanded to
415    /// multiple arguments.
416    InvalidArgumentArity,
417
418    /// Object passed to TransferObject does not have public transfer, i.e. the `store` ability
419    InvalidTransferObject,
420
421    /// First argument to MakeMoveVec is not an object. If no type is specified for MakeMoveVec,
422    /// all arguments must be the same object type.
423    InvalidMakeMoveVecNonObjectArgument,
424
425    /// Specified argument location does not have a value and cannot be used
426    ArgumentWithoutValue,
427
428    /// Cannot move a borrowed value. The value's type does resulted in this argument usage being
429    /// inferred as a move. This is likely due to the type not having the `copy` ability; although
430    /// in rare cases, it could also be this is the last usage of a value without the `drop`
431    /// ability.
432    CannotMoveBorrowedValue,
433
434    /// Cannot write to an argument location that is still borrowed, and where that borrow is an
435    /// extension of that reference. This is likely due to this argument being used in a Move call
436    /// that returns a reference, and that reference is used in a later command.
437    CannotWriteToExtendedReference,
438
439    /// The argument specified cannot be used as a reference argument in the Move call. Either the
440    /// argument is a mutable reference and it conflicts with another argument to the call, or the
441    /// argument is mutable and another reference extends it and will be used in a later command.
442    InvalidReferenceArgument,
443}
444
445/// An error with a upgrading a package
446///
447/// # BCS
448///
449/// The BCS serialized form for this type is defined by the following ABNF:
450///
451/// ```text
452/// package-upgrade-error = unable-to-fetch-package /
453///                         not-a-package           /
454///                         incompatible-upgrade    /
455///                         digest-does-not-match   /
456///                         unknown-upgrade-policy  /
457///                         package-id-does-not-match
458///
459/// unable-to-fetch-package     = %x00 address
460/// not-a-package               = %x01 address
461/// incompatible-upgrade        = %x02
462/// digest-does-not-match       = %x03 digest
463/// unknown-upgrade-policy      = %x04 u8
464/// package-id-does-not-match   = %x05 address address
465/// ```
466#[derive(Eq, PartialEq, Clone, Debug)]
467#[cfg_attr(
468    feature = "serde",
469    derive(serde_derive::Serialize, serde_derive::Deserialize)
470)]
471#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
472#[non_exhaustive]
473pub enum PackageUpgradeError {
474    /// Unable to fetch package
475    UnableToFetchPackage { package_id: Address },
476
477    /// Object is not a package
478    NotAPackage { object_id: Address },
479
480    /// Package upgrade is incompatible with previous version
481    IncompatibleUpgrade,
482
483    /// Digest in upgrade ticket and computed digest differ
484    DigestDoesNotMatch { digest: Digest },
485
486    /// Upgrade policy is not valid
487    UnknownUpgradePolicy { policy: u8 },
488
489    /// PackageId does not matach PackageId in upgrade ticket
490    PackageIdDoesNotMatch {
491        package_id: Address,
492        ticket_id: Address,
493    },
494}
495
496/// An error with a type argument
497///
498/// # BCS
499///
500/// The BCS serialized form for this type is defined by the following ABNF:
501///
502/// ```text
503/// type-argument-error = type-not-found / constraint-not-satisfied
504/// type-not-found = %x00
505/// constraint-not-satisfied = %x01
506/// ```
507#[derive(Eq, PartialEq, Clone, Copy, Debug)]
508#[cfg_attr(
509    feature = "serde",
510    derive(serde_derive::Serialize, serde_derive::Deserialize)
511)]
512#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
513#[non_exhaustive]
514pub enum TypeArgumentError {
515    /// A type was not found in the module specified
516    TypeNotFound,
517
518    /// A type provided did not match the specified constraint
519    ConstraintNotSatisfied,
520}