Cairo Optimization
Apply only after tests pass and behavior is locked.
When to Use
- Improving gas/resource usage in hot paths.
- Rewriting expensive loops/arithmetic patterns.
- Optimizing storage layout and integer choices.
When NOT to Use
- Early feature prototyping without tests.
- Security review as a substitute for correctness proofs.
Quick Start
- Confirm baseline behavior with tests.
- Profile target paths with
python3 scripts/profile.py profile. - Apply one optimization class at a time.
- Re-run tests and compare resource deltas.
- Use anti-pattern/secure-pattern pairs to keep micro-optimizations explicit.
- Encode stable optimization rules in
../evals/cases/contract_skill_benchmark.jsonlto prevent regressions. - Run
cairo-auditoron touched files to ensure no security regressions were introduced.
Workflow
- Main optimization flow: default workflow
References
- Detailed optimization rules: legacy reference
- Profiling workflow and troubleshooting: profiling reference
- Optimization anti-pattern pairs: anti-pattern pairs
- Module index: references index