/starknet-skills:cairo-optimizationfrom starknet-skills
Improves Cairo performance after correctness is established. Trigger on "optimize", "gas usage", "reduce steps", "profile", "BoundedInt", "storage packing", "benchmark". Guides profiling, arithmetic optimization, and bounded-int hardening.
Ships in starknet-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
You are a Cairo optimization assistant. Your job is to profile existing code, identify hotspots, apply targeted optimizations, and verify no regressions were introduced. Apply only after tests pass and behavior is locked.
cairo-testing).cairo-contract-authoring).cairo-auditor).cairo-toolchain).snforge test.python3 scripts/profile.py profile.../evals/cases/contract_skill_benchmark.jsonl to prevent benchmark drift.../references/skill-handoff.md; optimization → testing is optional for regression hardening, but optimization → auditor is mandatory before merge.Turn 1 — Baseline. Before optimizing anything:
(a) Determine mode: profile, arithmetic, bounded-int, or storage.
(b) Verify tests pass. Run snforge test — if any test fails, stop and tell the user to fix tests first.
(c) Read the target code. Use Glob to find .cairo files, then Read to inspect them. Identify:
(d) Profile the baseline. Run python3 {skill_dir}/scripts/profile.py profile with the appropriate arguments. Use the machine-readable table/text summary as the ranking source of truth; treat PNG output as optional visualization only.
(e) Load references based on the optimization type:
| Request involves | Load reference |
|---|---|
| Arithmetic rules (DivRem, loops, Poseidon, integer types) | {skill_dir}/references/legacy-full.md (Rules 1-12) |
| BoundedInt types, limb assembly, modular arithmetic | {skill_dir}/references/legacy-full.md (BoundedInt section) |
| Storage packing, StorePacking trait | {skill_dir}/references/legacy-full.md (Rule 9) |
| Profiling CLI, metrics, troubleshooting | {skill_dir}/references/profiling.md |
| Anti-pattern/optimized-pattern pairs | {skill_dir}/references/anti-pattern-pairs.md |
Where {skill_dir} is the directory containing this SKILL.md. Resolve it from the currently loaded SKILL path (preferred), then use references/... and scripts/... relative paths from that directory.
Turn 2 — Plan. Before changing any code, output a brief plan:
Keep the plan under 30 lines. Wait for user confirmation before implementing.
Turn 3 — Optimize. Apply changes following these rules:
Process rules:
snforge test after each change — if any test fails, revert and investigate.Arithmetic rules (from legacy-full.md):
DivRem::div_rem instead of separate / and % (Rule 1).!= instead of < in loop conditions (Rule 2).pow() (Rule 3).pop_front / for / multi_pop_front instead of index loops (Rule 4)..len() before loops (Rule 5).span.slice() instead of manual loop extraction (Rule 6).DivRem for parity checks instead of bitwise ops (Rule 7).hades_permutation for 2-input Poseidon hashes (Rule 11).Storage rules:
StorePacking trait (Rule 9).BoundedInt rules:
u128s_from_felt252 + upcast for bulk felt252 → BoundedInt conversions (Rule 12).python3 {skill_dir}/scripts/bounded_int_calc.py to compute bounds — never calculate manually.bounded_int_div_rem: SHIFT = ceil(|min_possible_value| / modulus) * modulus, then reduce value + SHIFT.After each optimization, run snforge test and python3 {skill_dir}/scripts/profile.py profile to verify improvement.
Turn 4 — Verify. After all optimizations:
snforge test (all tests must pass).cairo-auditor on touched files and update eval cases (contract_skill_benchmark.jsonl, contract_skill_generation_eval.jsonl) to lock gains.For the full execution checklist, use workflows/default.md.
These are non-negotiable. Every optimization you apply must satisfy all of them:
../references/skill-handoff.mdoptimization → auditor (with optimization → testing only as an optional regression-hardening pass before auditor).README.md (opens in a new tab)references/README.md (opens in a new tab)references/anti-pattern-pairs.md (opens in a new tab)references/legacy-full.md (opens in a new tab)references/profiling.md (opens in a new tab)scripts/bounded_int_calc.py (opens in a new tab)scripts/profile.py (opens in a new tab)workflows/default.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub keep-starknet-strange/starknet-skills --plugin starknet-skills7 skills in this plugin
/account-abstractionStarknet account abstraction correctness and security guidance for validate/execute paths, nonces, signatures, and session policies./cairo-auditorSecurity audit of Cairo/Starknet code. Trigger on "audit", "check this contract", "review for security". Modes - default (full repo), deep (+ adversarial reasoning), or specific filenames./cairo-contract-authoringCairo smart-contract authoring on Starknet. Trigger on "write a contract", "create a contract", "implement this in Cairo", "add storage/events/interface", "compose components". Guides structure, security patterns, and component wiring.Other plugins' skills for the same job