Move Concepts
Move is an open source language for writing safe packages to manipulate onchain objects (sometimes referred to as smart contracts). Move is a platform-agnostic language to enable common libraries, tooling, and developer communities across blockchains with vastly different data and execution models. Move is adaptable to meet the needs of the blockchain the code operates on, see Move on Sui to review enhancements made to Move for optimization on the Sui blockchain.
You can use Move to define, create, and manage programmable Sui objects representing assets and smart contracts. Sui implements its object system by adding new functionality to Move while also imposing additional restrictions.
Move on Sui contains some important differences from Move on other blockchains. Sui takes advantage of Move's security and flexibility, enhancing it with the features to vastly improve throughput, reduce delays in finality, and make Move programming more approachable. For full details, see the Sui Smart Contracts Platform whitepaper.
Where the Sui documentation refers to the Move language, the content is documenting the specific Move implementation on the Sui blockchain. If relevant, the documentation expressly refers to the original use case for the Move language as Move on Diem.
Key differences
Key differences of Move on Sui include:
-
Sui uses its own object-centric global storage
-
Addresses represent object IDs
-
Sui objects have globally unique IDs
-
Sui has module initializers (
init) -
Sui has unique use cases for the
entrykeyword
Object-centric global storage
In Move on Diem, global storage is part of the programming model. Global storage holds resources and modules, which an account with an address owns. Transactions are free to access resources from any account in global storage when they run, using special operations such as move_to and move_from.
This approach introduces a scaling issue, as it is not possible to statically determine which transactions are contending over the same resource and which are not. This is similar to the scaling issues that other blockchains face, where smart contracts typically store account information in large, internal mappings, which limit throughput.
Move on Sui addresses the scaling issue by not having global storage or its related operations. When Sui stores objects (in contrast to resources) and packages (sets of modules), it gives each of them a unique identifier. Each transaction explicitly specifies all of its inputs up front using these unique identifiers to allow the network to schedule transactions with non-overlapping inputs in parallel.
Addresses represent object IDs
In Move on Diem, there is a 16 byte address type used to represent account addresses in global storage. A 16 byte address is sufficient for the Move on Diem security model.
Sui doesn't have global storage, so it repurposes address as a 32 byte identifier used for both objects and accounts. An account (the sender) that is accessible from the transaction context signs each transaction, and each object stores its address wrapped in its id: UID field.
See the address section in The Move Book for an overview on addresses and refer to object.move in the Sui framework for implementation details.
Object with key ability, globally unique IDs
In Move on Diem, the key ability indicates that the type is a resource, meaning you can use it, along with an account address, as a key in global storage.
On Sui, the key ability indicates that a struct is an object type and comes with an additional requirement that the first field of the struct has signature id: UID to contain the object's unique address onchain. Sui's bytecode verifier ensures that Sui always assigns fresh UIDs to new objects. Sui never reuses identifiers.
Module initializers
As described in object-centric global storage, you publish Move modules into Sui storage. The Sui runtime executes a special initializer function you optionally define in a module only once at the time of module publication to pre-initialize module-specific data, for example, creating singleton objects. See the module initializer section in The Move Book for more information.
Entry functions
The entry keyword has a specific use case in Move on Sui. Use entry when you want some functionality to be usable by anyone onchain, but you don't want other Move logic to wrap it. In other words, you can call the function in programmable transaction blocks (PTBs) but not in other Sui packages. For example, you use this with Sui's onchain randomness standard to prevent other smart contract engineers from creating logic to essentially front-run or back-run the randomness generation. Find more information about this in the onchain randomness page.
Make your function private (don't add the public visibility keyword) and mark it with the entry keyword, as in entry fun example_function.
In addition to this Sui-specific use case, there are other rules and restrictions for entry functions:
- Non-public
entryfunctions (private orpublic(package)) have restrictions on arguments that are entangled with hot potato values in a PTB. See Non-public entry function restrictions for details.
Previously, entry functions had additional restrictions on their signatures (their types for parameters and return values), but this is no longer the case. entry functions can have the same arguments or return values as a public function in a PTB.