An alternative implementation of the OP Stack's Cannon, a MIPS emulator for the EVM.

Overview

Cannon

An alternative implementation of the OP Stack's Cannon in Rust.

Ci License OP Stack

What's a Cannon?OverviewCreditsBenchmarksContributingDocumentationDocker

What's a Cannon?

Cannon is an emulator designed to simulate a single MIPS thread context on the EVM. Its primary use is to execute the op-program (also known as the fault-proof program) for the OP Stack's interactive dispute protocol. The op-program consists of a stripped down version of op-geth's state transition code in addition to the derivation pipeline, and produces deterministic results. Subsequently, it is compiled to MIPS to be ran on top of Cannon on-chain to prove fault in claims about the state of L2 on L1. Cannon also has a native implementation of the MIPS thread context that mirrors the on-chain version, which enables the op-challenger to generate state commitments for an op-program execution trace and participate in dispute games.

TL;DR:

Overview

  • cannon-mipsevm - Contains the native implementation of the MIPS thread context emulator.
  • preimage-oracle - Rust bindings for interacting as client or sever over the Pre-image Oracle ABI.
  • cannon-contracts - [in OP monorepo] Contains the Solidity implementation of the MIPS thread context and the Preimage Oracle.

Credits

This repository is heavily inspired by the original Cannon, built by George Hotz and members of the OP Labs team. The original implementation is written in Go, and can be found in the Optimism monorepo. All credits for the original idea and reference implementation of this concept go to these folks.

Benchmarks

cannon-mipsevm benchmarks

The below benchmark was ran on a 2021 Macbook Pro with an M1 Max and 32 GB of unified memory on commit 71b68d5.

Benchmark Name cannon mean (Reference) cannon-rs mean
Memory Merkle Root (25MB) 736.94 ms 29.58 µs (-99%)
Memory Merkle Root (50MB) 1.54s 7.25 ms (-99%)
Memory Merkle Root (100MB) 3.34s 273.76 ms (-91.8%)
Memory Merkle Root (200MB) 6.30s 1.65s (-73.81%)

todo - execution benchmarks

Contributing

To get started, a few dependencies are required:

Testing

# With `cargo-nextest`
cargo nextest run --all --all-features
# Without `cargo-nextest`
cargo t --all --all-features

Linting and Formatting

cargo +nightly fmt --all -- && cargo +nightly clippy --all --all-features -- -D warnings

Running Benchmarks

cargo bench --all --all-features

Documentation

Rustdocs are available by running cargo doc --open after cloning the repo.

Specification

The specification for both Cannon and the preimage oracle can be found in the Optimism monorepo.

Docker

The docker image for cannon-rs is located in the docker directory, and can be built using the script provided.

Comments
  • POC: Parallelize merkleization

    POC: Parallelize merkleization

    Overview

    Bad idea, just a loose test. There could be something to making the merkle root hashing asynchronous (i.e. lazy calculation, not parallelizing sub-trees like here), but the overhead in this method is definitely not it.

    do-not-merge 
    opened by clabby 0
  • feat: ELF Tests

    feat: ELF Tests

    Overview

    The ELF file patcher was added today, we're now unblocked on porting over the ELF tests. These tests run the binaries in the example directory through the emulator and assert correctness.

    opened by clabby 0
  • ✨ EVM Diff tests

    ✨ EVM Diff tests

    Overview

    Adds the first round of differential tests for the Rust implementation of the MIPS VM and the Solidity implementation and cleans up the test utilities project structure.

    TODO

    • [x] Non-oracle tests
    • [x] Oracle tests
    opened by clabby 0
  • feat: Docker image

    feat: Docker image

    Overview

    Create a workflow that builds cannon-rs as a distributable docker image from this GitHub repository, or allows people to easily build the image themselves locally.

    enhancement 
    opened by clabby 0
  • perf: `Page` bitmap

    perf: `Page` bitmap

    Overview

    At the moment, mipsevm's Page data structure uses a bitmap of 128 bits for the invalid address tracking. While this is efficient, it is somewhat restrictive because the page size can no longer be increased without breaking the datastructure. It would be nice to have an alternative solution that is quick to read/write to, does not require much memory, and supports adjustable page sizes.

    enhancement 
    opened by clabby 0
  • feat: `cannon-rs` binary

    feat: `cannon-rs` binary

    Overview

    Implement a binary for the cannon-rs library that is equivalent in interaction with upstream cannon's binary. The idea here is that cannon-rs should be able to drop-in replace cannon in existing setups, such as the op-challenger, while still retaining the ability to be invoked programmatically in software that is more sane and doesn't invoke it as an executable binary.

    binary 
    opened by clabby 0
  • feat: `preimage-oracle` crate

    feat: `preimage-oracle` crate

    Overview

    In order for cannon-rs to run the op-program and other MIPS programs that reach out to the Preimage Oracle through the ABI, we'll need to define Rust bindings for the preimage service. This will effectively be a re-write of op-preimage

    preimage-oracle 
    opened by clabby 0
  • feat: EVM Tests

    feat: EVM Tests

    Overview

    As the native implementation of the Cannon emulator must be equivalent to the on-chain version, we'll need to add EVM tests. This will involve porting Cannon's evm_test.go and fuzz_evm_test.go tests into the cannon-mipsevm crate.

    Advice

    • Use revm and turn USE_GAS off for faster execution. We only need to assert correctness, so gas accounting will just slow these tests down.
    mipsevm 
    opened by clabby 0
  • feat: Binary Serialization

    feat: Binary Serialization

    Overview

    https://github.com/ethereum-optimism/optimism/pull/7559 defines a new binary serialization format for the State and Memory structs, specifically for the snapshots. This should alleviate some of the pain in the Go <> Rust JSON interoperability (context: https://github.com/golang/go/issues/37711 - tl;dr golang does not marshal nil slices as [] in JSON by default.)

    Move the serialization of State and Memory over to this format once (or if) this PR is merged.

    mipsevm binary 
    opened by clabby 0
  • spike: Memory invalidation inefficiencies

    spike: Memory invalidation inefficiencies

    Overview

    Memory in Cannon contains a cache for recently accessed pages, and within those pages a cache for intermediate nodes to reduce the merkleization time. When the page data is invalidated (i.e. it's been changed), the root will need to be recalculated on the next pass.

    The program is pretty performant, but merkleization is expensive and takes the most time during each step (w/ proof generation turned on), so it would be great to look into how we can further optimize this codepath to decrease cache misses and redundant recomputation of merkle roots.

    Refs:

    flamegraph

    help wanted mipsevm perf 
    opened by clabby 0
  • feat: Benchmarks

    feat: Benchmarks

    Overview

    Once the full implementation is complete and is able to run the op-program, it will be great to start benchmarking it. Micro-benchmarks on core data structures, such as cannon-mipsevm's Memory and Page are great, and we'll also want some more end-to-end benchmarks such as executing a full op-program trace as would be done for an on-chain dispute.

    enhancement preimage-oracle mipsevm 
    opened by clabby 0
Owner
Anton Systems
Anton Systems
Pure Go implementation of jq

gojq Pure Go implementation of jq This is an implementation of jq command written in Go language. You can also embed gojq as a library to your Go prod

itchyny 2.4k Jan 8, 2023
An implementation of the JSONPath A spec in Rust, with several extensions added on

Rust JSONPath Plus An implementation of the JSONPath A spec in Rust, with several extensions added on. This library also supports retrieving AST analy

Rune Tynan 4 Jul 13, 2022
Easy c̵̰͠r̵̛̠ö̴̪s̶̩̒s̵̭̀-t̶̲͝h̶̯̚r̵̺͐e̷̖̽ḁ̴̍d̶̖̔ ȓ̵͙ė̶͎ḟ̴͙e̸̖͛r̶̖͗ë̶̱́ṉ̵̒ĉ̷̥e̷͚̍ s̷̹͌h̷̲̉a̵̭͋r̷̫̊ḭ̵̊n̷̬͂g̵̦̃ f̶̻̊ơ̵̜ṟ̸̈́ R̵̞̋ù̵̺s̷̖̅ţ̸͗!̸̼͋

Rust S̵̓i̸̓n̵̉ I̴n̴f̶e̸r̵n̷a̴l mutability! Howdy, friendly Rust developer! Ever had a value get m̵̯̅ð̶͊v̴̮̾ê̴̼͘d away right under your nose just when

null 294 Dec 23, 2022
The Stacks 2.0 blockchain implementation

Stacks 2.0 Reference implementation of the Stacks blockchain in Rust. Stacks 2.0 is a layer-1 blockchain that connects to Bitcoin for security and ena

Stacks 2.7k Dec 31, 2022
MIPS assembler written in Rust

frasm MIPS assembler written in Rust About frasm is an assembler written in Rust speicifally for the MIPs architecture. This is my first time writing

Jacob Mealey 3 Oct 23, 2022
Rust development environment for MIPS on NT4

Summary This is a project which allows us to run Rust "shellcode" in a MIPS environment on NT 4.0. TL;DR Setup NT Install NT 4.0 MIPS in QEMU using th

null 19 Dec 18, 2022
Rust SDK for writing contracts for Stellar Jump Cannon

rs-stellar-contract-sdk Rust SDK for writing contracts for Stellar Jump Cannon. This repository contains code that is in early development, incomplete

Stellar 44 Dec 28, 2022
Rust environment for Stellar Jump Cannon.

rs-stellar-contract-env Rust contract-environment interface and (optional) host implementation for Stellar Jump Cannon. This crate contains elements o

Stellar 24 Dec 15, 2022
Rust Cannon Template 🦀 💣 💥

A build system and a minimal Rust program for building MIPS binaries that are executable in the context of [Optimism Cannon]

Willem Olding 19 Jan 25, 2023
A command-line tool which can move CloudFormation resources between stacks

cfn-teleport A command-line tool which can move CloudFormation resources between stacks. Installation On a Mac you can install via Homebrew: brew inst

Daniel Schroeder 19 Apr 2, 2023
An efficient, robust, and generalized batch submission service for rollup stacks written in pure rust.

archon is an efficient, robust, and generalized batch submission service for rollup stacks written in pure rust. Note Archon is primarily tested again

refcell.eth 75 Apr 2, 2023
Ideas => Creations, a multi-language CMS(Content Management System) based on Rust Web stacks, with long-term upgrade and maintenance.

Ideas => Creations 中文 RustHub: Rust ideas yesterday, shining creations today! This repository holds source code used to run https://rusthub.org, it's

rusthub.org 4 May 9, 2023
runs init, preview and apply on pulumi stacks right in your Github Actions. Inspired from Atalantis for Terraform

pulumi-actions runs init, preview and apply on pulumi stacks right in your Github-Actions. Inspired from Atlantis for Terraform PREVIEW Release Curren

Meet Vasani 6 Aug 7, 2023
Nes-emulator - A NES emulator made to learn the Rust programming language

nes-emulator Building $ rustc --version rustc 1.32.0 (9fda7c223 2019-01-16) $ cargo --version cargo 1.32.0 (8610973aa 2019-01-02) $ cargo build --rel

Michael Burge 225 Dec 23, 2022
Simple EVM implementation from scratch using Rust.

smol-evm-rs • smol-evm-rs is a Rust port of the smol-evm project, originally implemented in Python by karmacoma. This project aims to implement the Et

Pranesh A S 29 Dec 27, 2023
EVM contract for Aurora.

Aurora Engine Prerequisites Rust nightly (2021-01-30) with the WebAssembly toolchain GNU Make (3.81+) rustup install nightly-2021-01-30 rustup target

Project Aurora 258 Dec 30, 2022
EVM compatible chain with NPoS/PoC consensus

Reef Chain Reef chain is written in Rust. A basic familiarity with Rust tooling is required. To learn more about Reef chain, please refer to Documenta

Reef Finance 148 Dec 31, 2022
A temporary repo for ETH connector to be used by EVM

ETH connector for Rainbow bridge Definitions bridgedETH - NEP-141 fungible-token representation of ETH inside Near. nETH - native ETH inside Near EVM.

Project Aurora 36 Jul 26, 2022
a frontier based evm compatible chain template

Substrate Frontier Node Template A FRAME-based Substrate node with the Ethereum RPC support, ready for hacking ?? Generation & Upstream This template

zero network 2 Oct 6, 2021
Emerald, the EVM compatible paratime

The Emerald ParaTime This is the Emerald ParaTime, an official EVM-compatible Oasis Protocol Foundation's ParaTime for the Oasis Network built using t

Oasis Protocol Foundation 5 Mar 31, 2022