public/SKILLS/Web3 & Blockchain/gas-optimization/SKILL.md
Aptos gas optimization expert for Move smart contracts. Covers storage costs, execution efficiency, inline functions, aggregators for parallel execution, Table vs SmartTable vs vector tradeoffs, event optimization, struct packing, and gas profiling tools.
npx skillsauth add eric861129/skills_all-in-one aptos-gas-optimizationInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Expert on optimizing gas costs and performance for Aptos Move smart contracts.
Total Gas Cost = Execution Gas + Storage Gas + IO Gas
Gas Fee (APT) = Gas Units x Gas Unit Price
1 APT = 100,000,000 octas
| Structure | Read | Write | Best For | |-----------|------|-------|----------| | vector | O(n) | O(n) | Small lists (<1000) | | SimpleMap | O(n) | O(n) | Small maps (<1000) | | Table | O(1) | O(1) | Large maps | | SmartTable | O(1) | O(1) | Very large maps (100k+) | | Aggregator | O(1) | O(1) | Parallel counters |
use aptos_framework::aggregator_v2::{Self, Aggregator};
struct Stats has key {
total_users: Aggregator<u64> // Concurrent-safe!
}
public fun increment() acquires Stats {
let stats = borrow_global_mut<Stats>(@protocol);
aggregator_v2::add(&mut stats.total_users, 1);
// Multiple txns can do this in parallel!
}
inline fun min(a: u64, b: u64): u64 {
if (a < b) a else b
}
// Bad: calls length() every iteration
while (i < vector::length(v)) { ... }
// Good: cache length
let len = vector::length(v);
while (i < len) { ... }
#[event]
struct TransferEvent has drop, store {
from: address,
to: address,
amount: u64,
}
event::emit(TransferEvent { from, to, amount });
// Bad: 8 bytes wasted on padding
struct Data { flag1: bool, value1: u64, flag2: bool, value2: u64 }
// Good: group bools together
struct Data { flag1: bool, flag2: bool, value1: u64, value2: u64 }
// Best: pack into bitmap
struct Data { flags: u8, value1: u64, value2: u64 }
// Bad for large datasets
struct Registry { users: vector<User> }
// Good for large datasets
struct Registry { users: Table<address, User> }
// Best for very large datasets (100k+)
struct Registry { users: SmartTable<address, User> }
// Single transaction for multiple transfers
public entry fun batch_transfer(
sender: &signer,
recipients: vector<address>,
amounts: vector<u64>
) { ... }
// Check cheapest conditions first
if (amount == 0) return;
if (amount >= MAX) return;
if (!is_valid(user)) return;
// Then do expensive work
# Run tests with gas profiling
aptos move test --gas
# Simulate transaction
aptos move run --function-id 0x1::module::func --profile gas
development
Run structured What-If scenario analysis with multi-branch possibility exploration. Use this skill when the user asks speculative questions like "what if...", "what would happen if...", "what are the possibilities", "explore scenarios", "scenario analysis", "possibility space", "what could go wrong", "best case / worst case", "risk analysis", "contingency planning", "strategic options", or any question about uncertain futures. Also trigger when the user faces a fork-in-the-road decision, wants to stress-test an idea, or needs to think through consequences before committing.
development
Access comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
development
Use when challenging ideas, plans, decisions, or proposals using structured critical reasoning. Invoke to play devil's advocate, run a pre-mortem, red team, or audit evidence and assumptions.
tools
Core skill for the deep research and writing tool. Write scientific manuscripts in full paragraphs (never bullet points). Use two-stage process with (1) section outlines with key points using research-lookup then (2) convert to flowing prose. IMRAD structure, citations (APA/AMA/Vancouver), figures/tables, reporting guidelines (CONSORT/STROBE/PRISMA), for research papers and journal submissions.