The Cairo Book
Foreword
Introduction
The Cairo Programming Language
1.
Getting Started
❱
1.1.
Installation
1.2.
Hello, World!
2.
Common Programming Concepts
❱
2.1.
Variables and Mutability
2.2.
Data Types
2.3.
Functions
2.4.
Comments
2.5.
Control Flow
3.
Common Collections
❱
3.1.
Arrays
3.2.
Dictionaries
4.
Understanding Ownership
❱
4.1.
What is Ownership?
4.2.
References and Snapshots
5.
Using Structs to Structure Related Data
❱
5.1.
Defining and Instantiating Structs
5.2.
An Example Program Using Structs
5.3.
Method Syntax
6.
Enums and Pattern Matching
❱
6.1.
Enums
6.2.
The Match Control Flow Construct
6.3.
Concise Control Flow with if let and while let
7.
Managing Cairo Projects with Packages, Crates and Modules
❱
7.1.
Packages and Crates
7.2.
Defining Modules to Control Scope
7.3.
Paths for Referring to an Item in the Module Tree
7.4.
Bringing Paths into Scope with the use Keyword
7.5.
Separating Modules into Different Files
8.
Generic Types and Traits
❱
8.1.
Generic Data Types
8.2.
Traits in Cairo
9.
Error Handling
❱
9.1.
Unrecoverable Errors with panic
9.2.
Recoverable Errors with Result
10.
Testing Cairo Programs
❱
10.1.
How To Write Tests
10.2.
Test Organization
11.
Functional Language Features: Iterators and Closures
❱
11.1.
Closures: Anonymous Functions that Capture Their Environment
12.
Advanced Cairo Features
❱
12.1.
Custom Data Structures
12.2.
Smart Pointers
12.3.
Deref Coercion
12.4.
Associated Items
12.5.
Operator Overloading
12.6.
Working with Hashes
12.7.
Macros
12.8.
Procedural Macros
12.9.
Inlining in Cairo
12.10.
Printing
12.11.
Arithmetic Circuits
13.
Appendix (Cairo)
❱
13.1.
A - Keywords
13.2.
B - Operators and Symbols
13.3.
C - Derivable Traits
13.4.
D - The Cairo Prelude
13.5.
E - Common Error Messages
13.6.
F - Useful Development Tools
Smart Contracts in Cairo
14.
Introduction to Smart Contracts
15.
Building Starknet Smart Contracts
❱
15.1.
Contract Storage
❱
15.1.1.
Storage Mappings
15.1.2.
Storage Vecs
15.2.
Contract Functions
15.3.
Contract Events
16.
Starknet Contract Interactions
❱
16.1.
Contract Class ABI
16.2.
Interacting with Another Contract
16.3.
Executing Code from Another Class
17.
Building Advanced Starknet Smart Contracts
❱
17.1.
Optimizing Storage Costs
17.2.
Composability and Components
❱
17.2.1.
Under the Hood
17.2.2.
Component Dependencies
17.2.3.
Testing Components
17.3.
Upgradeability
17.4.
L1 <> L2 Messaging
17.5.
Oracle Interactions
❱
17.5.1.
Price Feeds
17.5.2.
Randomness
17.6.
Other Examples
❱
17.6.1.
Deploying and Interacting with a Voting Contract
18.
Starknet Smart Contracts Security
❱
18.1.
General Recommendations
18.2.
Testing Smart Contracts
18.3.
Static Analysis Tools
19.
Appendix (Starknet)
❱
19.1.
A - System Calls
Cairo VM
20.
Introduction
21.
Architecture
22.
Memory
❱
22.1.
Non-Deterministic Read-only Memory
22.2.
Segments
22.3.
Segment Value
22.4.
Relocation
22.5.
Layout
23.
Execution Model
❱
23.1.
Registers
23.2.
Instructions
23.3.
Cairo Assembly (CASM)
23.4.
State transition
24.
Builtins
❱
24.1.
How Builtins Work
24.2.
Builtins List
❱
24.2.1.
Output
24.2.2.
Pedersen
24.2.3.
Range Check
24.2.4.
ECDSA
24.2.5.
Bitwise
24.2.6.
EC OP
24.2.7.
Keccak
24.2.8.
Poseidon
24.2.9.
Range Check96
24.2.10.
AddMod
24.2.11.
MulMod
24.2.12.
Segment Arena
24.2.13.
Gas
24.2.14.
System
25.
Hints
❱
25.1.
Structure
25.2.
Hint runner
25.3.
List of hints
26.
Runner
❱
26.1.
Program
❱
26.1.1.
Program Artifacts
26.1.2.
Program Parsing
26.2.
Runner Mode
❱
26.2.1.
Execution Mode
26.2.2.
Proof Mode
26.3.
Output
❱
26.3.1.
Cairo PIE
26.3.2.
Memory File
26.3.3.
Trace file
26.3.4.
AIR public input
26.3.5.
AIR private input
27.
Tracer
28.
Implementations
29.
Resources
Light
Rust
Coal
Navy
Ayu
The Cairo Programming Language
Cairo Home
English
Español
Français
简体中文
Indonesian
Turkçe
Starknet Smart Contracts Security