Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsCommunityBlog
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

Back to skills

Cairo Scanner

ASecurity

Use when the user wants to audit Cairo smart contracts for security vulnerabilities, scan Starknet contracts for felt overflow, storage collision, or account abstraction issues, review Cairo 2.x contracts for component architecture flaws, or analyze STARK-based protocols for cryptographic and computational errors.

61 stars
0 votes
0 copies
0 views
Added 9/19/2026
securityrustgoawssecurity

Security Analysis

A100/100

Scanned 9/19/2026

Install to Claude Code

$npx -y skills add 0x-Shashi/WEB3-AUDIT-SKILLS --skill cairo-scanner --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Cairo Scanner?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Cairo Scanner
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/0x-shashi-cairo-scanner/badge)](https://www.skillsdirectory.com/skills/0x-shashi-cairo-scanner)

More formats (shields.io, HTML) on the badges page.

Download Zip
Files
SKILL.md
---
id: SCANNER-CAIRO
title: Cairo Smart Contract Security Scanner
category: chain-scanner
chains: [starknet]
languages: [cairo]
version: cairo-2.x
last_updated: 2026-02-24
description: >-
  Use when the user wants to audit Cairo smart contracts for security
  vulnerabilities, scan Starknet contracts for felt overflow, storage collision,
  or account abstraction issues, review Cairo 2.x contracts for component
  architecture flaws, or analyze STARK-based protocols for cryptographic and
  computational errors.
---

# Cairo Scanner Skill

## Purpose

Analyze Cairo smart contracts deployed on Starknet for security vulnerabilities. Cairo's unique computational model — based on field elements (felts), STARK proofs, and native account abstraction — creates attack surfaces that don't exist on EVM chains.

## Cairo Security Model

| Property | Cairo/Starknet | EVM/Solidity |
|----------|---------------|-------------|
| Integer type | Felt252 (field element, $0$ to $P-1$ where $P = 2^{251} + 17 \cdot 2^{192} + 1$) | uint256, int256 |
| Arithmetic | Modular (wraps around $P$) | Checked (reverts in Solidity 0.8+) |
| Division | Modular inverse (not integer division) | Integer truncation |
| Account model | All accounts are smart contracts (native AA) | EOAs + smart contracts |
| Upgrades | `replace_class_syscall` (instant) | Proxy patterns (delegatecall) |
| Storage | Pedersen hash-based addresses | Sequential slots (keccak256) |
| L1 interaction | L1-L2 messaging via Starknet Core on Ethereum | Bridges required |
| Proving | STARK proofs for L1 verification | No proofs needed |

## Detection Capabilities

### Critical — Direct Fund Loss

| Vulnerability | Description | Detection Signal |
|---------------|-------------|-----------------|
| **Felt overflow wrapping** | Arithmetic on felt252 wraps around $P$, enabling underflow/overflow | Felt252 used for balances or amounts without range checks |
| **Unprotected `replace_class_syscall`** | Anyone can upgrade the contract logic | `replace_class_syscall` without `assert_only_owner` or equivalent |
| **L1-L2 message replay** | Same L1→L2 message consumed multiple times | Missing nonce or message hash tracking in `l1_handler` |
| **Account validation bypass** | Custom `__validate__` skips critical checks | `__validate__` returns success without signature verification |
| **Storage collision** | Two different state variables map to same storage slot | Custom `storage_address_from_base` with colliding inputs |

### High — Significant Impact

| Vulnerability | Description | Detection Signal |
|---------------|-------------|-----------------|
| **Reentrancy via `call_contract_syscall`** | External contract call re-enters before state update | `call_contract_syscall` before storage writes |
| **Missing caller validation** | External function callable by anyone | `get_caller_address()` not checked in sensitive functions |
| **Felt252 comparison pitfalls** | Comparing felts that represent "negative" numbers (near $P$) | `<` or `>` on felts where semantic negativity matters |
| **Component storage isolation failure** | Components sharing storage addresses | Overlapping `#[storage]` declarations across components |
| **Incorrect modular division** | Using `/` operator expecting integer division | `a / b` on felt252 produces modular inverse, not truncation |

### Medium — Conditional Impact

| Vulnerability | Description | Detection Signal |
|---------------|-------------|-----------------|
| **Unbounded storage growth** | Maps or arrays without size limits | `Map<K, V>` without pruning mechanism |
| **Missing events** | State changes without event emission | `write` to storage without `emit` |
| **Library dispatch trust** | Using `library_call_syscall` with unchecked class hash | External class hash in library call |
| **Paymaster manipulation** | Transaction fee payment logic exploitable | Custom `__validate__` with fee token handling |
| **Felt-to-u256 conversion errors** | Incorrect type casting between felt and uint types | `felt252.into()` or `TryInto::<u256>` without bounds |

## Cairo-Specific Pitfalls

### Felt Arithmetic Is Modular

```cairo
// DANGEROUS: Felt subtraction wraps around P
let balance: felt252 = 100;
let amount: felt252 = 200;
let result = balance - amount;
// result is NOT -100, it is P - 100 (a very large number)
// Any comparison result > 0 will be TRUE

// SAFE: Use u256 for amounts
let balance: u256 = 100;
let amount: u256 = 200;
assert(balance >= amount, 'Insufficient balance'); // Correctly reverts
```

### Division Is Not Integer Division

```cairo
// UNEXPECTED: Felt division is modular inverse
let a: felt252 = 7;
let b: felt252 = 2;
let result = a / b;
// result is NOT 3 (integer truncation)
// result is the felt252 x such that x * 2 ≡ 7 (mod P)
// This is (P + 7) / 2 = a very large number

// SAFE: Use u256 for integer division
let a: u256 = 7;
let b: u256 = 2;
let result = a / b; // result is 3 (integer truncation, as expected)
```

## Resources

| Resource | Description |
|----------|-------------|
| [Cairo Patterns](resources/cairo-patterns.md) | Vulnerability patterns specific to Cairo language and Starknet |
| [Starknet Security](resources/starknet-security.md) | Starknet architecture security: sequencer, proofs, upgrades |
| [Messaging Security](resources/messaging-security.md) | L1-L2 messaging: message replay, nonce handling, proof finalization |

## Workflows

| Workflow | Description |
|----------|-------------|
| [Cairo Audit](workflows/cairo-audit.md) | Step-by-step audit workflow for Cairo contracts on Starknet |

## Notable Starknet Security Incidents

| Incident | Root Cause | Impact |
|----------|-----------|--------|
| Various DeFi exploits on Starknet testnet | Felt overflow in token balances | Fund inflation |
| L1→L2 message replay in early bridges | Missing consumed message tracking | Double-spending |
| Account contract vulnerabilities | Insufficient `__validate__` logic | Transaction forging |

## Integration with Other Skills

| Skill | Connection |
|-------|-----------|
| `starknet-scanner/` | Shares Cairo language patterns; this skill focuses on language, starknet-scanner focuses on chain |
| `chain-guides/starknet.md` | Chain-level context for Starknet architecture |
| `patterns/` | Cross-reference with general vulnerability categories (reentrancy, access control) |
| `exploit-forensics/` | Limited Starknet exploits but growing as ecosystem matures |

## Error Code Reference

Common Cairo/Starknet errors encountered during audits. Cairo errors manifest as felt252 values in transaction reverts.

### Cairo Language Errors

| Error Pattern | Error Source | Meaning |
|--------------|-------------|----------|
| `felt252 overflow` | Arithmetic operation | Result exceeds field prime P (≈ 2^251 + 17·2^192 + 1) — wraps silently |
| `index out of bounds` | Array access | Array index exceeds length — causes execution failure |
| `Option::unwrap on None` | Option handling | Attempted to unwrap an empty Option — missing existence check |
| `assertion failed` | `assert()` macro | Contract invariant violation — check assert conditions |
| `'Entry not found'` | StorageMap access | Key does not exist in LegacyMap/Map — missing default handling |
| `u256_sub Overflow` | Subtraction underflow | Unsigned subtraction result would be negative |
| `u256_add Overflow` | Addition overflow | Addition exceeds u256 max value |
| `Division by zero` | Division operation | Denominator is zero — missing zero-check |

### Starknet Contract Errors

| Error Pattern | Error Source | Meaning |
|--------------|-------------|----------|
| `'Caller is not the owner'` | OZ Ownable | Missing ownership — check access control |
| `'Caller is the zero address'` | OZ Ownable | Zero address caller — validate caller identity |
| `'ERC20: insufficient balance'` | OZ ERC20 | Token balance too low |
| `'ERC20: insufficient allowance'` | OZ ERC20 | Approval not set or insufficient |
| `'ERC20: approve to zero address'` | OZ ERC20 | Invalid spender address |
| `'ERC721: invalid token ID'` | OZ ERC721 | Token does not exist |
| `'Contract already initialized'` | Initializable pattern | Re-initialization attempt — check initializer guard |
| `'ENTRYPOINT_NOT_FOUND'` | Starknet OS | Called selector doesn't exist on contract |
| `'UNINITIALIZED_CONTRACT'` | Starknet OS | Class not declared or deployed |
| `'TRANSACTION_FAILED'` | Starknet sequencer | Generic failure — check inner error for details |

### Felt Arithmetic Audit Concerns

| Issue | Risk | Detection |
|-------|------|----------|
| Felt overflow wrapping | Arithmetic wraps mod P instead of reverting | Flag all felt252 math ops — prefer u256/u128 for financial math |
| Felt comparison edge cases | `<` and `>` comparisons are mod P, not natural ordering | Check comparisons on felt252 values — may produce unexpected results |
| Integer to felt truncation | Converting large u256 to felt252 silently truncates | Flag all `into()` / `try_into()` conversions between types |
| Storage key collision | LegacyMap keys hash via Pedersen — potential collision with crafted inputs | Verify map key uniqueness assumptions |

## Troubleshooting

| Issue | Likely Cause | Solution |
|-------|-------------|----------|
| Scanner misses felt overflow issues | Analyzing code as if integers revert on overflow | Cairo felt252 wraps mod P — flag all felt arithmetic in financial logic |
| False positives on storage access | Scanner flags all LegacyMap reads as risky | Verify if default value (0) is safe for the use case |
| Account abstraction patterns not detected | Scanner uses EVM mental model | Load `starknet-scanner/` for account abstraction-specific checks |
| Component architecture flaws missed | Scanner doesn't understand Cairo components | Manually review component trait implementations and storage conflicts |
| Missed reentrancy via L1 handler | Scanner only checks external functions | Include `#[l1_handler]` functions in reentrancy analysis |
| Cairo version mismatch warnings | Pattern written for Cairo 1.x, contract uses 2.x | Verify syntax patterns match target Cairo version; update detection rules |

Attribution

0x-Shashi0x-Shashi
View sourceMore from 0x-Shashi →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Springboot Security

Java Spring Boot 服务中关于身份验证/授权、验证、CSRF、密钥、标头、速率限制和依赖安全的 Spring Security 最佳实践。

2456590 votes

Security Review

Use this skill when adding authentication, handling user input, working with secrets, creating API endpoints, or implementing payment/sensitive features. Provides comprehensive security checklist and patterns.

2456590 votes

Summarize Status

Write a short, colloquial summary for a Paperclip summary slot: open with the 1–3 specific, concrete actions the reader needs to take right now to unblock the work, then a brief plain-language status, streaming progress as it works.

798220 votes

Paperclip Task Bridge

Create, comment on, update, and list Paperclip tasks from Hermes using scoped Paperclip API credentials.

798220 votes

V3 Security Overhaul

Complete security architecture overhaul for claude-flow v3. Addresses critical CVEs (CVE-1, CVE-2, CVE-3) and implements secure-by-default patterns. Use for security-first v3 implementation.

701370 votes
View all in security →