Sui

Move is a smart contract programming language written in Rust that powers the Sui Network. It offers significant advancements in security and productivity, making it an excellent choice for building decentralized applications (dApps). Here are some key features of Move:

  1. Inherently Secure: Move is designed with security in mind. It minimizes the risk of vulnerabilities and ensures robustness in smart contracts.
  2. zkLogin Authentication: Move includes zkLogin, an authentication mechanism that leverages web credentials for secure user interactions.
  3. Kiosk - Customizable Policies: Developers can create customizable trade and transfer policies using Move, allowing fine-grained control over asset management.
  4. Use Cases:

Gaming: Tradable in-game assets can be built using Move.

Finance: Move enables low-fee and near-instant settlement for financial applications.

Commerce: Authentic interactions and verifiable assets can be implemented using Move.


Similarities with Rust!

  • Static Typing: Both Move and Rust enforce static typing, meaning data types are strictly defined at compile time. This helps prevent runtime errors and unexpected behavior.
  • Memory Safety: Both languages prioritize memory safety. Move uses ownership and borrowing to prevent memory leaks, while Rust employs a similar ownership system with a focus on preventing dangling pointers.
  • Compiler Focus: Both Move and Rust prioritize code safety and verification. Their compilers play a crucial role in ensuring code adheres to the language's rules and identifying potential issues before execution.


Key Difference :

Purpose:

Move: Designed specifically for secure smart contract development on blockchains.

Rust: General-purpose language suitable for various applications, including systems programming, web development, and embedded systems.

Execution Environment:

Move: Primarily compiled to bytecode for execution on a virtual machine within a blockchain.

Rust: Compiled directly to machine code for native execution on various platforms.

Ownership System:

Move: Ownership is transferred at compile time, offering strong guarantees against memory leaks. Borrowing allows temporary use of resources.

Rust: Ownership is enforced at compile time, but borrowing can be more flexible with explicit lifetime annotations.

Features:

Move: Focuses on resource management and safety for smart contracts. Lacks features like generics or macros present in Rust.

Rust: Offers a wider range of features like generics, macros, and advanced memory management techniques for broader application development.


Performance comparison between Rust and Move:

Move's performance is not on par with Rust's native execution:

  • Virtual Machine Overhead: Move code is compiled to bytecode, which then needs to be interpreted by a virtual machine (VM) within the blockchain. This extra layer of interpretation adds overhead compared to Rust's direct machine code execution.
  • Focus on Security: Move prioritizes security over raw performance. The ownership and borrowing system, while enhancing memory safety, can introduce some overhead compared to Rust's more flexible memory management.
  • Limited Optimization: Blockchains are resource-constrained environments, and optimizing for security and resource management can sometimes come at the expense of raw speed.

However, it's important to consider the trade-offs:

  • Security is Paramount for Blockchains: In the context of smart contracts, security is often the primary concern. Move's focus on safety helps mitigate vulnerabilities that can be exploited in financial applications on blockchains.
  • Performance Optimization Can Be Done: While Move might not be as performant as Rust in raw speed, there are ongoing efforts to optimize the Move VM and bytecode execution for improved performance within the blockchain environment.

So:

  • Rust offers superior performance due to its native compilation and flexibility.
  • Move prioritizes security for smart contracts, sacrificing some performance due to VM execution.

The choice between the two depends on the specific needs of the project.


The move is adaptable to meet the needs of the blockchain and the code it operates on.

The move can be customized based on the blockchain needs :

FYI:

Move on Sui contains some important differences from Move on other blockchains.

Some of the key differences with Move on Sui include:


Link: Move Concepts | Sui Documentation

Reference:

move/language/documentation/tutorial/README.md at main · move-language/move (github.com)

Sui

Sui is an account-based model: Sui transactions are processable in parallel makes it fast and efficient.

Sui has a native token called SUI : Fixed supply;

Consensus mechanism: Delegated Proof-of-Stake (DPoS) powered Byzantine fault tolerant.

  • Validators: The Sui network relies on a set of validator nodes responsible for verifying transactions and maintaining the network's state.
  • Stake: SUI token holders can delegate their tokens to validators they trust. This delegation process indicates their support for the validator's participation in securing the network.
  • Validator Selection: Based on the amount of delegated SUI tokens, a fixed number of validators are chosen to form the validator committee responsible for validating transactions in a specific epoch (typically 24 hours).
  • Transaction Validation: Validators in the committee propose blocks containing transactions, and other validators vote on the validity of these proposed blocks.
  • Authorities are Byzantine fault tolerant: Authorities are periodically reconfigured according to the stake delegated to them. In any epoch, the set of authorities is Byzantine fault tolerant.
  • Rewards: At the end of the epoch, fees collected through all transactions processed are distributed to authorities according to their contribution to the operation of the system. Authorities can in turn share some of the fees as rewards to users that delegated stakes to them. Validators who contribute to securing the network by proposing and validating blocks earn rewards in the form of SUI tokens.


Features of move and sui:

1. Object-based data models :

Building blocks on move , its just a big database of objects ,Works with scarce objects , Objacts have conservation property (cant copy , cant drop,Strong ownership transfer), Objects are notyhing but structs with unique ids. These id reamin same evene whne they are transferred from one account to another account.

“Most things in life are objects,” especially assets managed by real-world contracts. With the object data model on Sui, smart contracts mirror that reality. Object types, ownership, transfers, and display are native features. Objects are a common vocabulary throughout the stack, simplifying apps, wallets, explorers, and the overall developer experience.

2. Programmable Transaction Blocks [PTBs]

We can create programmable transaction blocks (PTBs) on Sui to perform multiple commands in a single transaction.

PTBs enable rich but safe (no re-entrance or dynamic dispatch) code composability. A single Sui transaction can call up to 1024 separate Move functions, either homogeneously for mass batching or heterogeneously where typed objects serve as inputs to the next calls. Highly expressive, heterogeneous PTBs move composition from the smart contract level to the transaction level, significantly improving gas efficiency and code simplicity. : Composiablity on the fly.

Programmable Transaction Blocks | Sui Documentation

3. Dynamic fields -. Fields can be added dynamically

Dynamic fields enable safe data composability. Add or remove object fields on the fly, link objects together, and organize data via intuitive object hierarchies.

4. Security: Highly secure :

Security is achieved via following:

1. Need to write the access control checks as objects have native metadata and one of the important pieces of the metadata is the owner of the object.

2. No - Re-entrance by construction: Every time it calls the statically known functions which makes it very easy to write a predictable code . <- This removes the biggest source of hacks.

Practicals :

I did some experiments on both move and sui. I just recording them here :

Get the sui binaries from below :

FYI V1.23.1 can be replaced with latest one .

Release mainnet-v1.23.1 · MystenLabs/sui (github.com)

It contains below :

Functionality of each of the binaries :


How to connect the Sui client to a network, run the following command:

amit@DESKTOP-TF687VE:~$ sui client        

It gives below output:


The available environment in local PC:

amit@DESKTOP-TF687VE:~/OmBlockchain/OmSui$ sui client envs        

In the above my sui client is connected to devnet.

Switching the env :

sui client switch --env <ALIAS>
Ex; amit@DESKTOP-TF687VE:~/OmBlockchain/OmSui$ sui client switch --env localnet        



How to launch the blockchain in local PC?

To start the local network, run the following command from your sui root folder.

amit@DESKTOP-TF687VE:~$ RUST_LOG="off,sui_node=info" ./sui-test-validator        

The output looks like below :

For various options to strat the full node please use below command :

sui-test-validator --help         

Access the local Full node using the curl:

curl --location --request POST 'https://0.0.0.0:9000' \
--header 'Content-Type: application/json' \
--data-raw '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "sui_getTotalTransactionBlocks",
  "params": []
}'        

We see the output as below underlined in red color:

Building the package/smartContract & deploying in the network

When we build the smart contract for the sui, we use below command :

$ sui move build         

Sui client address :

amit@DESKTOP-TF687VE:$ sui client active-address
0xa9b4ce1301c66d7c4e4f97b1292d1b97c6316aa9ef96c833cb5540a888ea5c11        

Requesting Coins using the client:

amit@DESKTOP-TF687VE:$ sui client faucet
Request successful. It can take up to 1 minute to get the coin. Run sui client gas to check your gas coins.        


Balance checking using the client:

amit@DESKTOP-TF687VE:$ sui client balance        

or we can check using objects also :

amit@DESKTOP-TF687VE:~ $ sui client objects        

Publishing the move package in sui network:

The output of the command "sui client publish --gas-budget 100000000" is the transaction digest, which is a unique identifier of the transaction and can be used to query the transaction status.

Transaction Data

The section titled TransactionData contains the information about the transaction we just sent.

It features fields like sender, gas_budget set with the --gas-budget argument, and the Coin we used for payment.

Transaction Effects

Transaction Effects contains the status of the transaction, the changes that the transaction made to the state of the network and the objects involved in the transaction.

Events

If there were any events emitted, you would see them in this section. Our package does not use events, so the section is empty, as you see above.


Object Changes

These are the changes to objects that transaction has made. It has 3 sections in our case ;

  1. created a new UpgradeCap object which is a special object that allows the sender to upgrade the package in the future,
  2. mutated the Gas object.
  3. published a new package. Packages are also objects on Sui.

Balance Changes

This last section contains changes to SUI Coins, in our case, we have spent around 0.012 SUI, which in MIST is 8275480. You can see it under the amount field in the output in the above screenshot.


Sending Transactions:

I am faced issues in sending the transactions in devnet, for which I have raised the Issue. I will update this once I resolve my issue.

I update my env to local then I am able to send the transactions:

Prepare the env Variables as below:

amit@DESKTOP-TF687VE:~$  export PACKAGE_ID=0x95a7aa2ff2b1d11f8d188ecebe62b9c90855bbeb5d78bcbb21d4d0c17824cb03

amit@DESKTOP-TF687VE:~/$ export MY_ADDRESS=$(sui client active-address)        

Sending the tranmsaction:

sui client ptb \
--gas-budget 100000000 \
--assign sender @$MY_ADDRESS \
--move-call $PACKAGE_ID::todo_list::new \
--assign list \
--transfer-objects "[list]" sender        

Then you will o/p as below :





In the above todo-list is created.


Now let's push some elements to the to-do list:

Passing Objects to Functions

The TodoList that we created in the previous step is an object that you can interact with as its owner. You can call functions defined in the todo_list module on this object. To demonstrate this, we will add an item to the list. First, we will add just one item, and in the second transaction, we will add 3 and remove another one.

Double-check that you have variables set up from the previous step, and then add one more variable for the list object.

export LIST_ID=0x4925ee58c94f3c6e145c9912804f2e82a071f44394dd647dbf7063905ed49769        


Adding the item to list

We can push the item to the list using below commands:

sui client ptb --gas-budget 100000000 --move-call $PACKAGE_ID::todo_list::add @$LIST_ID "'Jai Shree Ram'"        


lets push one more item :

sui client ptb --gas-budget 100000000 --move-call $PACKAGE_ID::todo_list::add @$LIST_ID "'Jai Bajrang Bali"        

We can check the object id as below:


Removing the element from the list :


$--move-call $PACKAGE_ID::todo_list::remove @$LIST_ID 0        

Reference :

Install Sui | Sui Documentation

Hello, Sui! - The Move Book (move-book.com)


要查看或添加评论,请登录

社区洞察

其他会员也浏览了