keep-starknet-strange / snos

Rust Library for running the Starknet OS via the Cairo VM
MIT License
59 stars 28 forks source link
### ✨ SNOS ✨ A Rust Library for running the [Starknet OS](https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/core/os/os.cairo). [Report Bug](https://github.com/keep-starknet-strange/snos/issues/new?assignees=&labels=bug&projects=&template=bug_report.md&title=bug%3A+) · [Request Feature](https://github.com/keep-starknet-strange/snos/issues/new?labels=enhancement&title=feat%3A+) [![Check Workflow Status](https://github.com/keep-starknet-strange/snos/actions/workflows/check.yml/badge.svg)](https://github.com/keep-starknet-strange/snos/actions/workflows/check.yml) [![license](https://img.shields.io/github/license/keep-starknet-strange/snos)](/LICENSE) [![pr-welcome]](#-contributing) [pr-welcome]: https://img.shields.io/static/v1?color=blue&label=PRs&style=flat&message=welcome

Table of Contents

πŸ“– About

Starknet OS is a Cairo program designed to prove the integrity of state transitions between blocks on Starknet.

By re-executing transactions from a block and verifying consistency, it produces a PIE (Program Independent Execution) result. This PIE can be used to generate a STARK proof of integrity, which, if accepted by Starknet L1 verifiers, confirms block validity and updates the Starknet state root in the StarknetCore contract.

πŸ› οΈ Getting Started

Prerequisites

Ensure you have the following dependencies installed:

Optional

Installation

  1. Clone the Repository

Clone this repository and its submodules:

   git clone https://github.com/keep-starknet-strange/snos.git --recursive

Install project dependencies

In order to compile the Starknet OS Cairo program, you’ll need the Cairo compiler:

This will create a virtual environment and download needed dependencies to compile cairo programs. You will need to activate it to compile Cairo programs.

πŸ§ͺ Running Tests

To verify your setup, follow these steps:

Activate snos-env:

 source ./snos-env/bin/activate

Run Tests

./scripts/setup-tests.sh

cargo test

Reset Tests

If you need to reset the test environment:

./scripts/reset-tests.sh

πŸš€ Usage

Adding SNOS as a dependency

You can add the following to your rust project's Cargo.toml:

starknet-os = { git = "https://github.com/keep-starknet-strange/snos", rev = "662d1706f5855044e52ebf688a18dd80016c8700" }

Using the prove_block Binary

To execute correctly, SNOS requires detailed block information, including:

The prove_block binary handles this entire process by collecting, formatting, and feeding the necessary data into the OS, ensuring the correct OSInput is passed for execution.

To accomplish this, it queries the required information from a full node. Currently, Pathfinder is the only full node implementing all the necessary RPC methods, so a synced Pathfinder instance running as an archive node (to provide access to storage proofs) is required to execute this binary successfully.

For example, you can run Pathfinder executing:

PATHFINDER_ETHEREUM_API_URL="YOUR_KEY" ./target/release/pathfinder --data-directory /home/herman/pathfinder-data --http-rpc 0.0.0.0:9545 --storage.state-tries archive

Once you have a synced full node, you can start generating PIEs of a given block by running:

cargo run --release -p prove_block -- --block-number 200000 --rpc-provider http://0.0.0.0:9545

🀝 Related Projects

πŸ“š Documentation

Cairo:

Starknet

StarknetOS

πŸ“œ License

This project is licensed under the MIT License. See the LICENSE file for details.