Skip to main content

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    /// The consensus commit timestamp is after the transaction's max_timestamp
297    TransactionExpired,
298}
299
300/// Location in move bytecode where an error occurred
301///
302/// # BCS
303///
304/// The BCS serialized form for this type is defined by the following ABNF:
305///
306/// ```text
307/// move-location = address identifier u16 u16 (option identifier)
308/// ```
309#[derive(Eq, PartialEq, Clone, Debug)]
310#[cfg_attr(
311    feature = "serde",
312    derive(serde_derive::Serialize, serde_derive::Deserialize)
313)]
314#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
315pub struct MoveLocation {
316    /// The package id
317    pub package: Address,
318
319    /// The module name
320    pub module: Identifier,
321
322    /// The function index
323    pub function: u16,
324
325    /// Index into the code stream for a jump. The offset is relative to the beginning of
326    /// the instruction stream.
327    pub instruction: u16,
328
329    /// The name of the function if available
330    pub function_name: Option<Identifier>,
331}
332
333/// An error with an argument to a command
334///
335/// # BCS
336///
337/// The BCS serialized form for this type is defined by the following ABNF:
338///
339/// ```text
340/// command-argument-error =  type-mismatch
341///                        =/ invalid-bcs-bytes
342///                        =/ invalid-usage-of-pure-argument
343///                        =/ invalid-argument-to-private-entry-function
344///                        =/ index-out-of-bounds
345///                        =/ secondary-index-out-of-bound
346///                        =/ invalid-result-arity
347///                        =/ invalid-gas-coin-usage
348///                        =/ invalid-value-usage
349///                        =/ invalid-object-by-value
350///                        =/ invalid-object-by-mut-ref
351///                        =/ consensus-object-operation-not-allowed
352///
353/// type-mismatch                               = %x00
354/// invalid-bcs-bytes                           = %x01
355/// invalid-usage-of-pure-argument              = %x02
356/// invalid-argument-to-private-entry-function  = %x03
357/// index-out-of-bounds                         = %x04 u16
358/// secondary-index-out-of-bound                = %x05 u16 u16
359/// invalid-result-arity                        = %x06 u16
360/// invalid-gas-coin-usage                      = %x07
361/// invalid-value-usage                         = %x08
362/// invalid-object-by-value                     = %x09
363/// invalid-object-by-mut-ref                   = %x0a
364/// consensus-object-operation-not-allowed         = %x0b
365/// ```
366#[derive(Eq, PartialEq, Clone, Debug)]
367#[cfg_attr(
368    feature = "serde",
369    derive(serde_derive::Serialize, serde_derive::Deserialize)
370)]
371#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
372#[non_exhaustive]
373pub enum CommandArgumentError {
374    /// The type of the value does not match the expected type
375    TypeMismatch,
376
377    /// The argument cannot be deserialized into a value of the specified type
378    InvalidBcsBytes,
379
380    /// The argument cannot be instantiated from raw bytes
381    InvalidUsageOfPureArgument,
382
383    /// Invalid argument to private entry function.
384    /// Private entry functions cannot take arguments from other Move functions.
385    InvalidArgumentToPrivateEntryFunction,
386
387    /// Out of bounds access to input or results
388    IndexOutOfBounds { index: u16 },
389
390    /// Out of bounds access to subresult
391    SecondaryIndexOutOfBounds { result: u16, subresult: u16 },
392
393    /// Invalid usage of result.
394    /// Expected a single result but found either no return value or multiple.
395    InvalidResultArity { result: u16 },
396
397    /// Invalid usage of Gas coin.
398    /// The Gas coin can only be used by-value with a TransferObjects command.
399    InvalidGasCoinUsage,
400
401    /// Invalid usage of move value.
402    //     Mutably borrowed values require unique usage.
403    //     Immutably borrowed values cannot be taken or borrowed mutably.
404    //     Taken values cannot be used again.
405    InvalidValueUsage,
406
407    /// Immutable objects cannot be passed by-value.
408    InvalidObjectByValue,
409
410    /// Immutable objects cannot be passed by mutable reference, &mut.
411    InvalidObjectByMutRef,
412
413    /// consensus object operations such a wrapping, freezing, or converting to owned are not
414    /// allowed.
415    ConsensusObjectOperationNotAllowed,
416
417    /// Invalid argument arity. Expected a single argument but found a result that expanded to
418    /// multiple arguments.
419    InvalidArgumentArity,
420
421    /// Object passed to TransferObject does not have public transfer, i.e. the `store` ability
422    InvalidTransferObject,
423
424    /// First argument to MakeMoveVec is not an object. If no type is specified for MakeMoveVec,
425    /// all arguments must be the same object type.
426    InvalidMakeMoveVecNonObjectArgument,
427
428    /// Specified argument location does not have a value and cannot be used
429    ArgumentWithoutValue,
430
431    /// Cannot move a borrowed value. The value's type does resulted in this argument usage being
432    /// inferred as a move. This is likely due to the type not having the `copy` ability; although
433    /// in rare cases, it could also be this is the last usage of a value without the `drop`
434    /// ability.
435    CannotMoveBorrowedValue,
436
437    /// Cannot write to an argument location that is still borrowed, and where that borrow is an
438    /// extension of that reference. This is likely due to this argument being used in a Move call
439    /// that returns a reference, and that reference is used in a later command.
440    CannotWriteToExtendedReference,
441
442    /// The argument specified cannot be used as a reference argument in the Move call. Either the
443    /// argument is a mutable reference and it conflicts with another argument to the call, or the
444    /// argument is mutable and another reference extends it and will be used in a later command.
445    InvalidReferenceArgument,
446
447    /// Invalid usage of TxContext in the function signature. TxContext can only be used by
448    /// reference, `&TxContext` or `&mut TxContext`. If used mutably, it must be the only
449    /// TxContext parameter, and TxContext can never be returned from a Move call.
450    InvalidTxContext,
451}
452
453/// An error with a upgrading a package
454///
455/// # BCS
456///
457/// The BCS serialized form for this type is defined by the following ABNF:
458///
459/// ```text
460/// package-upgrade-error = unable-to-fetch-package /
461///                         not-a-package           /
462///                         incompatible-upgrade    /
463///                         digest-does-not-match   /
464///                         unknown-upgrade-policy  /
465///                         package-id-does-not-match
466///
467/// unable-to-fetch-package     = %x00 address
468/// not-a-package               = %x01 address
469/// incompatible-upgrade        = %x02
470/// digest-does-not-match       = %x03 digest
471/// unknown-upgrade-policy      = %x04 u8
472/// package-id-does-not-match   = %x05 address address
473/// ```
474#[derive(Eq, PartialEq, Clone, Debug)]
475#[cfg_attr(
476    feature = "serde",
477    derive(serde_derive::Serialize, serde_derive::Deserialize)
478)]
479#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
480#[non_exhaustive]
481pub enum PackageUpgradeError {
482    /// Unable to fetch package
483    UnableToFetchPackage { package_id: Address },
484
485    /// Object is not a package
486    NotAPackage { object_id: Address },
487
488    /// Package upgrade is incompatible with previous version
489    IncompatibleUpgrade,
490
491    /// Digest in upgrade ticket and computed digest differ
492    DigestDoesNotMatch { digest: Digest },
493
494    /// Upgrade policy is not valid
495    UnknownUpgradePolicy { policy: u8 },
496
497    /// PackageId does not matach PackageId in upgrade ticket
498    PackageIdDoesNotMatch {
499        package_id: Address,
500        ticket_id: Address,
501    },
502}
503
504/// An error with a type argument
505///
506/// # BCS
507///
508/// The BCS serialized form for this type is defined by the following ABNF:
509///
510/// ```text
511/// type-argument-error = type-not-found / constraint-not-satisfied
512/// type-not-found = %x00
513/// constraint-not-satisfied = %x01
514/// ```
515#[derive(Eq, PartialEq, Clone, Copy, Debug)]
516#[cfg_attr(
517    feature = "serde",
518    derive(serde_derive::Serialize, serde_derive::Deserialize)
519)]
520#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
521#[non_exhaustive]
522pub enum TypeArgumentError {
523    /// A type was not found in the module specified
524    TypeNotFound,
525
526    /// A type provided did not match the specified constraint
527    ConstraintNotSatisfied,
528}