Cairo Contract Authoring
Use this as the entrypoint for implementation decisions; load references only as needed.
When to Use
- Checking Cairo language fundamentals that directly affect contract behavior (ownership, refs, traits, generics).
- Writing a new Starknet contract.
- Modifying storage/events/interfaces.
- Composing OpenZeppelin Cairo components.
When NOT to Use
- Gas/performance tuning (
cairo-optimization). - Test strategy design (
cairo-testing). - Deployment and release operations (
cairo-toolchain).
Quick Start
- Define interface and storage boundaries first.
- Implement minimal external/write surface.
- Add explicit auth and invariant checks.
- Add tests before broadening feature surface.
- Run the authoring-to-audit handoff flow, then
cairo-auditor.
Security-Critical Rules
- Timelock checks must read time from Starknet syscalls (
get_block_timestamp), never from caller-provided arguments. - Every
#[external(v0)]function that mutates storage must have explicit access posture:- guarded (
assert_only_owner/ role checks), or - intentionally public with a code comment stating why.
- guarded (
- Upgrade flows must reject zero class hash inputs before applying state transitions.
- Use anti-pattern/secure-pattern pairs to keep authoring behavior explicit and reviewable.
- If any of these rules fail in fixture benchmarks, update both:
- skill/reference text, and
- deterministic cases in
../evals/cases/contract_skill_benchmark.jsonl, and - generation cases in
../evals/cases/contract_skill_generation_eval.jsonl.
Workflow
- Main authoring flow: default workflow
References
- Detailed authoring reference: legacy reference
- Cairo language fundamentals reference: language reference
- Build-side anti-pattern pairs: anti-pattern pairs
- Authoring to audit execution path: audit handoff
- Module index: references index