Sui Hub Workshop — 30 Minutes
Secure Contracts • Testing Practices • Cost Optimization
Use ← → arrow keys or click to navigate
Access control vulnerabilities caused 58% of all losses in 2025. On Sui, every shared or immutable object input must be treated as attacker-controlled.
Assign the minimum abilities required. Excessive abilities create attack surface.
key only — cannot be transferred. Bound to owner forever. Best for admin rights.
key, store — can be sold or traded. Use when rights should be marketable.
AdminCap via share_object lets anyone call admin functions.Requires owner signature. Parallel execution. Best for wallets, personal items.
Anyone can access. Needs consensus. Slower, more expensive. Use sparingly.
| Vulnerability | Impact | Fix |
|---|---|---|
| Excessive abilities | Unexpected transfers, drops | Minimal abilities only |
| Shared AdminCap | Anyone becomes admin | Transfer to deployer |
| Unvalidated generics | Wrong coin type accepted | Include type in signature |
| Dynamic field collision | Data overwrite | Check contains before add |
| ID leak | Object ID reuse | Only fresh IDs from object::new |
| Coin metadata unfrozen | Admin changes token info | public_freeze_object |
Public functions with generic <COIN> accept any coin type. Without validation, users can pay with worthless tokens.
Unit tests, scenario testing & debugging your contracts
Sui Move has built-in test support. Write tests in the same file or a tests/ directory.
#[expected_failure] for abort tests.Use #[test_only] to expose internal state for testing without polluting your public API.
• Happy path works
• #[expected_failure] on bad inputs
• Zero/edge amounts
• Unauthorized access blocked
• Object ownership verified
• sui move test — run all tests
• sui move test --gas-limit 1000000
• std::debug::print(&value) in tests
• sui client publish --dry-run
Storage, computation & transaction cost optimization on Sui
Sui gas = computation + storage. Unlike Ethereum, storage is a deposit you get back when deleting objects.
• Bytecode execution
• Native function calls
• Transaction processing
Fixed per tx + variable per op
• Object creation
• Dynamic field addition
• Event emission
Deposit refunded on deletion
| Technique | Savings | How |
|---|---|---|
| Prefer owned objects | ~50-80% | No consensus overhead vs shared |
| Batch in PTBs | ~30-50% | One tx fee for 1,024 ops |
| Avoid dynamic fields | ~20% | Direct wrapping is cheaper |
| Delete unused objects | Refund | Get storage deposit back |
| Minimize event data | ~10% | Only emit essential fields |
| Use entry functions | ~5-10% | Simpler call graph = less gas |
Move Security & Gas Tuning
DOCS docs.sui.io/build/move/security
COURSE github.com/sui-foundation/sui-move-intro-course
CLI sui move test | sui client publish --dry-run
Thanks for joining — build secure & efficient contracts on Sui!