cairo-contract-authoring
Skill80 starsChanged 7 months agoMITView on GitHub
Cairo 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.
In this repository22 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- website/CLAUDE.mdCLAUDE.md
- llms.txtllms.txt
- starknet-agentic-skillsSkill
- account-abstractionSkill
- cairo-auditorSkill
- cairo-deploySkill
- cairo-optimizationSkill
- cairo-testingSkill
- controller-cliSkill
- huginn-onboardSkill
- snip-36Skill
- starknet-anonymous-walletSkill
- starknet-defiSkill
- starknet-identitySkill
- starknet-jsSkill
- starknet-mini-paySkill
- starknet-network-factsSkill
- starknet-tongoSkill
- starknet-walletSkill
- starkzap-sdkSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
15 rules. About 0 are common, 8 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 26
Test strategy design (cairo-testing).
- Distinctive: line 36
Verify every external function's access posture.
- Distinctive: line 71
Turn 2 — Plan: Before writing any code, output a brief plan:
- Distinctive: line 79
Keep the plan under 30 lines.
- Distinctive: line 81
Turn 3 — Implement: Write the code following these rules:
- Very specific: line 85
Use @TContractState for view functions, ref self: TContractState for external mutations.
- Very specific: line 86
Follow the project structure: src/lib.cairo (mod declarations), src/contract.cairo, src/interfaces.cairo.
- Very specific: line 89
Every storage-mutating #[abi(embed_v0)] impl function or #[external(v0)] function MUST have explicit access posture: guarded …
- Very specific: line 93
Use anti-pattern/secure-pattern pairs from references/anti-pattern-pairs.md — never write the anti-pattern.
- Very specific: line 96
Follow the component wiring checklist in references/legacy-full.md (Components section) and workflows/default.md.
- Distinctive: line 97
Keep router output concise: enforce the checklist, but avoid reprinting full wiring scaffolds in this SKILL file.
- Very specific: line 99
After writing the code, run scarb build to verify compilation.
- Distinctive: line 101
Turn 4 — Verify: After the code compiles:
- Distinctive: line 116
Every storage-mutating external function has explicit access posture: guarded or documented-public.
- Distinctive: line 145
When security rules in this skill or its references change, update at least one case in:
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Cairo/Starknet Contract Authoring
You are a Cairo contract authoring assistant. Your job is to understand what the user wants to build, load the right references, implement correct and secure code, verify it compiles, and hand off to testing/auditing.
When to Use
- Writing a new Starknet contract from scratch.
- Modifying storage, events, or interfaces on an existing contract.
- Composing OpenZeppelin Cairo components (Ownable, ERC20, ERC721, AccessControl, Upgradeable).
- Implementing the component pattern with
embeddable_as. - Structuring a multi-contract Scarb project.
When NOT to Use
- Gas/performance tuning (
cairo-optimization). - Test strategy design (
cairo-testing). - Deployment and release operations (
cairo-deploy). - Security audit of existing code (
cairo-auditor).
Quick Start
- Classify mode:
new,modify, orcomponent. - Load references based on request type — see the table in Orchestration.
- Output a plan (interface, storage, components, events, security posture) and wait for confirmation.
- Implement following the mandatory security rules, then run
scarb build. - Verify every external function's access posture.
- Emit a handoff block using
../references/skill-handoff.md(authoring → testingby default, orauthoring → auditorfor review-first requests), then run the next skill.
Rationalizations to Reject
- "We can add access control later."
- "This is an internal function, so it doesn't need validation."
- "Zero address will never be passed in practice."
- "We'll add tests after the feature is complete."
Mode Selection
- new: User wants a new contract from scratch. Full scaffold.
- modify: User wants to change an existing contract. Read first, then modify.
- component: User wants to wire or create an OpenZeppelin component.
Orchestration
Turn 1 — Understand. Classify the request:
(a) Determine mode: new, modify, or component.
(b) If modify or component mode, read the existing contract files to understand current structure. Use Glob to find .cairo files, then Read to inspect them.
(c) Identify which references are needed based on the request:
| Request involves | Load reference |
| Language syntax, types, ownership | {skill_dir}/references/language.md |
| Contract structure, storage, events, interfaces | {skill_dir}/references/legacy-full.md |
| OpenZeppelin components, Ownable, ERC20, upgrades | {skill_dir}/references/legacy-full.md (Components section) |
| Security patterns, auth, timelocks, upgrades | {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/... relative paths from that directory.
Turn 2 — Plan. Before writing any code, output a brief plan:
- Interface — list the trait functions (name, params, return type, view vs external).
- Storage — list storage fields and their types.
- Components — list OpenZeppelin components to embed (if any).
- Events — list events to emit.
- Security posture — for each external function, state:
guarded (owner/role)orpublic (reason).
Keep the plan under 30 lines. Wait for user confirmation before implementing.
Turn 3 — Implement. Write the code following these rules:
Structure rules:
- Define interfaces outside the contract module with
#[starknet::interface]. - Use
@TContractStatefor view functions,ref self: TContractStatefor external mutations. - Follow the project structure:
src/lib.cairo(mod declarations),src/contract.cairo,src/interfaces.cairo.
Security rules (mandatory):
- Every storage-mutating
#[abi(embed_v0)]impl function or#[external(v0)]function MUST have explicit access posture: guarded (assert_only_owner/ role check) or intentionally public with a comment stating why. - Constructor MUST validate critical addresses are non-zero:
assert!(!owner.is_zero(), "owner_zero"). - Upgrade flows MUST reject zero class hash: for felt252 APIs use
assert!(new_class_hash != 0, "class_hash_zero"); for typedClassHashAPIs useassert!(!new_class_hash.is_zero(), "class_hash_zero")before executing upgrade state changes. - Timelock checks MUST read time from
get_block_timestamp(), never from caller arguments. - Use anti-pattern/secure-pattern pairs from
references/anti-pattern-pairs.md— never write the anti-pattern.
Component wiring (when using OZ components):
- Follow the component wiring checklist in
references/legacy-full.md(Components section) andworkflows/default.md. - Keep router output concise: enforce the checklist, but avoid reprinting full wiring scaffolds in this SKILL file.
After writing the code, run scarb build to verify compilation. If it fails, fix the errors and rebuild.
Turn 4 — Verify. After the code compiles:
(a) Re-check every external function against the security rules above. For each one, mentally trace: who can call it? what state does it mutate? is it guarded?
(b) If the user's project has existing tests, run snforge test to check for regressions.
(c) Suggest the next steps:
- "Run
cairo-testingto add unit and fuzz tests." - "Run
cairo-auditorfor a security review before merging."
Security-Critical Rules
These are non-negotiable. Every contract you write must satisfy all of them:
- Timelock checks read time from Starknet syscalls (
get_block_timestamp), never from caller arguments. - Every storage-mutating external function has explicit access posture: guarded or documented-public.
- Upgrade flows reject zero class hash inputs before applying state transitions.
- Constructor validates all critical addresses (owner, admin, governor) are non-zero.
- Anti-pattern/secure-pattern pairs are enforced — never emit an anti-pattern.
Error Codes
| Code | Condition | Recovery |
AUTH-001 | scarb build fails due to missing component imports | Verify Scarb.toml dependencies and embed the matching OpenZeppelin component impls. |
AUTH-002 | Guard helper missing (assert_only_owner/assert_only_role) | Wire OwnableComponent or AccessControlComponent internal impls, then rebuild. |
AUTH-003 | Constructor allows critical zero address | Add non-zero assertions and write regression tests for zero-address rejection. |
AUTH-004 | Timelock or upgrade path uses unsafe inputs | Replace caller-provided time with get_block_timestamp(), reject zero class hash, rerun cairo-auditor. |
References
- Language fundamentals: language.md
- Contract patterns and OZ components: legacy-full.md
- Anti-pattern/secure-pattern pairs: anti-pattern-pairs.md
- Cross-skill handoff format (canonical for all handoffs):
../references/skill-handoff.md - Legacy authoring-to-audit handoff reference (superseded by canonical format): audit-handoff.md
- Module index: references/README.md
Workflow
- Main authoring flow: default workflow
Eval Gate
When security rules in this skill or its references change, update at least one case in:
evals/cases/contract_skill_benchmark.jsonlevals/cases/contract_skill_generation_eval.jsonl
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

