Skip to content

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

License

Notifications You must be signed in to change notification settings

optimism-java/cannon-rs

 
 

Repository files navigation

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 +nightly nextest run --release --all --all-features
# Without `cargo-nextest`
cargo +nightly t --release --all --all-features

Linting and Formatting

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

Running Benchmarks

cargo +nightly 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.

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 66.9%
  • Assembly 31.0%
  • Shell 0.7%
  • Go 0.7%
  • Python 0.4%
  • Makefile 0.3%