Cairo VM
Cairo-vm ⚡ is a faster and safer implementation of the Cairo VM, written in 🦀 Rust 🦀. This project offers a robust environment for compiling and running Cairo programs, optimized for performance and security.
Cairo VM is the virtual machine for the Cairo language. Previously, Cairo VM was written in Python, but this newer version in Rust offers improved speed, safety, and expressive typing. It has replaced the older Python version to become the primary Cairo VM.
Cairo is the first production-grade platform for generating STARK proofs for general computation. It is Turing-complete and was created by Starkware as part of the Starknet ecosystem.
These dependencies are needed to compile and use the project:
These dependencies are only necessary to run the original VM, compile Cairo programs, and run tests:
You can install all required and optional dependencies by running the install.sh
script from the repository root.
To compile programs, install the cairo-lang
package. Use the following command to create a virtual environment with all the required dependencies:
For macOS users, use:
Activate the environment by running:
To add Cairo-vm to your Rust project, include the following in your Cargo.toml
file:
Compile the repository from the cairo-vm-cli
folder:
The binary will be located in target/release/
under the name cairo-vm-cli
.
Activate the environment created during installation:
To compile a program, use:
For example:
To run a compiled .json
program through the VM:
The --layout
flag determines which builtins can be used. More information about layouts can be found in the documentation.
Cairo-vm-cli supports several optional arguments, including:
--trace_file <TRACE_FILE>
--memory_file <MEMORY_FILE>
--print_output
--proof_mode
--secure_run
--air_public_input <AIR_PUBLIC_INPUT>
--air_private_input <AIR_PRIVATE_INPUT>
--cairo_pie_output <CAIRO_PIE_OUTPUT>
--allow_missing_builtins
run_from_cairo_pie
For example, to obtain the air public inputs from a Fibonacci program run:
This VM is under construction and currently supports a limited number of Python hints. Non-standard hints can be used by:
To run a Cairo program directly, specify the program and prepare the VM, cairo_runner, hint processor, and entrypoint:
For Starknet devnet, additional parameters are required for the run_from_entrypoint
method.
Navigate to the folder cd cairo1-run
and follow the cairo1-run documentation.
A demo on using cairo-vm with WebAssembly is available in examples/wasm-demo
.
To run the test suite, install cargo-llvm-cov
dependency:
Run the test suite with:
Cairo-vm includes a tracer for visualizing memory and register changes during execution. More information can be found here.
Running a Cairo program to get the 1.5 millionth Fibonacci number provides benchmarks, including execution time with Criterion and flamegraph results. Ensure Valgrind is installed for the iai_benchmark
.
Run the complete benchmark suite with:
Run only the criterion_benchmark
suite with:
Run only the iai_benchmark
suite with:
Benchmark the cairo-vm in a hyper-threaded environment with: