60 releases (26 stable)

2.6.3 Mar 12, 2024
2.6.0-rc.1 Feb 14, 2024
2.5.0-dev.0 Dec 26, 2023
2.4.0-rc6 Nov 26, 2023
0.1.0 Jan 3, 2023

#1351 in Magic Beans

Download history 4962/week @ 2023-12-22 5075/week @ 2023-12-29 6349/week @ 2024-01-05 6873/week @ 2024-01-12 6884/week @ 2024-01-19 6414/week @ 2024-01-26 8319/week @ 2024-02-02 8192/week @ 2024-02-09 6805/week @ 2024-02-16 5750/week @ 2024-02-23 6614/week @ 2024-03-01 7303/week @ 2024-03-08 7305/week @ 2024-03-15 7004/week @ 2024-03-22 5849/week @ 2024-03-29 6374/week @ 2024-04-05

27,982 downloads per month
Used in 40 crates (18 directly)

Custom license

555KB
12K SLoC

Cairo 🐺

⚡ Blazing ⚡ fast ⚡ compiler for Cairo, written in 🦀 Rust 🦀


Report a Bug - Request a Feature - Ask a Question

GitHub Workflow Status Project license Pull Requests welcome

Table of Contents

About

Cairo is the first Turing-complete language for creating provable programs for general computation.

Getting Started

Prerequisites

  • Install Rust
  • Setup Rust:
rustup override set stable && rustup update

Ensure rust was installed correctly by running the following from the root project directory:

cargo test

Compiling and running Cairo files

Compile Cairo to Sierra:

cargo run --bin cairo-compile -- --single-file /path/to/input.cairo /path/to/output.sierra --replace-ids

Compile Sierra to casm (Cairo assembly):

cargo run --bin sierra-compile -- /path/to/input.sierra /path/to/output.casm

Run Cairo code directly:

cargo run --bin cairo-run -- --single-file /path/to/file.cairo

See more information here. You can also find Cairo examples in the examples directory.

For running tests specifically, see here: cairo-test

Compiling Starknet Contracts

Compile a Starknet Contract to a Sierra ContractClass:

cargo run --bin starknet-compile -- --single-file /path/to/input.cairo /path/to/output.json

Or specify the contract path if multiple contracts are defined in the same project:

cargo run --bin starknet-compile -- /path/to/input/crate /path/to/output.json --contract-path path::to::contract

Compile the ContractClass of a CompiledClass:

cargo run --bin starknet-sierra-compile -- /path/to/input.json /path/to/output.casm

Development

Install the language server

Follow the instructions in vscode-cairo.

Roadmap

The next milestone is to reach feature parity with the old Cairo version. You can track the exact progress here.

Support

Project assistance

If you want to say thank you or/and support active development of Cairo:

  • Add a GitHub Star to the project.
  • Tweet about your Cairo work.
  • Write interesting articles about the project on Dev.to, Medium or your personal blog.

Together, we can make Cairo better!

Contributing

First off, thanks for taking the time to contribute! Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make will benefit everybody else and are greatly appreciated.

Please read our contribution guidelines, and thank you for being involved!

Authors & contributors

For a full list of all authors and contributors, see the contributors page.

Security

Cairo follows good practices of security, but 100% security cannot be assured. Cairo is provided "as is" without any warranty. Use at your own risk.

For more information and to report security issues, please refer to our security documentation.

License

This project is licensed under the Apache 2.0.

See LICENSE for more information.


lib.rs:

Sierra is an intermediate representation between high level Cairo and compilation targets, such as CASM. Sierra code is guaranteed to be "safe"* by construction. Sierra has a primitive, yet rich typing system to express all high level code while guaranteeing safety and allowing for efficient compilation down to the target.

Safety - this means a few things:

  1. There are no "panics" / "runtime errors". Every function is guaranteed to return.
  2. There are no infinite loops. Moreover, every program "counts" its own steps, and returns when the limit is reached.
  3. Builtin library functions are always used correctly.

Dependencies

~10–14MB
~205K SLoC