Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/kkrt-labs/cairo-vm-ts

A typescript implementation of the Cairo VM
https://github.com/kkrt-labs/cairo-vm-ts

Last synced: about 2 months ago
JSON representation

A typescript implementation of the Cairo VM

Lists

README

        

# TypeScript Cairo VM


TypeScript Cairo VM

An implementation of the Cairo VM in TypeScript, focusing on
education

[Github](https://github.com/kkrt-labs/cairo-vm-ts)

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.

## What is Cairo

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](#resources) for more information.

## Why this

### Implementation Diversity

There are currently seven other Cairo VM implementations:

- Reference (original)
[implementation in Python](https://github.com/starkware-libs/cairo-lang) by
Starkware (prod)
- New [implementation in Rust](https://github.com/lambdaclass/cairo-vm) by
Lambda Class (prod)
- A [Go implementation](https://github.com/lambdaclass/cairo-vm_in_go), by
Lambda Class (dev)
- Another [Go implementation](https://github.com/NethermindEth/cairo-vm-go) by
Nethermind (dev)
- A
[Zig implementation](https://github.com/keep-starknet-strange/ziggy-starkdust),
by Community (dev)
- A [C++ implementation](https://github.com/lambdaclass/cairo-vm.c) by Lambda
Class (dev)
- A
[GoogleSheets (gs AppScript) implementation](https://github.com/ClementWalter/cairo-vm-gs)
by ClΓ©ment Walter (dev)

The Lambda Class alt-implementations comes with a detailed guide
([Go](https://github.com/lambdaclass/cairo-vm_in_go/blob/main/README.md#documentation),
[C++](https://github.com/lambdaclass/cairo-vm.c?tab=readme-ov-file#documentation))
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](https://geth.ethereum.org/) and
[reth](https://github.com/paradigmxyz/reth) written in Go and Rust), whose
primary goals are **performance** and **safety**, and the
[reference EVM implementation](https://github.com/ethereum/execution-specs/?tab=readme-ov-file#execution-specification-work-in-progress)
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**.

### Demistifying the Cairo VM

- 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.

## State of the VM

| Goals | Done? |
| ---------------------------- | ------- |
| Run basic Cairo Zero program | β˜‘ |
| Run basic Cairo program | ☐ |
| Add [builtins](#builtins) | ☐ |
| Add [hints](#hints) | ☐ |
| Run StarkNet contracts | ☐ |
| Benchmark against other VMs | ☐ |

### Builtins

### Hints

## Resources

- [Cairo whitepaper](https://eprint.iacr.org/2021/1063)
- [Cairo Book](https://book.cairo-lang.org/)
- [Cairo website](https://www.cairo-lang.org/)

## Local Development

### Requirements

- Install [bun](https://bun.sh/)
- Run `bun install` to install all dependencies
- Run `bun test` to run all tests