By: Johan & Victory!
background
Some time ago, we discussed the characteristics of TON and user asset security issues in Getting to Know TON: Accounts, Tokens, Transactions and Asset Security. Today, let’s learn about another emerging high-performance blockchain platform - Sui, which has many innovative technologies and unique features that have attracted the attention of developers and researchers. Sui focuses on providing a fast and secure transaction experience suitable for various application scenarios. This article will help readers understand Sui by explaining Sui’s account model, token management, transaction mechanism and asset security.
Account Model
address
Sui follows widely accepted wallet specifications in the cryptocurrency industry, including BIP-32 (and its variant SLIP-0010), BIP-44, and BIP-39 to provide key management for users.
To derive a 32-byte Sui address, Sui concatenates the signature scheme flag (1 byte) with the public key bytes using the BLAKE2b (256-bit output) hash function. Sui addresses currently support pure Ed25519, Secp256k1, Secp256r1, and MultiSig, with the corresponding flag bytes being 0x00, 0x01, 0x02, and 0x03, respectively.
Balance
On Sui, everything is an object, including the user's balance. During the transfer process, if the balance contained in the object is not equal to the required value, the object needs to be split or merged. For example, if you have an object containing 100 SUI, but you only want to transfer 30 SUI, the system will split the object into two objects: one containing 30 SUI and the other containing 70 SUI. You can transfer the object containing 30 SUI and keep the remaining objects. Conversely, if a larger amount is needed, you can also merge multiple balance objects to form a larger amount object.
Token Management
Sui officially implements the standard code of Coin. When issuing Coin, developers only need to call `use sui::coin;` in the contract to use all the functions of this standard library.
Since Move is used, which is different from other commonly used programming languages for blockchains (such as Solidity), developers need to understand and pay attention to some unique functions or features when using it. Let's take a look at a piece of code:
This is a complete Coin issuance contract. The smart contract design on Sui is different from blockchain platforms such as Ethereum or Solana. We cannot see the management of permissions in the source code. When creating a Coin using this function (coin::create_regulated_currency), the creator of the contract receives a TreasuryCap object, which is required to mint new coins or destroy existing coins. Only addresses that have access to this object can maintain Coin issuance.
For the user who receives the Coin, his account controls the ownership of these tokens. When calling the smart contract to use these tokens, these objects also need to be passed in and the transaction needs to be signed.
Trading Mechanism
Transactions are a basic concept in the blockchain world, and they are a way to interact with a blockchain. Transactions are used to change the state of a blockchain, and they are the only way to do so. In the Move programming language used by Sui, transactions are used to call functions in packages, deploy new packages, and upgrade existing packages.
When constructing transactions, it is important to note that each transaction must explicitly specify the object of its operation! This is somewhat similar to Solana's transaction requiring the account to be passed in.
The transaction includes:
Sender -- the account that signed the transaction
A list of commands (or command chains) -- the operations to be performed
Command input -- the command's arguments: plain text -- a simple value like a number or string, or object -- the object the transaction will access
Gas object -- Coin object used to pay for the transaction
Gas Prices and Budgets — Transaction Costs
Contract Security
Sui uses Move as the programming language for smart contracts, which can solve the common vulnerabilities of Solidity to a certain extent, such as reentrancy attacks, integer overflows, double spending, DoS attacks, and compiler problems, but it cannot prevent developers from introducing errors in the code, so security audits are still necessary. The following are some things that developers need to pay attention to during the development process:
1. Permission check: Analyze the object type received by the external function. For privileged functions involving sensitive operations, it is necessary to ensure that the object passed in is a privileged object. If the function receives and uses a privileged object, the function caller must be the legal owner of the object.
2. Check external functions: Some functions themselves should not be called directly from the outside. If there is a function interface that should not be released externally, the developer should propose that the function should not be made public.
3. Object analysis check: Since objects in Sui can be converted into shared objects, developers need to sort out the types of all objects used, confirm whether they are static or public, and whether there are any errors. If an object that should be privatized is converted into a public object, then anyone can use this object, which poses a security risk.
4. Coin consumption check: Sui’s token model is different from other chains. Its design allows token objects to be contained and held by other objects, and can also be split, which derives several token consumption modes:
Directly transfer a token object to another object;
The token object is restructured to generate a new object, which is then transferred to the target object;
Split a token object and transfer the split parts to a new object.
Therefore, in the case of token consumption, developers need to check the following points:
Whether the amount consumed is correct;
Whether the object has been transferred;
If there is a split, is the amount of the split correct?
5. Oracle price manipulation attack: If the contract on Sui uses an oracle to obtain prices, then you also need to pay attention to the possibility of price manipulation. Developers can prevent the risk of a single data source being manipulated by introducing multiple data sources and consensus mechanisms. In addition, the time-weighted average price can also be used to prevent the risk of oracle manipulation.
6. Governance attacks: In the contract on Sui, if the voting rights of the governance token are not designed reasonably, there is also a risk of governance attacks. In this regard, you can refer to the community governance logic of some mature decentralized organizations.
7. Arbitrage attack: If the logic design is not reasonable, the DeFi contract on Sui is also at risk of arbitrage attack. Developers should carefully review the logic in the contract during development to avoid being exploited by attackers.
8. Fake recharge attack: When processing Sui token recharge, exchanges or developers also need to check whether the transaction status is successful and whether the token’s Package ID is correct to prevent fake recharge attacks.
Summarize
In this article, we briefly explore the design features of Sui, including its account model, token management, transaction mechanism, and contract security. Using the Move programming language, Sui not only ensures high performance and low latency, but also introduces innovative data models and object storage methods, significantly improving security and flexibility. Compared with other blockchain platforms, the Move language performs well in preventing common smart contract vulnerabilities (such as overflows, reentrancy attacks, etc.), which makes Sui more robust and reliable on a technical level. However, developers still need to pay attention to security at the business logic level, especially in terms of permission management, use of object types, and token consumption, and beware of asset losses due to errors or improper design in the code.
Reference Links:
https://docs.sui.io/
https://docs.sui.io/standards/coin
https://move-book.com/