Sui.

帖子

分享您的知识。

Benjamin XDV.
Jun 30, 2025
专家问答

What Are Common Security Pitfalls in Sui Move Development?

I’m auditing a Sui Move smart contract and want to avoid critical vulnerabilities. From reviewing past exploits, I’ve seen: access control issues, arithmetic overflows, reentrancy risks, frontrunning, improper object ownership

Questions:

What are the most critical Sui Move vulnerabilities to watch for?

How does Move’s ownership model prevent/differ from traditional reentrancy?

Are there Sui-specific attack vectors (e.g., object spoofing)?

  • Sui
  • Architecture
5
2
分享
评论
.

答案

2
Evgeniy CRYPTOCOIN.
Jun 30 2025, 18:08

回答

1. Sui Move 中的五大安全陷阱

访问控制不当

风险:任何人都可以调用本应限制的函数.

示例:

move
public fun admin_withdraw(signer: &signer) { // No check!  
    withdraw_coins(signer, ...);  
}  

修复:

move
public fun admin_withdraw(signer: &signer, admin_cap: &AdminCap) {  
    assert!(address_of(signer) == admin_cap.admin, EUnauthorized);  
}  

关键见解:使用能力模式(AdminCap、ownerCap)来控制敏感操作.

算术溢出/下溢

风险:u64 的数学运算是静默的(例如,余额变为 0 → 2^64-1).

示例:

move
let total = user_balance + deposit_amount; // Overflow possible  

修复:

move
use sui::math;  
let total = math::checked_add(user_balance, deposit_amount)?;  

专家提示:请务必使用:

math:: checked_*(添加/sub/mul/div)

余额:: join () /split () 用于硬币.

共享对象竞赛条件

风险:同时修改共享对象(例如 AMM 池)会导致损坏状态.

示例:

move
// Two TXNs read pool.reserves simultaneously → bad swap rates  

修复:

尽可能只使用 &mut.

对于共享对象,设计等效运算(例如,要求随机抽取 TXN 摘要).

Sui 的优势: Move 的类型系统可以防止重入(与 Solidity 不同),但共享对象仍然可以竞争.

领跑和 MEV

风险:矿工重新排序 TxN 以获取价值(例如,三明治攻击).

示例:

move
// AMM swap with no slippage check:  
let dy = reserve_y * dx / reserve_x; // Miner can manipulate `reserve_x/y`  

修复:

需要 min_received 参数:


move
assert!(dy >= min_dy, EInsufficientOutput);  

使用截止日期检查:

move
assert!(tx_context::epoch(ctx) <= deadline, EExpired);  
Phantom Type Confusion
Risk: Using the wrong type parameter (e.g., mixing Coin<USD> and Coin<USDC>).

示例:

move
public fun merge_coins<C>(a: Coin<C>, b: Coin<C>) { ... }  
// Can be called with `Coin<USD>` and `Coin<USDC>` if `C` isn’t constrained!  

修复:

move
constraint C: store + drop; // Restrict valid types  

2. Sui 专属攻击向量

物体欺骗 风险:通过恶意 RPC 调用注入的虚假对象. 防御:

务必验证对象所有权(有密钥和所有者字段).

使用对象 ID 白名单进行关键操作.

动态场劫持 风险:攻击者向您的对象添加恶意动态字段. 防御:

仅在必要时使用 store 标记对象.

对敏感数据使用私有包装器.

5
最佳答案
评论
.
0xduckmove.
Jun 30 2025, 18:52

有一篇关于在 Sui 上进行构建的安全最佳实践的文章. 看看这个太棒了 https://blog.sui.io/security-best-practices/

0
评论
.

你知道答案吗?

请登录并分享。

Sui is a Layer 1 protocol blockchain designed as the first internet-scale programmable blockchain platform.

352帖子499答案
Sui.X.Peera.

赚取你的 1000 Sui 份额

获取声誉积分,并因帮助 Sui 社区成长而获得奖励。

奖励活动七月