From d439e863f77ad8b5709bcddf575d25c8f9bea4a9 Mon Sep 17 00:00:00 2001 From: Tim Zakian <2895723+tzakian@users.noreply.github.com> Date: Thu, 13 Jun 2024 15:39:00 -0700 Subject: [PATCH] [move] Add more enums tests (#18241) ## Description Adds some more tests for enums in Move ## Test plan Added a bunch new tests. --- .../tests/enums/enum_with_key_only.exp | 17 +++ .../tests/enums/enum_with_key_only.mvir | 45 +++++++ .../enums/enum_with_key_only_uid_field.exp | 17 +++ .../enums/enum_with_key_only_uid_field.mvir | 53 ++++++++ .../tests/enums/enum_with_key_store.exp | 32 +++++ .../tests/enums/enum_with_key_store.mvir | 106 +++++++++++++++ .../enums/enum_with_key_store_uid_field.exp | 32 +++++ .../enums/enum_with_key_store_uid_field.mvir | 122 ++++++++++++++++++ .../tests/enums/enum_with_key_only.exp | 5 + .../tests/enums/enum_with_key_only.mvir | 11 ++ .../enums/enum_with_key_only_uid_field.exp | 5 + .../enums/enum_with_key_only_uid_field.mvir | 13 ++ ...num_with_key_only_uid_field_version_48.exp | 5 + ...um_with_key_only_uid_field_version_48.mvir | 14 ++ .../enums/enum_with_key_only_version_48.exp | 5 + .../enums/enum_with_key_only_version_48.mvir | 12 ++ .../tests/enums/enum_with_key_store.exp | 5 + .../tests/enums/enum_with_key_store.mvir | 11 ++ .../enums/enum_with_key_store_uid_field.exp | 5 + .../enums/enum_with_key_store_uid_field.mvir | 13 ++ ...um_with_key_store_uid_field_version_48.exp | 5 + ...m_with_key_store_uid_field_version_48.mvir | 14 ++ .../enums/enum_with_key_store_version_48.exp | 5 + .../enums/enum_with_key_store_version_48.mvir | 12 ++ .../src/struct_with_key_verifier.rs | 16 ++- 25 files changed, 579 insertions(+), 1 deletion(-) create mode 100644 crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_only.exp create mode 100644 crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_only.mvir create mode 100644 crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_only_uid_field.exp create mode 100644 crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_only_uid_field.mvir create mode 100644 crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_store.exp create mode 100644 crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_store.mvir create mode 100644 crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_store_uid_field.exp create mode 100644 crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_store_uid_field.mvir create mode 100644 crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only.exp create mode 100644 crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only.mvir create mode 100644 crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only_uid_field.exp create mode 100644 crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only_uid_field.mvir create mode 100644 crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only_uid_field_version_48.exp create mode 100644 crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only_uid_field_version_48.mvir create mode 100644 crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only_version_48.exp create mode 100644 crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only_version_48.mvir create mode 100644 crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store.exp create mode 100644 crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store.mvir create mode 100644 crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store_uid_field.exp create mode 100644 crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store_uid_field.mvir create mode 100644 crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store_uid_field_version_48.exp create mode 100644 crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store_uid_field_version_48.mvir create mode 100644 crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store_version_48.exp create mode 100644 crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store_version_48.mvir diff --git a/crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_only.exp b/crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_only.exp new file mode 100644 index 0000000000000..0d17cff248fa2 --- /dev/null +++ b/crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_only.exp @@ -0,0 +1,17 @@ +processed 6 tasks + +task 1 'publish'. lines 6-37: +Error: Transaction Effects Status: Sui Move Bytecode Verification Error. Please run the Sui Move Verifier for more information. +Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: SuiMoveVerificationError, source: Some("Enum X cannot have the 'key' ability. Enums cannot have the 'key' ability."), command: Some(0) } } + +task 2 'set-address'. lines 39-39: +Error: INVALID TEST. Unknown object, object(1,0) + +task 3 'run'. lines 41-41: +Error: Error checking transaction input objects: DependentPackageNotFound { package_id: 0x0000000000000000000000000000000000000000000000000000000000000000 } + +task 4 'run'. lines 43-43: +Error: Error checking transaction input objects: DependentPackageNotFound { package_id: 0x0000000000000000000000000000000000000000000000000000000000000000 } + +task 5 'run'. lines 45-45: +Error: Error checking transaction input objects: DependentPackageNotFound { package_id: 0x0000000000000000000000000000000000000000000000000000000000000000 } diff --git a/crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_only.mvir b/crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_only.mvir new file mode 100644 index 0000000000000..8507571d29a29 --- /dev/null +++ b/crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_only.mvir @@ -0,0 +1,45 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +//# init --addresses test=0x0 + +//# publish +module 0x0.f { + import 0x2.transfer; + + enum X has key { + A { } + } + + public transfer() { + let x: Self.X; + label l0: + x = X.A { }; + transfer.transfer(move(x), 0x0); + return; + } + + public share() { + let x: Self.X; + label l0: + x = X.A { }; + transfer.share_object(move(x)); + return; + } + + public freezer() { + let x: Self.X; + label l0: + x = X.A { }; + transfer.freeze_object(move(x)); + return; + } +} + +//# set-address test object(1,0) + +//# run test::f::transfer + +//# run test::f::share + +//# run test::f::freezer diff --git a/crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_only_uid_field.exp b/crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_only_uid_field.exp new file mode 100644 index 0000000000000..cb3c93e44d27a --- /dev/null +++ b/crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_only_uid_field.exp @@ -0,0 +1,17 @@ +processed 6 tasks + +task 1 'publish'. lines 6-45: +Error: Transaction Effects Status: Sui Move Bytecode Verification Error. Please run the Sui Move Verifier for more information. +Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: SuiMoveVerificationError, source: Some("Enum X cannot have the 'key' ability. Enums cannot have the 'key' ability."), command: Some(0) } } + +task 2 'set-address'. lines 47-47: +Error: INVALID TEST. Unknown object, object(1,0) + +task 3 'run'. lines 49-49: +Error: Error checking transaction input objects: DependentPackageNotFound { package_id: 0x0000000000000000000000000000000000000000000000000000000000000000 } + +task 4 'run'. lines 51-51: +Error: Error checking transaction input objects: DependentPackageNotFound { package_id: 0x0000000000000000000000000000000000000000000000000000000000000000 } + +task 5 'run'. lines 53-53: +Error: Error checking transaction input objects: DependentPackageNotFound { package_id: 0x0000000000000000000000000000000000000000000000000000000000000000 } diff --git a/crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_only_uid_field.mvir b/crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_only_uid_field.mvir new file mode 100644 index 0000000000000..4ace5169c957b --- /dev/null +++ b/crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_only_uid_field.mvir @@ -0,0 +1,53 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +//# init --addresses test=0x0 + +//# publish +module 0x0.f { + import 0x2.transfer; + import 0x2.object; + import 0x2.tx_context; + + enum X has key { + A { id: object.UID } + } + + public transfer(ctx: &mut tx_context.TxContext) { + let x: Self.X; + let id: object.UID; + label l0: + id = object.new(move(ctx)); + x = X.A { id: move(id) }; + transfer.transfer(move(x), 0x0); + return; + } + + public share(ctx: &mut tx_context.TxContext) { + let x: Self.X; + let id: object.UID; + label l0: + id = object.new(move(ctx)); + x = X.A { id: move(id) }; + transfer.share_object(move(x)); + return; + } + + public freezer(ctx: &mut tx_context.TxContext) { + let x: Self.X; + let id: object.UID; + label l0: + id = object.new(move(ctx)); + x = X.A { id: move(id) }; + transfer.freeze_object(move(x)); + return; + } +} + +//# set-address test object(1,0) + +//# run test::f::transfer + +//# run test::f::share + +//# run test::f::freezer diff --git a/crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_store.exp b/crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_store.exp new file mode 100644 index 0000000000000..ce1c629c6755d --- /dev/null +++ b/crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_store.exp @@ -0,0 +1,32 @@ +processed 11 tasks + +task 1 'publish'. lines 6-88: +Error: Transaction Effects Status: Sui Move Bytecode Verification Error. Please run the Sui Move Verifier for more information. +Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: SuiMoveVerificationError, source: Some("Enum X cannot have the 'key' ability. Enums cannot have the 'key' ability."), command: Some(0) } } + +task 2 'set-address'. lines 90-90: +Error: INVALID TEST. Unknown object, object(1,0) + +task 3 'run'. lines 92-92: +Error: Error checking transaction input objects: DependentPackageNotFound { package_id: 0x0000000000000000000000000000000000000000000000000000000000000000 } + +task 4 'run'. lines 94-94: +Error: Error checking transaction input objects: DependentPackageNotFound { package_id: 0x0000000000000000000000000000000000000000000000000000000000000000 } + +task 5 'run'. lines 96-96: +Error: Error checking transaction input objects: DependentPackageNotFound { package_id: 0x0000000000000000000000000000000000000000000000000000000000000000 } + +task 6 'run'. lines 98-98: +Error: Error checking transaction input objects: DependentPackageNotFound { package_id: 0x0000000000000000000000000000000000000000000000000000000000000000 } + +task 7 'run'. lines 100-100: +Error: Error checking transaction input objects: DependentPackageNotFound { package_id: 0x0000000000000000000000000000000000000000000000000000000000000000 } + +task 8 'run'. lines 102-102: +Error: Error checking transaction input objects: DependentPackageNotFound { package_id: 0x0000000000000000000000000000000000000000000000000000000000000000 } + +task 9 'run'. lines 104-104: +Error: Error checking transaction input objects: DependentPackageNotFound { package_id: 0x0000000000000000000000000000000000000000000000000000000000000000 } + +task 10 'run'. lines 106-106: +Error: Error checking transaction input objects: DependentPackageNotFound { package_id: 0x0000000000000000000000000000000000000000000000000000000000000000 } diff --git a/crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_store.mvir b/crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_store.mvir new file mode 100644 index 0000000000000..2c9b2dfdc04e4 --- /dev/null +++ b/crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_store.mvir @@ -0,0 +1,106 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +//# init --addresses test=0x0 + +//# publish +module 0x0.f { + import 0x2.transfer; + import 0x2.object; + import 0x2.dynamic_field; + import 0x2.dynamic_object_field; + import 0x2.tx_context; + + enum X has store, key { + A { } + } + + public transfer() { + let x: Self.X; + label l0: + x = X.A { }; + transfer.transfer(move(x), 0x0); + return; + } + + public share() { + let x: Self.X; + label l0: + x = X.A { }; + transfer.share_object(move(x)); + return; + } + + public public_transfer() { + let x: Self.X; + label l0: + x = X.A { }; + transfer.public_transfer(move(x), 0x0); + return; + } + + public public_share() { + let x: Self.X; + label l0: + x = X.A { }; + transfer.public_share_object(move(x)); + return; + } + + public freezer() { + let x: Self.X; + label l0: + x = X.A { }; + transfer.freeze_object(move(x)); + return; + } + + public public_freezer() { + let x: Self.X; + label l0: + x = X.A { }; + transfer.public_freeze_object(move(x)); + return; + } + + public add_as_df(ctx: &mut tx_context.TxContext) { + let x: Self.X; + let id: object.UID; + label l0: + id = object.new(move(ctx)); + x = X.A { }; + dynamic_field.add(&mut id, 0, move(x)); + object.delete(move(id)); + return; + + } + + public dof_add(ctx: &mut tx_context.TxContext) { + let x: Self.X; + let id: object.UID; + label l0: + id = object.new(move(ctx)); + x = X.A { }; + dynamic_object_field.add(&mut id, 0, move(x)); + object.delete(move(id)); + return; + } +} + +//# set-address test object(1,0) + +//# run test::f::transfer + +//# run test::f::share + +//# run test::f::public_transfer + +//# run test::f::public_share + +//# run test::f::freezer + +//# run test::f::public_freezer + +//# run test::f::add_df + +//# run test::f::add_dof diff --git a/crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_store_uid_field.exp b/crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_store_uid_field.exp new file mode 100644 index 0000000000000..60dc6389ac3b8 --- /dev/null +++ b/crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_store_uid_field.exp @@ -0,0 +1,32 @@ +processed 11 tasks + +task 1 'publish'. lines 6-104: +Error: Transaction Effects Status: Sui Move Bytecode Verification Error. Please run the Sui Move Verifier for more information. +Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: SuiMoveVerificationError, source: Some("Enum X cannot have the 'key' ability. Enums cannot have the 'key' ability."), command: Some(0) } } + +task 2 'set-address'. lines 106-106: +Error: INVALID TEST. Unknown object, object(1,0) + +task 3 'run'. lines 108-108: +Error: Error checking transaction input objects: DependentPackageNotFound { package_id: 0x0000000000000000000000000000000000000000000000000000000000000000 } + +task 4 'run'. lines 110-110: +Error: Error checking transaction input objects: DependentPackageNotFound { package_id: 0x0000000000000000000000000000000000000000000000000000000000000000 } + +task 5 'run'. lines 112-112: +Error: Error checking transaction input objects: DependentPackageNotFound { package_id: 0x0000000000000000000000000000000000000000000000000000000000000000 } + +task 6 'run'. lines 114-114: +Error: Error checking transaction input objects: DependentPackageNotFound { package_id: 0x0000000000000000000000000000000000000000000000000000000000000000 } + +task 7 'run'. lines 116-116: +Error: Error checking transaction input objects: DependentPackageNotFound { package_id: 0x0000000000000000000000000000000000000000000000000000000000000000 } + +task 8 'run'. lines 118-118: +Error: Error checking transaction input objects: DependentPackageNotFound { package_id: 0x0000000000000000000000000000000000000000000000000000000000000000 } + +task 9 'run'. lines 120-120: +Error: Error checking transaction input objects: DependentPackageNotFound { package_id: 0x0000000000000000000000000000000000000000000000000000000000000000 } + +task 10 'run'. lines 122-122: +Error: Error checking transaction input objects: DependentPackageNotFound { package_id: 0x0000000000000000000000000000000000000000000000000000000000000000 } diff --git a/crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_store_uid_field.mvir b/crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_store_uid_field.mvir new file mode 100644 index 0000000000000..7affe6d794870 --- /dev/null +++ b/crates/sui-adapter-transactional-tests/tests/enums/enum_with_key_store_uid_field.mvir @@ -0,0 +1,122 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +//# init --addresses test=0x0 + +//# publish +module 0x0.f { + import 0x2.transfer; + import 0x2.object; + import 0x2.dynamic_field; + import 0x2.dynamic_object_field; + import 0x2.tx_context; + + enum X has store, key { + A { id: object.UID } + } + + public transfer(ctx: &mut tx_context.TxContext) { + let x: Self.X; + let id: object.UID; + label l0: + id = object.new(move(ctx)); + x = X.A { id: move(id) }; + transfer.transfer(move(x), 0x0); + return; + } + + public share(ctx: &mut tx_context.TxContext) { + let x: Self.X; + let id: object.UID; + label l0: + id = object.new(move(ctx)); + x = X.A { id: move(id) }; + transfer.share_object(move(x)); + return; + } + + public public_transfer(ctx: &mut tx_context.TxContext) { + let x: Self.X; + let id: object.UID; + label l0: + id = object.new(move(ctx)); + x = X.A { id: move(id) }; + transfer.public_transfer(move(x), 0x0); + return; + } + + public public_share(ctx: &mut tx_context.TxContext) { + let x: Self.X; + let id: object.UID; + label l0: + id = object.new(move(ctx)); + x = X.A { id: move(id) }; + transfer.public_share_object(move(x)); + return; + } + + public freezer(ctx: &mut tx_context.TxContext) { + let x: Self.X; + let id: object.UID; + label l0: + id = object.new(move(ctx)); + x = X.A { id: move(id) }; + transfer.freeze_object(move(x)); + return; + } + + public public_freezer(ctx: &mut tx_context.TxContext) { + let x: Self.X; + let id: object.UID; + label l0: + id = object.new(move(ctx)); + x = X.A { id: move(id) }; + transfer.public_freeze_object(move(x)); + return; + } + + public add_as_df(ctx: &mut tx_context.TxContext) { + let x: Self.X; + let parent_id: object.UID; + let id: object.UID; + label l0: + parent_id = object.new(copy(ctx)); + id = object.new(move(ctx)); + x = X.A { id: move(id) }; + dynamic_field.add(&mut parent_id, 0, move(x)); + object.delete(move(parent_id)); + return; + + } + + public dof_add(ctx: &mut tx_context.TxContext) { + let x: Self.X; + let parent_id: object.UID; + let id: object.UID; + label l0: + parent_id = object.new(copy(ctx)); + id = object.new(move(ctx)); + x = X.A { id: move(id) }; + dynamic_object_field.add(&mut parent_id, 0, move(x)); + object.delete(move(parent_id)); + return; + } +} + +//# set-address test object(1,0) + +//# run test::f::transfer + +//# run test::f::share + +//# run test::f::public_transfer + +//# run test::f::public_share + +//# run test::f::freezer + +//# run test::f::public_freezer + +//# run test::f::add_df + +//# run test::f::add_dof diff --git a/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only.exp b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only.exp new file mode 100644 index 0000000000000..eded5762cba05 --- /dev/null +++ b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only.exp @@ -0,0 +1,5 @@ +processed 2 tasks + +task 1 'publish'. lines 6-11: +Error: Transaction Effects Status: Sui Move Bytecode Verification Error. Please run the Sui Move Verifier for more information. +Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: SuiMoveVerificationError, source: Some("Enum X cannot have the 'key' ability. Enums cannot have the 'key' ability."), command: Some(0) } } diff --git a/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only.mvir b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only.mvir new file mode 100644 index 0000000000000..442bab9910c49 --- /dev/null +++ b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only.mvir @@ -0,0 +1,11 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +//# init --addresses test=0x0 + +//# publish +module 0x0.f { + enum X has key { + A { } + } +} diff --git a/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only_uid_field.exp b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only_uid_field.exp new file mode 100644 index 0000000000000..05fda759024fd --- /dev/null +++ b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only_uid_field.exp @@ -0,0 +1,5 @@ +processed 2 tasks + +task 1 'publish'. lines 6-13: +Error: Transaction Effects Status: Sui Move Bytecode Verification Error. Please run the Sui Move Verifier for more information. +Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: SuiMoveVerificationError, source: Some("Enum X cannot have the 'key' ability. Enums cannot have the 'key' ability."), command: Some(0) } } diff --git a/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only_uid_field.mvir b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only_uid_field.mvir new file mode 100644 index 0000000000000..af7580042fab5 --- /dev/null +++ b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only_uid_field.mvir @@ -0,0 +1,13 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +//# init --addresses test=0x0 + +//# publish +module 0x0.f { + import 0x2.object; + + enum X has key { + A { id: object.UID } + } +} diff --git a/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only_uid_field_version_48.exp b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only_uid_field_version_48.exp new file mode 100644 index 0000000000000..59c4b2a9bf7b6 --- /dev/null +++ b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only_uid_field_version_48.exp @@ -0,0 +1,5 @@ +processed 2 tasks + +task 1 'publish'. lines 6-13: +Error: Transaction Effects Status: Move Bytecode Verification Error. Please run the Bytecode Verifier for more information. +Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: VMVerificationOrDeserializationError, source: Some(VMError { major_status: UNKNOWN_VERSION, sub_status: None, message: None, exec_state: None, location: Undefined, indices: [], offsets: [] }), command: Some(0) } } diff --git a/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only_uid_field_version_48.mvir b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only_uid_field_version_48.mvir new file mode 100644 index 0000000000000..735aef5ac5afe --- /dev/null +++ b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only_uid_field_version_48.mvir @@ -0,0 +1,14 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +//# init --addresses test=0x0 --protocol-version 48 + +//# publish +module 0x0.f { + import 0x2.object; + + enum X has key { + A { id: object.UID } + } +} + diff --git a/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only_version_48.exp b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only_version_48.exp new file mode 100644 index 0000000000000..c9b5c15c8d08a --- /dev/null +++ b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only_version_48.exp @@ -0,0 +1,5 @@ +processed 2 tasks + +task 1 'publish'. lines 6-11: +Error: Transaction Effects Status: Move Bytecode Verification Error. Please run the Bytecode Verifier for more information. +Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: VMVerificationOrDeserializationError, source: Some(VMError { major_status: UNKNOWN_VERSION, sub_status: None, message: None, exec_state: None, location: Undefined, indices: [], offsets: [] }), command: Some(0) } } diff --git a/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only_version_48.mvir b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only_version_48.mvir new file mode 100644 index 0000000000000..8e2b51ce3369f --- /dev/null +++ b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_only_version_48.mvir @@ -0,0 +1,12 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +//# init --addresses test=0x0 --protocol-version 48 + +//# publish +module 0x0.f { + enum X has key { + A { } + } +} + diff --git a/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store.exp b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store.exp new file mode 100644 index 0000000000000..eded5762cba05 --- /dev/null +++ b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store.exp @@ -0,0 +1,5 @@ +processed 2 tasks + +task 1 'publish'. lines 6-11: +Error: Transaction Effects Status: Sui Move Bytecode Verification Error. Please run the Sui Move Verifier for more information. +Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: SuiMoveVerificationError, source: Some("Enum X cannot have the 'key' ability. Enums cannot have the 'key' ability."), command: Some(0) } } diff --git a/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store.mvir b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store.mvir new file mode 100644 index 0000000000000..6ae954decadce --- /dev/null +++ b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store.mvir @@ -0,0 +1,11 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +//# init --addresses test=0x0 + +//# publish +module 0x0.f { + enum X has store, key { + A { } + } +} diff --git a/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store_uid_field.exp b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store_uid_field.exp new file mode 100644 index 0000000000000..05fda759024fd --- /dev/null +++ b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store_uid_field.exp @@ -0,0 +1,5 @@ +processed 2 tasks + +task 1 'publish'. lines 6-13: +Error: Transaction Effects Status: Sui Move Bytecode Verification Error. Please run the Sui Move Verifier for more information. +Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: SuiMoveVerificationError, source: Some("Enum X cannot have the 'key' ability. Enums cannot have the 'key' ability."), command: Some(0) } } diff --git a/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store_uid_field.mvir b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store_uid_field.mvir new file mode 100644 index 0000000000000..4fa38db15001f --- /dev/null +++ b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store_uid_field.mvir @@ -0,0 +1,13 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +//# init --addresses test=0x0 + +//# publish +module 0x0.f { + import 0x2.object; + + enum X has store, key { + A { id: object.UID } + } +} diff --git a/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store_uid_field_version_48.exp b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store_uid_field_version_48.exp new file mode 100644 index 0000000000000..59c4b2a9bf7b6 --- /dev/null +++ b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store_uid_field_version_48.exp @@ -0,0 +1,5 @@ +processed 2 tasks + +task 1 'publish'. lines 6-13: +Error: Transaction Effects Status: Move Bytecode Verification Error. Please run the Bytecode Verifier for more information. +Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: VMVerificationOrDeserializationError, source: Some(VMError { major_status: UNKNOWN_VERSION, sub_status: None, message: None, exec_state: None, location: Undefined, indices: [], offsets: [] }), command: Some(0) } } diff --git a/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store_uid_field_version_48.mvir b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store_uid_field_version_48.mvir new file mode 100644 index 0000000000000..8ed852d0f5384 --- /dev/null +++ b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store_uid_field_version_48.mvir @@ -0,0 +1,14 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +//# init --addresses test=0x0 --protocol-version 48 + +//# publish +module 0x0.f { + import 0x2.object; + + enum X has store, key { + A { id: object.UID } + } +} + diff --git a/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store_version_48.exp b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store_version_48.exp new file mode 100644 index 0000000000000..c9b5c15c8d08a --- /dev/null +++ b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store_version_48.exp @@ -0,0 +1,5 @@ +processed 2 tasks + +task 1 'publish'. lines 6-11: +Error: Transaction Effects Status: Move Bytecode Verification Error. Please run the Bytecode Verifier for more information. +Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { kind: VMVerificationOrDeserializationError, source: Some(VMError { major_status: UNKNOWN_VERSION, sub_status: None, message: None, exec_state: None, location: Undefined, indices: [], offsets: [] }), command: Some(0) } } diff --git a/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store_version_48.mvir b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store_version_48.mvir new file mode 100644 index 0000000000000..ad7368442160e --- /dev/null +++ b/crates/sui-verifier-transactional-tests/tests/enums/enum_with_key_store_version_48.mvir @@ -0,0 +1,12 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +//# init --addresses test=0x0 --protocol-version 48 + +//# publish +module 0x0.f { + enum X has store, key { + A { } + } +} + diff --git a/sui-execution/latest/sui-verifier/src/struct_with_key_verifier.rs b/sui-execution/latest/sui-verifier/src/struct_with_key_verifier.rs index e339281b5e617..3f0c426448c77 100644 --- a/sui-execution/latest/sui-verifier/src/struct_with_key_verifier.rs +++ b/sui-execution/latest/sui-verifier/src/struct_with_key_verifier.rs @@ -16,7 +16,8 @@ use sui_types::{ }; pub fn verify_module(module: &CompiledModule) -> Result<(), ExecutionError> { - verify_key_structs(module) + verify_key_structs(module)?; + verify_no_key_enums(module) } fn verify_key_structs(module: &CompiledModule) -> Result<(), ExecutionError> { @@ -80,3 +81,16 @@ fn verify_key_structs(module: &CompiledModule) -> Result<(), ExecutionError> { } Ok(()) } + +fn verify_no_key_enums(module: &CompiledModule) -> Result<(), ExecutionError> { + for def in &module.enum_defs { + let handle = module.datatype_handle_at(def.enum_handle); + if handle.abilities.has_key() { + return Err(verification_failure(format!( + "Enum {} cannot have the 'key' ability. Enums cannot have the 'key' ability.", + module.identifier_at(handle.name) + ))); + } + } + Ok(()) +}