Cairo is a general purpose language for writing zero-knowledge provable programs, without the need for a deep understanding of zero-knowledge concepts.
Elevate your Cairo skills through 91 curated exercises across 23 core concepts. Master problem-solving with a structured learning path designed for modern developers.
Cairo is a Rust-inspired language that aims to make it easy to compute trustworthy values on untrusted machines using validity proofs. It is a programming language designed for a virtual CPU of the same name, which is capable of efficiently proving the execution of any program running on it. This means that you can perform time consuming operations on a machine you don't trust, and check the result very quickly on a cheaper machine.
One major usecase of Cairo is writing smart contracts for Starknet, a Layer 2 built on top of Ethereum. Instead of having all the participants of the network verify all user interactions, only one node, called the prover, executes the programs and generates proofs that the computations were done correctly. These proofs are then verified by an Ethereum smart contract, requiring significantly less computational power, which increases throughput and reduces transaction costs while preserving Ethereum security.
Another notable use case of Cairo is in AI model training. Suppose you have a large dataset and wish to train an AI model on it but lack the necessary infrastructure. You can pay a major AI model provider to train the AI on your data and return the trained model. Since the provider used Cairo to write and train their AI model, they can produce a "proof" that you can use to verify that they did actually use the complete dataset you provided, ensuring the integrity of the training process and guaranteeing that no other data or partial data was used.
Cairo differs significantly from traditional programming languages, particularly in its execution and performance optimizations. Programs can be executed by a prover, similar to other languages, though with some performance overhead due to virtualization of the language. When proofs are verified, efficiency is crucial as verification may occur on small machines, and Cairo has various advantages to improve verification speed. A notable one is non-determinism, which is the idea that you can theoretically use a different algorithm for verifying than for computing. Take the example of sorting an array in Cairo - the prover has to sort the array, while the verifier only needs to check that the array is sorted, which is much cheaper. Additionally, Cairo's memory model is immutable, meaning values cannot be changed once written. Cairo provides abstractions that help developers work with these constraints, but it does not fully simulate mutability. This means that developers are required to be mindful of memory management and data structures to optimize performance.
The home page for Cairo is cairo-lang.org. List of Cairo resources at cairo-lang.org/documentation.html. Newcomers should start with "The Book" located at book.cairo-lang.org/.
Developer-friendly
Write Rust-like code and generate proofs for program execution - math isn't a barrier.
Provable
Produces provable programs, making it possible to compute trustworthy values on untrusted machines.
Efficient
Cairo compiles down to an ad-hoc assembly engineered specifically for efficient proof generation.
Immutable
Cairo uses the immutable memory model, improving data integrity and security.
General purpose
From blockchain gaming to provable ML, Cairo makes building trustless applications possible.
Innovative
Cairo is a fast-growing language that keeps delivering new and exciting features to its developers.
Developer-friendly
Write Rust-like code and generate proofs for program execution - math isn't a barrier.
Provable
Produces provable programs, making it possible to compute trustworthy values on untrusted machines.
Efficient
Cairo compiles down to an ad-hoc assembly engineered specifically for efficient proof generation.
Immutable
Cairo uses the immutable memory model, improving data integrity and security.
General purpose
From blockchain gaming to provable ML, Cairo makes building trustless applications possible.
Innovative
Cairo is a fast-growing language that keeps delivering new and exciting features to its developers.