An implementation of the Cairo VM in TypeScript, focusing on education
Built with 🥕 by KKRT Labs
⚠️ This project is in its genesis, undergoing fast-paced development. It is not suitable for production yet. Expect frequent breaking changes.
Cairo stands for CPU AIR "o" (like insp"o", conv"o", 🤔).
It is a framework (a machine, an assembly and a language) which allows writing provable programs without having to understand the underneath ZK-technology.
A program written in Cairo (or Cairo Zero) is compiled to Cairo Assembly (CASM) and then executed on a Cairo VM which produces traces to be used for the STARK proof generation.
See resources for more information.
There are currently seven other Cairo VM implementations:
- Reference (original) implementation in Python by Starkware (prod)
- New implementation in Rust by Lambda Class (prod)
- A Go implementation, by Lambda Class (dev)
- Another Go implementation by Nethermind (dev)
- A Zig implementation, by Community (dev)
- A C++ implementation by Lambda Class (dev)
- A GoogleSheets (gs AppScript) implementation by Clément Walter (dev)
The Lambda Class alt-implementations comes with a detailed guide (Go, C++) on how they built their Cairo VM. It gives insights into the overall Cairo VM but is incomplete and rather specific to language details.
Why would you have different implementations of the same program in multiple languages? For implementation diversity.
More implementations provide more:
- Resilience. It helps in finding bugs in the existing implementations.
- Documentation. The documentation over the Cairo VM is still scarce, and the latest version in prod (Rust) is not easy to read for the average dev.
- Architecture diversity. Different architectures can be implemented to achieve the same goal (e.g. memory model). However, most of the current implementations essentially are a rewrite of the Rust implementation, which is an (enhanced) rewrite of the Python implementation itself.
Implementation diversity also implies usage diversity. The primary goals of each implementation can differ.
For example, the EVM implementation in clients (e.g. geth and reth written in Go and Rust), whose primary goals are performance and safety, and the reference EVM implementation in Python, prioritizing readability and simplicity.
Analogous to the EVM implementations, the primary goals of the Rust Cairo VM are performance and safety. While the ones of our TypeScript implementation is education through readability and simplicity.
- TypeScript is easily readable and known by most devs if not all
- Deliberate design choices to further improve readability and simplicity
- Extensive documentation: JSDoc, diagrams, explainers, etc.
Goals | Done? |
---|---|
Run basic Cairo Zero program | ☑ |
Run basic Cairo program | ☐ |
Add builtins | ☐ |
Add hints | ☐ |
Run StarkNet contracts | ☐ |
Benchmark against other VMs | ☐ |
- Install bun
- Run
bun install
to install all dependencies - Run
bun test
to run all tests