A comprehensive collection of crates and tools to support development of Cannon programs in Rust
Thinking about contributing? There are bounties available for meaningful contributions via our OnlyDust page!
Cannon-rs aims to support the emerging number of projects using Rust to develop provable programs for Optimism Cannon. This is the evolution of the rust-cannon-template supported by the Optimism RetroPGF round 2.
Advantages of using Rust are:
- Code Reuse - Take advantage of existing, trusted crates in the crypto ecosystem
- Compact Binaries - Cannon programs built using Rust are much smaller than their Golang equivalents
- Proving Speed - Generating proofs through emulation for large programs can be slow. Effective use of Rust can reduce the length of the program trace required speeding up the proving process
The project itself provides a number of tools to enable this:
Although MIPS is a standard Rust target the specific configuration needed to support the Cannon ISA is quite different. Cannon-rs provides a custom Rust target and a Docker image configured to build elf files which can be patched to run within Cannon.
Cannon uses syscalls for communication between the guest program and the host. The cannon-io crate exposes a simple and safe wrapper around the low level syscalls to allow printing to stdout, retrieving data via the pre-image oracle and safely terminating a program with an exit code.
The Optimism Cannon emulator uses custom IO streams to communicate with a child process responsible for retrieving preimage data given its key. The Cannon preimage server implementation is geared toward providing access to the Ethereum data required for rollup execution.
Cannon-rs provides a simple CLI tool for serving preimages stored in a JSON file. This can be extended with new implementations of the PreimageProvider
trait in order to provide a tool suited to your application.
Makes generating and building new Cannon projects as easy as:
cargo cannon new
cargo cannon build
Cross compiling for Cannon requires:
- Docker
- Just (
cargo install just
)
- Copy the
project-template
from this repo to get started - Build something awesome in Rust π¦
- Build for Cannon using
just build
- Rust build system for Cannon MIPS target (no_std)
- Heap implementation
- Guest<->Host Communication
- stdout
- Request data via Preimage Oracle
- Hints
- Template for bootstrapping own projects
- Preimage Server
- Server compatible with Optimism Cannon emulator
- Serve preimages from JSON file
- cargo cannon tooling
-
cargo cannon build
to wrap docker cross-compilation -
cargo cannon new
to create new Cannon projects
-
See the open issues for a full list of proposed features (and known issues).
Contributions are very welcome! To contribute please
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
A huge thanks to all existing contributors from the community!!
Distributed under the LGPL-3 License. See LICENSE for more information.
Willem Olding - @willemolding1 - willemolding@gmail.com
Project Link: https://github.com/BadBoiLabs/Cannon-rs