From 0930333b8e2cef7ad29a222d86a83e970f515354 Mon Sep 17 00:00:00 2001 From: Chris Li <666lcz@gmail.com> Date: Sat, 19 Feb 2022 21:13:43 -0800 Subject: [PATCH 1/2] Rename type ID in Move Framework to Versioned ID --- .../data/publish_init/sources/M1.move | 4 +-- .../data/publish_init_param/sources/M1.move | 4 +-- .../data/publish_init_public/sources/M1.move | 4 +-- .../data/publish_init_ret/sources/M1.move | 4 +-- .../data/simple_call/sources/M1.move | 4 +-- .../examples/sources/CombinableObjects.move | 8 +++--- .../sources/CustomObjectTemplate.move | 6 ++-- .../examples/sources/EconMod.move | 4 +-- .../examples/sources/Hero.move | 12 ++++---- .../examples/sources/HeroMod.move | 6 ++-- .../examples/sources/TicTacToe.move | 10 +++---- .../framework/sources/Coin.move | 6 ++-- .../framework/sources/Collection.move | 4 +-- .../framework/sources/Escrow.move | 4 +-- .../framework/sources/Geniteam.move | 8 +++--- sui_programmability/framework/sources/ID.move | 28 +++++++++---------- .../framework/sources/ObjectBasics.move | 6 ++-- .../framework/sources/TestScenario.move | 4 +-- .../framework/sources/TxContext.move | 4 +-- .../framework/tests/CollectionTests.move | 4 +-- .../framework/tests/IDTests.move | 2 +- .../framework/tests/TestScenarioTests.move | 4 +-- .../verifier/src/struct_with_key_verifier.rs | 4 +-- .../verifier/tests/common/module_builder.rs | 4 +-- .../tests/id_immutable_verification_test.rs | 10 +++---- .../tests/id_leak_verification_test.rs | 8 +++--- .../struct_with_key_verification_test.rs | 6 ++-- sui_types/src/id.rs | 2 +- 28 files changed, 87 insertions(+), 87 deletions(-) diff --git a/sui_programmability/adapter/src/unit_tests/data/publish_init/sources/M1.move b/sui_programmability/adapter/src/unit_tests/data/publish_init/sources/M1.move index 8fab7e5773596..397ef812bb72c 100644 --- a/sui_programmability/adapter/src/unit_tests/data/publish_init/sources/M1.move +++ b/sui_programmability/adapter/src/unit_tests/data/publish_init/sources/M1.move @@ -1,10 +1,10 @@ module Test::M1 { - use FastX::ID::ID; + use FastX::ID::VersionedID; use FastX::TxContext::{Self, TxContext}; use FastX::Transfer; struct Object has key, store { - id: ID, + id: VersionedID, value: u64, } diff --git a/sui_programmability/adapter/src/unit_tests/data/publish_init_param/sources/M1.move b/sui_programmability/adapter/src/unit_tests/data/publish_init_param/sources/M1.move index 5abb7f202049c..4d2d26b4439e4 100644 --- a/sui_programmability/adapter/src/unit_tests/data/publish_init_param/sources/M1.move +++ b/sui_programmability/adapter/src/unit_tests/data/publish_init_param/sources/M1.move @@ -1,10 +1,10 @@ module Test::M1 { - use FastX::ID::ID; + use FastX::ID::VersionedID; use FastX::TxContext::{Self, TxContext}; use FastX::Transfer; struct Object has key, store { - id: ID, + id: VersionedID, value: u64, } diff --git a/sui_programmability/adapter/src/unit_tests/data/publish_init_public/sources/M1.move b/sui_programmability/adapter/src/unit_tests/data/publish_init_public/sources/M1.move index d37d8903c1958..fdb0f9bf1051f 100644 --- a/sui_programmability/adapter/src/unit_tests/data/publish_init_public/sources/M1.move +++ b/sui_programmability/adapter/src/unit_tests/data/publish_init_public/sources/M1.move @@ -1,10 +1,10 @@ module Test::M1 { - use FastX::ID::ID; + use FastX::ID::VersionedID; use FastX::TxContext::{Self, TxContext}; use FastX::Transfer; struct Object has key, store { - id: ID, + id: VersionedID, value: u64, } diff --git a/sui_programmability/adapter/src/unit_tests/data/publish_init_ret/sources/M1.move b/sui_programmability/adapter/src/unit_tests/data/publish_init_ret/sources/M1.move index b89a44745a6c4..c19d288723fe0 100644 --- a/sui_programmability/adapter/src/unit_tests/data/publish_init_ret/sources/M1.move +++ b/sui_programmability/adapter/src/unit_tests/data/publish_init_ret/sources/M1.move @@ -1,10 +1,10 @@ module Test::M1 { - use FastX::ID::ID; + use FastX::ID::VersionedID; use FastX::TxContext::{Self, TxContext}; use FastX::Transfer; struct Object has key, store { - id: ID, + id: VersionedID, value: u64, } diff --git a/sui_programmability/adapter/src/unit_tests/data/simple_call/sources/M1.move b/sui_programmability/adapter/src/unit_tests/data/simple_call/sources/M1.move index cb15f4e7e965a..04e71b91fac19 100644 --- a/sui_programmability/adapter/src/unit_tests/data/simple_call/sources/M1.move +++ b/sui_programmability/adapter/src/unit_tests/data/simple_call/sources/M1.move @@ -1,12 +1,12 @@ module Test::M1 { use FastX::Address; - use FastX::ID::ID; + use FastX::ID::VersionedID; use FastX::TxContext::{Self, TxContext}; use FastX::Transfer; use FastX::Coin::Coin; struct Object has key, store { - id: ID, + id: VersionedID, value: u64, } diff --git a/sui_programmability/examples/sources/CombinableObjects.move b/sui_programmability/examples/sources/CombinableObjects.move index aa858b92f0299..60dfeeeacac81 100644 --- a/sui_programmability/examples/sources/CombinableObjects.move +++ b/sui_programmability/examples/sources/CombinableObjects.move @@ -4,20 +4,20 @@ module Examples::CombinableObjects { use Examples::TrustedCoin::EXAMPLE; use FastX::Address::{Self, Address}; use FastX::Coin::{Self, Coin}; - use FastX::ID::{Self, ID}; + use FastX::ID::{Self, VersionedID}; use FastX::Transfer; use FastX::TxContext::{Self, TxContext}; struct Ham has key { - id: ID + id: VersionedID } struct Bread has key { - id: ID + id: VersionedID } struct Sandwich has key { - id: ID + id: VersionedID } /// Address selling ham, bread, etc diff --git a/sui_programmability/examples/sources/CustomObjectTemplate.move b/sui_programmability/examples/sources/CustomObjectTemplate.move index cd5e42847a189..4664a9a8aee30 100644 --- a/sui_programmability/examples/sources/CustomObjectTemplate.move +++ b/sui_programmability/examples/sources/CustomObjectTemplate.move @@ -1,7 +1,7 @@ /// An example of a custom object with comments explaining the relevant bits module Examples::CustomObjectTemplate { use FastX::Address::{Self, Address}; - use FastX::ID::ID; + use FastX::ID::VersionedID; use FastX::Transfer; use FastX::TxContext::{Self, TxContext}; @@ -11,7 +11,7 @@ module Examples::CustomObjectTemplate { /// Other object attributes present at the protocol level (authenticator, /// sequence number, TxDigest, ...) are intentionally not exposed here. struct Object has key { - id: ID, + id: VersionedID, /// Custom objects can have fields of arbitrary type... custom_field: u64, /// ... including other objects @@ -30,7 +30,7 @@ module Examples::CustomObjectTemplate { /// An object that can live either in the global object pool or as a nested /// object. struct AnotherObject has key, store { - id: ID, + id: VersionedID, } /// Example of updating an object. All Move fields are private, so the diff --git a/sui_programmability/examples/sources/EconMod.move b/sui_programmability/examples/sources/EconMod.move index 358c18de73722..3cfbff24f5ea8 100644 --- a/sui_programmability/examples/sources/EconMod.move +++ b/sui_programmability/examples/sources/EconMod.move @@ -7,7 +7,7 @@ module Examples::EconMod { use Examples::Hero::Hero; use FastX::Address::Address; use FastX::Coin::{Self, Coin}; - use FastX::ID::{Self, ID}; + use FastX::ID::{Self, VersionedID}; use FastX::Transfer; use FastX::TxContext::{Self, TxContext}; @@ -16,7 +16,7 @@ module Examples::EconMod { /// The two players split the reward for slaying the monster according to /// the `helper_reward` parameter. struct HelpMeSlayThisMonster has key { - id: ID, + id: VersionedID, /// Monster to be slay by the owner of this object monster: SeaMonster, /// Identity of the user that originally owned the monster diff --git a/sui_programmability/examples/sources/Hero.move b/sui_programmability/examples/sources/Hero.move index 276f2cf81caf2..836580596cde5 100644 --- a/sui_programmability/examples/sources/Hero.move +++ b/sui_programmability/examples/sources/Hero.move @@ -5,7 +5,7 @@ module Examples::Hero { use FastX::Address::{Self, Address}; use FastX::Coin::{Self, Coin}; use FastX::Event; - use FastX::ID::{Self, ID, IDBytes}; + use FastX::ID::{Self, VersionedID, IDBytes}; use FastX::Math; use FastX::Transfer; use FastX::TxContext::{Self, TxContext}; @@ -13,7 +13,7 @@ module Examples::Hero { /// Our hero! struct Hero has key, store { - id: ID, + id: VersionedID, /// Hit points. If they go to zero, the hero can't do anything hp: u64, /// Experience of the hero. Begins at zero @@ -24,7 +24,7 @@ module Examples::Hero { /// The hero's trusty sword struct Sword has key, store { - id: ID, + id: VersionedID, /// Constant set at creation. Acts as a multiplier on sword's strength. /// Swords with high magic are rarer (because they cost more). magic: u64, @@ -34,14 +34,14 @@ module Examples::Hero { /// For healing wounded heroes struct Potion has key, store { - id: ID, + id: VersionedID, /// Effectivenss of the potion potency: u64 } /// A creature that the hero can slay to level up struct Boar has key { - id: ID, + id: VersionedID, /// Hit points before the boar is slain hp: u64, /// Strength of this particular boar @@ -50,7 +50,7 @@ module Examples::Hero { /// Capability conveying the authority to create boars and potions struct GameAdmin has key { - id: ID, + id: VersionedID, /// Total number of boars the admin has created boars_created: u64, /// Total number of potions the admin has created diff --git a/sui_programmability/examples/sources/HeroMod.move b/sui_programmability/examples/sources/HeroMod.move index 96e2e7a349ee2..08d36d7873c2a 100644 --- a/sui_programmability/examples/sources/HeroMod.move +++ b/sui_programmability/examples/sources/HeroMod.move @@ -8,14 +8,14 @@ module Examples::HeroMod { use Examples::Hero::{Self, Hero}; use FastX::Address::Address; - use FastX::ID::{Self, ID}; + use FastX::ID::{Self, VersionedID}; use FastX::Coin::{Self, Coin, TreasuryCap }; use FastX::Transfer; use FastX::TxContext::{Self, TxContext}; /// A new kind of monster for the hero to fight struct SeaMonster has key, store { - id: ID, + id: VersionedID, /// Tokens that the user will earn for slaying this monster reward: Coin } @@ -23,7 +23,7 @@ module Examples::HeroMod { /// Admin capability granting permission to mint RUM tokens and /// create monsters struct SeaScapeAdmin has key { - id: ID, + id: VersionedID, /// Permission to mint RUM treasury_cap: TreasuryCap, /// Total number of monsters created so far diff --git a/sui_programmability/examples/sources/TicTacToe.move b/sui_programmability/examples/sources/TicTacToe.move index 5c32e2eaabbde..99982093b3dac 100644 --- a/sui_programmability/examples/sources/TicTacToe.move +++ b/sui_programmability/examples/sources/TicTacToe.move @@ -3,7 +3,7 @@ module Examples::TicTacToe { use Std::Vector; use FastX::Address::Address; - use FastX::ID::{Self, ID, IDBytes}; + use FastX::ID::{Self, VersionedID, IDBytes}; use FastX::Event; use FastX::Transfer; use FastX::TxContext::{Self, TxContext}; @@ -19,7 +19,7 @@ module Examples::TicTacToe { const NO_MORE_MARK: u64 = 1; struct TicTacToe has key { - id: ID, + id: VersionedID, gameboard: vector>>, cur_turn: u8, game_status: u8, @@ -28,20 +28,20 @@ module Examples::TicTacToe { } struct MarkMintCap has key { - id: ID, + id: VersionedID, game_id: IDBytes, remaining_supply: u8, } struct Mark has key, store { - id: ID, + id: VersionedID, player: Address, row: u64, col: u64, } struct Trophy has key { - id: ID, + id: VersionedID, } struct MarkSentEvent has copy, drop { diff --git a/sui_programmability/framework/sources/Coin.move b/sui_programmability/framework/sources/Coin.move index 5e4b66f9c1e8e..8853a91d41b0c 100644 --- a/sui_programmability/framework/sources/Coin.move +++ b/sui_programmability/framework/sources/Coin.move @@ -1,6 +1,6 @@ module FastX::Coin { use FastX::Address::{Self, Address}; - use FastX::ID::{Self, ID}; + use FastX::ID::{Self, VersionedID}; use FastX::Transfer; use FastX::TxContext::{Self, TxContext}; use Std::Errors; @@ -8,14 +8,14 @@ module FastX::Coin { /// A coin of type `T` worth `value`. Transferrable struct Coin has key, store { - id: ID, + id: VersionedID, value: u64 } /// Capability allowing the bearer to mint and burn /// coins of type `T`. Transferrable struct TreasuryCap has key, store { - id: ID, + id: VersionedID, total_supply: u64 } diff --git a/sui_programmability/framework/sources/Collection.move b/sui_programmability/framework/sources/Collection.move index 36f8f8ec71f8f..ec9fc7f33c0d7 100644 --- a/sui_programmability/framework/sources/Collection.move +++ b/sui_programmability/framework/sources/Collection.move @@ -3,7 +3,7 @@ module FastX::Collection { use Std::Option::{Self, Option}; use Std::Vector::Self; use FastX::Address::{Self, Address}; - use FastX::ID::{Self, ID, IDBytes}; + use FastX::ID::{Self, VersionedID, IDBytes}; use FastX::Transfer; use FastX::TxContext::{Self, TxContext}; @@ -17,7 +17,7 @@ module FastX::Collection { const DEFAULT_MAX_CAPACITY: u64 = 65536; struct Collection has key { - id: ID, + id: VersionedID, objects: vector, max_capacity: u64, } diff --git a/sui_programmability/framework/sources/Escrow.move b/sui_programmability/framework/sources/Escrow.move index 34ecb87809e60..0b1fe31f717b1 100644 --- a/sui_programmability/framework/sources/Escrow.move +++ b/sui_programmability/framework/sources/Escrow.move @@ -3,13 +3,13 @@ /// safety. module FastX::Escrow { use FastX::Address::Address; - use FastX::ID::{Self, IDBytes, ID}; + use FastX::ID::{Self, IDBytes, VersionedID}; use FastX::Transfer; use FastX::TxContext::{Self, TxContext}; /// An object held in escrow struct EscrowedObj has key, store { - id: ID, + id: VersionedID, /// owner of the escrowed object sender: Address, /// intended recipient of the escrowed object diff --git a/sui_programmability/framework/sources/Geniteam.move b/sui_programmability/framework/sources/Geniteam.move index 4f01f05d5a453..7a9427803399c 100644 --- a/sui_programmability/framework/sources/Geniteam.move +++ b/sui_programmability/framework/sources/Geniteam.move @@ -1,5 +1,5 @@ module FastX::Geniteam { - use FastX::ID::{Self, ID, IDBytes}; + use FastX::ID::{Self, VersionedID, IDBytes}; use FastX::TxContext::{Self, TxContext}; use FastX::Transfer; use Std::ASCII::{Self, String}; @@ -12,7 +12,7 @@ module FastX::Geniteam { const EMONSTER_NOT_FOUND: u64 = 1; struct Player has key { - id: ID, + id: VersionedID, player_name: String, farm: Farm, water_runes_count: u64, @@ -22,7 +22,7 @@ module FastX::Geniteam { } struct Farm has key, store { - id: ID, + id: VersionedID, farm_name: String, farm_img_id: u64, level: u64, @@ -34,7 +34,7 @@ module FastX::Geniteam { } struct Monster has key, store { - id: ID, + id: VersionedID, monster_name: String, monster_img_id: u64, breed: u8, diff --git a/sui_programmability/framework/sources/ID.move b/sui_programmability/framework/sources/ID.move index f1a466c9d3f55..bbca6a27f7003 100644 --- a/sui_programmability/framework/sources/ID.move +++ b/sui_programmability/framework/sources/ID.move @@ -9,14 +9,14 @@ module FastX::ID { /// Globally unique identifier of an object. This is a privileged type /// that can only be derived from a `TxContext` - /// ID doesn't have drop capability, which means to delete an ID (when + /// VersionedID doesn't have drop capability, which means to delete an VersionedID (when /// deleting an object), one must explicitly call the delete function. - struct ID has store { + struct VersionedID has store { id: IDBytes, - /// Version number for the ID. The version number is incremented each - /// time the object with this ID is passed to a non-failing transaction + /// Version number for the VersionedID. The version number is incremented each + /// time the object with this VersionedID is passed to a non-failing transaction /// either by value or by mutable reference. - /// Note: if the object with this ID gets wrapped in another object, the + /// Note: if the object with this VersionedID gets wrapped in another object, the /// child object may be mutated with no version number change. version: u64 } @@ -27,11 +27,11 @@ module FastX::ID { bytes: address } - /// Create a new ID. Only callable by TxContext + /// Create a new VersionedID. Only callable by TxContext // TODO (): bring this back once we can support `friend` - //public(friend) fun new(bytes: vector): ID { - public fun new(bytes: address): ID { - ID { id: IDBytes { bytes }, version: INITIAL_VERSION } + //public(friend) fun new(bytes: vector): VersionedID { + public fun new(bytes: address): VersionedID { + VersionedID { id: IDBytes { bytes }, version: INITIAL_VERSION } } /// Create a new ID bytes for comparison with existing ID's. @@ -40,7 +40,7 @@ module FastX::ID { } /// Get the underyling `IDBytes` of `id` - public fun get_inner(id: &ID): &IDBytes { + public fun get_inner(id: &VersionedID): &IDBytes { &id.id } @@ -71,15 +71,15 @@ module FastX::ID { BCS::to_bytes(get_bytes(i)) } - /// Get the ID for `obj`. Safe because fastX has an extra + /// Get the VersionedID for `obj`. Safe because fastX has an extra /// bytecode verifier pass that forces every struct with - /// the `key` ability to have a distinguished `ID` field. - public native fun get_id(obj: &T): &ID; + /// the `key` ability to have a distinguished `VersionedID` field. + public native fun get_id(obj: &T): &VersionedID; public native fun bytes_to_address(bytes: vector): address; /// When an object is being deleted through unpacking, the /// delete function must be called on the id to inform Sui /// regarding the deletion of the object. - public native fun delete(id: ID); + public native fun delete(id: VersionedID); } diff --git a/sui_programmability/framework/sources/ObjectBasics.move b/sui_programmability/framework/sources/ObjectBasics.move index a9c89b4eeb10d..f88f9d9d7b8e3 100644 --- a/sui_programmability/framework/sources/ObjectBasics.move +++ b/sui_programmability/framework/sources/ObjectBasics.move @@ -2,17 +2,17 @@ module FastX::ObjectBasics { use FastX::Address; use FastX::Event; - use FastX::ID::{Self, ID}; + use FastX::ID::{Self, VersionedID}; use FastX::TxContext::{Self, TxContext}; use FastX::Transfer; struct Object has key, store { - id: ID, + id: VersionedID, value: u64, } struct Wrapper has key { - id: ID, + id: VersionedID, o: Object } diff --git a/sui_programmability/framework/sources/TestScenario.move b/sui_programmability/framework/sources/TestScenario.move index e03c4ce1dcaab..370403a1b1554 100644 --- a/sui_programmability/framework/sources/TestScenario.move +++ b/sui_programmability/framework/sources/TestScenario.move @@ -4,7 +4,7 @@ #[test_only] module FastX::TestScenario { use FastX::Address::{Self, Address}; - use FastX::ID::{Self, ID, IDBytes}; + use FastX::ID::{Self, VersionedID, IDBytes}; use FastX::Transfer; use FastX::TxContext::{Self, TxContext}; use Std::Vector; @@ -196,7 +196,7 @@ module FastX::TestScenario { } /// Generate a fresh ID for the current tx associated with this `scenario` - public fun new_id(scenario: &mut Scenario): ID { + public fun new_id(scenario: &mut Scenario): VersionedID { TxContext::new_id(&mut scenario.ctx) } diff --git a/sui_programmability/framework/sources/TxContext.move b/sui_programmability/framework/sources/TxContext.move index 0e800e5610e86..9caa8ba52eb1e 100644 --- a/sui_programmability/framework/sources/TxContext.move +++ b/sui_programmability/framework/sources/TxContext.move @@ -4,7 +4,7 @@ module FastX::TxContext { #[test_only] use Std::Vector; - use FastX::ID::{Self, ID}; + use FastX::ID::{Self, VersionedID}; use FastX::Address::{Self, Address, Signer}; /// Number of bytes in an inputs_hash (which will be the transaction digest) @@ -43,7 +43,7 @@ module FastX::TxContext { } /// Generate a new object ID - public fun new_id(ctx: &mut TxContext): ID { + public fun new_id(ctx: &mut TxContext): VersionedID { let ids_created = ctx.ids_created; let id = ID::new(fresh_id(*&ctx.inputs_hash, ids_created)); ctx.ids_created = ids_created + 1; diff --git a/sui_programmability/framework/tests/CollectionTests.move b/sui_programmability/framework/tests/CollectionTests.move index 222f117ad6af9..56d78c05883fc 100644 --- a/sui_programmability/framework/tests/CollectionTests.move +++ b/sui_programmability/framework/tests/CollectionTests.move @@ -1,14 +1,14 @@ #[test_only] module FastX::CollectionTests { use FastX::Collection; - use FastX::ID::{Self, ID}; + use FastX::ID::{Self, VersionedID}; use FastX::TxContext; const ECOLLECTION_SIZE_MISMATCH: u64 = 0; const EOBJECT_NOT_FOUND: u64 = 1; struct Object has key { - id: ID, + id: VersionedID, } #[test] diff --git a/sui_programmability/framework/tests/IDTests.move b/sui_programmability/framework/tests/IDTests.move index 0c072e0f72215..1ff26ec430b73 100644 --- a/sui_programmability/framework/tests/IDTests.move +++ b/sui_programmability/framework/tests/IDTests.move @@ -6,7 +6,7 @@ module FastX::IDTests { const ID_BYTES_MISMATCH: u64 = 0; struct Object has key { - id: ID::ID, + id: ID::VersionedID, } #[test] diff --git a/sui_programmability/framework/tests/TestScenarioTests.move b/sui_programmability/framework/tests/TestScenarioTests.move index f67cdf7d99c18..ed18ed7225de0 100644 --- a/sui_programmability/framework/tests/TestScenarioTests.move +++ b/sui_programmability/framework/tests/TestScenarioTests.move @@ -12,12 +12,12 @@ module FastX::TestScenarioTests { const VALUE_MISMATCH: u64 = 1; struct Object has key, store { - id: ID::ID, + id: ID::VersionedID, value: u64, } struct Wrapper has key { - id: ID::ID, + id: ID::VersionedID, child: Object, } diff --git a/sui_programmability/verifier/src/struct_with_key_verifier.rs b/sui_programmability/verifier/src/struct_with_key_verifier.rs index 848e9238f133a..b55c3b7e70251 100644 --- a/sui_programmability/verifier/src/struct_with_key_verifier.rs +++ b/sui_programmability/verifier/src/struct_with_key_verifier.rs @@ -70,11 +70,11 @@ fn verify_key_structs(module: &CompiledModule) -> SuiResult { let id_type_module_address = module.address_identifier_at(id_type_module.address); let id_type_module_name = module.identifier_at(id_type_module.name).to_string(); fp_ensure!( - id_type_struct_name == "ID" + id_type_struct_name == "VersionedID" && id_type_module_address == &SUI_FRAMEWORK_ADDRESS && id_type_module_name == "ID", verification_failure(format!( - "First field of struct {} must be of type {}::ID::ID, {}::{}::{} type found", + "First field of struct {} must be of type {}::ID::VersionedID, {}::{}::{} type found", name, SUI_FRAMEWORK_ADDRESS, id_type_module_address, diff --git a/sui_programmability/verifier/tests/common/module_builder.rs b/sui_programmability/verifier/tests/common/module_builder.rs index e96d355559d9e..7de79a2102621 100644 --- a/sui_programmability/verifier/tests/common/module_builder.rs +++ b/sui_programmability/verifier/tests/common/module_builder.rs @@ -50,13 +50,13 @@ impl ModuleBuilder { } } - /// Creates the "ID" module in framework address, along with the "ID" struct. + /// Creates the "ID" module in framework address, along with the "VersionedID" struct. /// Both the module and the ID struct information are returned. pub fn default() -> (Self, StructInfo) { let mut module = Self::new(SUI_FRAMEWORK_ADDRESS, "ID"); let id = module.add_struct( module.get_self_index(), - "ID", + "VersionedID", AbilitySet::EMPTY | Ability::Store | Ability::Drop, vec![], ); diff --git a/sui_programmability/verifier/tests/id_immutable_verification_test.rs b/sui_programmability/verifier/tests/id_immutable_verification_test.rs index e9a17cc94a732..81c0b41307748 100644 --- a/sui_programmability/verifier/tests/id_immutable_verification_test.rs +++ b/sui_programmability/verifier/tests/id_immutable_verification_test.rs @@ -12,7 +12,7 @@ use sui_verifier::id_immutable_verifier::verify_module; fn mut_borrow_key_struct_id_field() { /* struct Foo has key { - id: 0x2::ID::ID + id: 0x2::ID::VersionedID } fun foo(f: Foo) { @@ -51,7 +51,7 @@ fn mut_borrow_key_struct_id_field() { fn mut_borrow_non_key_struct_id_field() { /* struct Foo { - id: 0x2::ID::ID + id: 0x2::ID::VersionedID } fun foo(f: Foo) { let ref = &mut f.id; @@ -84,8 +84,8 @@ fn mut_borrow_non_key_struct_id_field() { fn mut_borrow_key_struct_non_id_field() { /* struct Foo has key { - id: 0x2::ID::ID, - other: 0x2::ID::ID + id: 0x2::ID::VersionedID, + other: 0x2::ID::VersionedID } fun foo(f: Foo) { let ref = &mut f.other; @@ -121,7 +121,7 @@ fn mut_borrow_key_struct_non_id_field() { fn mut_borrow_generic_key_struct_id_field() { /* struct Foo has key { - id: 0x2::ID::ID + id: 0x2::ID::VersionedID } fun foo(f: Foo) { diff --git a/sui_programmability/verifier/tests/id_leak_verification_test.rs b/sui_programmability/verifier/tests/id_leak_verification_test.rs index 1cdab1068f021..cd5241604c54c 100644 --- a/sui_programmability/verifier/tests/id_leak_verification_test.rs +++ b/sui_programmability/verifier/tests/id_leak_verification_test.rs @@ -13,7 +13,7 @@ fn make_module_with_default_struct() -> (ModuleBuilder, StructInfo, StructInfo) Creating a module with a default struct Foo: struct Foo has key { - id: SUI_FRAMEWORK_ADDRESS::ID::ID + id: SUI_FRAMEWORK_ADDRESS::ID::VersionedID } */ let (mut module, id_struct) = ModuleBuilder::default(); @@ -29,7 +29,7 @@ fn make_module_with_default_struct() -> (ModuleBuilder, StructInfo, StructInfo) #[test] fn id_leak_through_direct_return() { /* - fun foo(f: Foo): 0x1::ID::ID { + fun foo(f: Foo): 0x1::ID::VersionedID { let Foo { id: id } = f; return id; } @@ -91,7 +91,7 @@ fn id_leak_through_indirect_return() { #[test] fn id_leak_through_reference() { /* - fun foo(f: Foo, ref: &mut 0x1::ID::ID) { + fun foo(f: Foo, ref: &mut 0x1::ID::VersionedID) { let Foo { id: id } = f; *ref = id; } @@ -126,7 +126,7 @@ fn id_leak_through_reference() { #[test] fn id_direct_leak_through_call() { /* - fun transfer(id: 0x1::ID::ID); + fun transfer(id: 0x1::ID::VersionedID); fun foo(f: Foo) { let Foo { id: id } = f; diff --git a/sui_programmability/verifier/tests/struct_with_key_verification_test.rs b/sui_programmability/verifier/tests/struct_with_key_verification_test.rs index c4f04206bef5f..fc9a32c2ccf12 100644 --- a/sui_programmability/verifier/tests/struct_with_key_verification_test.rs +++ b/sui_programmability/verifier/tests/struct_with_key_verification_test.rs @@ -102,7 +102,7 @@ fn key_struct_id_field_incorrect_struct_address() { let new_module_idx = module.add_module(addr, "ID"); let fake_id_struct = module.add_struct( new_module_idx, - "ID", + "VersionedID", AbilitySet::EMPTY | Ability::Store | Ability::Drop, vec![], ); @@ -114,7 +114,7 @@ fn key_struct_id_field_incorrect_struct_address() { ); let err_str = verify_module(module.get_module()).unwrap_err().to_string(); assert!(err_str.contains(&format!( - "First field of struct S must be of type {}::ID::ID, {}::ID::ID type found", + "First field of struct S must be of type {}::ID::VersionedID, {}::ID::VersionedID type found", SUI_FRAMEWORK_ADDRESS, addr ))); } @@ -138,7 +138,7 @@ fn key_struct_id_field_incorrect_struct_name() { .unwrap_err() .to_string() .contains(&format!( - "First field of struct S must be of type {0}::ID::ID, {0}::ID::FOO type found", + "First field of struct S must be of type {0}::ID::VersionedID, {0}::ID::FOO type found", SUI_FRAMEWORK_ADDRESS ))); } diff --git a/sui_types/src/id.rs b/sui_types/src/id.rs index 7c0b8e674dcb5..6da82b2ca81d3 100644 --- a/sui_types/src/id.rs +++ b/sui_types/src/id.rs @@ -18,7 +18,7 @@ pub const ID_MODULE_NAME: &IdentStr = ident_str!("ID"); pub const ID_STRUCT_NAME: &IdentStr = ID_MODULE_NAME; pub const ID_BYTES_STRUCT_NAME: &IdentStr = ident_str!("IDBytes"); -/// Rust version of the Move FastX::ID::ID type +/// Rust version of the Move FastX::ID::VersionedID type #[derive(Debug, Serialize, Deserialize)] pub struct ID { id: IDBytes, From a4c82ff432b05c175acd885644b5b76ae7a065bb Mon Sep 17 00:00:00 2001 From: Chris Li <666lcz@gmail.com> Date: Sat, 19 Feb 2022 21:19:30 -0800 Subject: [PATCH 2/2] Change Type id::ID in Rust to id::VersionedID --- sui_types/src/coin.rs | 8 ++++---- sui_types/src/gas_coin.rs | 4 ++-- sui_types/src/id.rs | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sui_types/src/coin.rs b/sui_types/src/coin.rs index dfc3e53e12821..57d93c67cff09 100644 --- a/sui_types/src/coin.rs +++ b/sui_types/src/coin.rs @@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize}; use crate::{ base_types::{ObjectID, SequenceNumber}, - id::ID, + id::VersionedID, SUI_FRAMEWORK_ADDRESS, }; @@ -21,12 +21,12 @@ pub const COIN_STRUCT_NAME: &IdentStr = COIN_MODULE_NAME; // Rust version of the Move FastX::Coin::Coin type #[derive(Debug, Serialize, Deserialize)] pub struct Coin { - id: ID, + id: VersionedID, value: u64, } impl Coin { - pub fn new(id: ID, value: u64) -> Self { + pub fn new(id: VersionedID, value: u64) -> Self { Self { id, value } } @@ -61,7 +61,7 @@ impl Coin { fields: vec![ MoveFieldLayout::new( ident_str!("id").to_owned(), - MoveTypeLayout::Struct(ID::layout()), + MoveTypeLayout::Struct(VersionedID::layout()), ), MoveFieldLayout::new(ident_str!("value").to_owned(), MoveTypeLayout::U64), ], diff --git a/sui_types/src/gas_coin.rs b/sui_types/src/gas_coin.rs index fe858c19761e9..2d847d5f61585 100644 --- a/sui_types/src/gas_coin.rs +++ b/sui_types/src/gas_coin.rs @@ -14,7 +14,7 @@ use crate::{ base_types::{ObjectID, SequenceNumber}, coin::Coin, error::{SuiError, SuiResult}, - id::ID, + id::VersionedID, object::{Data, MoveObject, Object}, SUI_FRAMEWORK_ADDRESS, }; @@ -44,7 +44,7 @@ pub struct GasCoin(Coin); impl GasCoin { pub fn new(id: ObjectID, version: SequenceNumber, value: u64) -> Self { - Self(Coin::new(ID::new(id, version), value)) + Self(Coin::new(VersionedID::new(id, version), value)) } pub fn value(&self) -> u64 { diff --git a/sui_types/src/id.rs b/sui_types/src/id.rs index 6da82b2ca81d3..a888d57509c40 100644 --- a/sui_types/src/id.rs +++ b/sui_types/src/id.rs @@ -20,7 +20,7 @@ pub const ID_BYTES_STRUCT_NAME: &IdentStr = ident_str!("IDBytes"); /// Rust version of the Move FastX::ID::VersionedID type #[derive(Debug, Serialize, Deserialize)] -pub struct ID { +pub struct VersionedID { id: IDBytes, version: u64, } @@ -31,7 +31,7 @@ struct IDBytes { bytes: ObjectID, } -impl ID { +impl VersionedID { pub fn new(bytes: ObjectID, version: SequenceNumber) -> Self { Self { id: IDBytes::new(bytes),