Skip to content

Commit

Permalink
Merge pull request #2 from BadBoiLabs/willem/update-to-cannon-v2
Browse files Browse the repository at this point in the history
simplify for cannonv2
  • Loading branch information
willemolding authored Jul 23, 2023
2 parents 30c09e2 + 0969bb9 commit df49572
Show file tree
Hide file tree
Showing 19 changed files with 53 additions and 517 deletions.
17 changes: 14 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
target
build
venv
# Generated by Cargo
# will have compiled files and executables
debug/
target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
64 changes: 0 additions & 64 deletions Cargo.lock

This file was deleted.

7 changes: 2 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ authors = ["{{authors}}"]
edition = "2021"

[dependencies]
linked_list_allocator = "0.10.3"
rlibc = "1.0.0"

[build-dependencies]
cc = "*"
cannon-io = { git = "https://github.com/badboilabs/Cannon-rs" }
cannon-heap = { git = "https://github.com/badboilabs/Cannon-rs" }

[profile.dev]
panic = "abort"
Expand Down
46 changes: 0 additions & 46 deletions Dockerfile

This file was deleted.

21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

7 changes: 0 additions & 7 deletions Makefile

This file was deleted.

40 changes: 19 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,45 @@
# Rust Cannon Template 🦀💣💥

This repo contains a build system and a minimal Rust program for building MIPS binaries that are executable in the context of [Optimism Cannon](https://github.com/ethereum-optimism/cannon).

It comes with a few barebones helpers for reading the input hashes, writing output and using the pre-image oracle.
This repo contains a build system and a minimal Rust program for building MIPS binaries that are executable in the context of [Optimism Cannon](https://github.com/ethereum-optimism/optimism/tree/develop/cannon).

It is intended to be used as a template with `cargo generate` e.g.

```shell
cargo generate willemolding/rust-cannon-template
cargo generate BadBoiLabs/rust-cannon-template
```

## Usage
## Building

### Building with Docker

The template uses Docker for cross-compiling MIPS on any host. First build the docker image by running:
Preferred build method is using docker. BadBoiLabs provides a builder image for Cannon-rs projects

```shell
make docker_image
docker run --rm -v `pwd`/..:/code -w="/code" ghcr.io/badboilabs/cannon-rs/builder:main cargo build --release -Zbuild-std
```

After this a Cannon ready MIPS binary can be build with:
## Patching and running in Cannon

Install the `cannon` tool from Optimism (requires Golang installed)

```shell
make build
git clone https://github.com/ethereum-optimism/optimism
cd optimism/cannon
go install .
```

This will write an `out.bin` file to the build directory.

---
Patch the elf

Alternatively if you want to experiment in the build environment you can load up an interactive shell with

```shell
make docker_image
docker run -it --rm -v $(pwd):/code {{project-name}}/builder bash
cannon load-elf --path ../target/mips-unknown-none/release/{{project-name}} --patch stack
```
(replace with your project name as required)

and from there you can run
Run it in the Cannon emulator

```shell
./build.sh
cannon run --input ./state.json --info-at %100 --stop-at never
```
to produce the output

## Credits

The majority of this amazing work was done by @pepyakin in their [Cannon fork](https://github.com/pepyakin/rusty-cannon/). This just pulls out the relevant pieces and adds a few quality of life improvements to the build system.
The origins of this amazing work is from @pepyakin in their [Cannon fork](https://github.com/pepyakin/rusty-cannon/). This has evolved into a streamlined Cannon build system and been migrated to the latest version of Cannon
5 changes: 0 additions & 5 deletions build.rs

This file was deleted.

15 changes: 0 additions & 15 deletions build.sh

This file was deleted.

60 changes: 0 additions & 60 deletions elf2bin.py

This file was deleted.

19 changes: 0 additions & 19 deletions mips-unknown-none.json

This file was deleted.

4 changes: 0 additions & 4 deletions requirements.txt

This file was deleted.

30 changes: 0 additions & 30 deletions src/asm.S

This file was deleted.

Loading

0 comments on commit df49572

Please sign in to comment.