Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Reorganizations + MIPS64 assembly tests #7

Merged
merged 5 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 26 additions & 34 deletions .github/workflows/ci.yaml → .github/workflows/rust_ci.yaml
Original file line number Diff line number Diff line change
@@ -1,80 +1,72 @@
name: Rust CI
on: [push]

on:
push:
branches: [main]
merge_group:
pull_request:
env:
CARGO_TERM_COLOR: always

jobs:
cargo-tests:
runs-on: ubuntu-latest
timeout-minutes: 20
name: test
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Install Rust nightly toolchain
uses: dtolnay/rust-toolchain@nightly
- uses: taiki-e/install-action@just
- name: Install Rust stable toolchain
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: Install xsltproc
run: sudo apt-get install xsltproc
- uses: taiki-e/install-action@nextest
- name: cargo test
run: cargo nextest run --release --workspace --all --locked
run: just test
cargo-lint:
runs-on: ubuntu-latest
timeout-minutes: 20
name: lint
steps:
- name: Checkout sources
uses: actions/checkout@v4
- uses: taiki-e/install-action@just
- name: Install Rust nightly toolchain
uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: Install xsltproc
run: sudo apt-get install xsltproc
- name: cargo fmt
run: cargo fmt --all -- --check
- name: cargo clippy
run: cargo clippy --workspace --all --locked -- -D warnings
cargo-build:
- name: lint
run: just lint
cargo-build-benches:
runs-on: ubuntu-latest
timeout-minutes: 20
name: build-benchmarks
continue-on-error: true
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Install Rust nightly toolchain
uses: dtolnay/rust-toolchain@nightly
- name: Install Rust stable toolchain
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: Install xsltproc
run: sudo apt-get install xsltproc
- name: build
id: build
run: cargo build --workspace --all --locked
cargo-doc:
- name: build benches
run: cargo bench --no-run --workspace --all --all-features
cargo-build:
runs-on: ubuntu-latest
timeout-minutes: 20
name: build
continue-on-error: true
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Install Rust nightly toolchain
uses: dtolnay/rust-toolchain@nightly
- name: Install Rust stable toolchain
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: Install xsltproc
run: sudo apt-get install xsltproc
- name: doclint
id: build
continue-on-error: true
run: RUSTDOCFLAGS="-D warnings" cargo doc --all --no-deps --document-private-items
- name: doctest
run: cargo test --doc --all --locked

- name: build
run: cargo build --workspace --all --all-targets --all-features
36 changes: 36 additions & 0 deletions .github/workflows/sol_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Solidity CI
on:
push:
branches: [main]
merge_group:
pull_request:
env:
FOUNDRY_PROFILE: ci
jobs:
check:
name: lint & test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Run Forge build
working-directory: ./contracts
run: |
forge --version
forge build --sizes
id: build
- name: Run Forge fmt
working-directory: ./contracts
run: |
forge fmt --check
id: fmt
- name: Run Forge tests
working-directory: ./contracts
run: |
forge test -vvv
id: test
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
.DS_Store

# Rust
/target
target/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "crates/fpvm/bindings/optimism"]
path = crates/fpvm/bindings/optimism
url = https://github.com/ethereum-optimism/optimism
[submodule "contracts/lib/forge-std"]
path = contracts/lib/forge-std
url = https://github.com/foundry-rs/forge-std
59 changes: 26 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,81 +12,71 @@
</a>
<img src="https://img.shields.io/badge/License-MIT-green.svg?label=license" alt="License">
<a href="https://github.com/ethereum-optimism/monorepo"><img src="https://img.shields.io/badge/OP%20Stack-monorepo-red" alt="OP Stack"></a>
<a href="https://t.me/+2yfSX0YikWMxNTRh"><img src="https://img.shields.io/badge/Telegram-x?logo=telegram&label=anton-rs%20contributors"></a>
</p>

<p align="center">
<a href="#whats-a-howitzer">What's a Howitzer?</a> •
<a href="#overview">Overview</a> •
<a href="#credits">Credits</a> •
<a href="#benchmarks">Benchmarks</a> •
<a href="#docker">Docker</a> •
<a href="#contributing">Contributing</a> •
<a href="#documentation">Documentation</a> •
<a href="#docker">Docker</a>
<a href="#credits">Credits</a>
</p>

## What's a Howitzer?

Howitzer is an emulator designed to simulate a single MIPS thread context on the EVM. Its primary use is to execute the [`op-program`][op-program]
(also known as the fault-proof program) for the [OP Stack][monorepo]'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 Howitzer on-chain to prove fault in claims about the state of L2 on L1. Howitzer also has a
native implementation of the MIPS thread context that mirrors the on-chain version, which enables the [op-challenger][op-challenger] to generate
state commitments for an `op-program` execution trace and participate in dispute games.
Howitzer is a MIPS64 emulator designed to simulate deterministic execution within a single MIPS thread context both
natively and on the EVM. Its primary objective is to execute [Fault Proof Programs][fpp-specs] such as [`kona`][kona]
or [`op-program`][op-program] for the sake of the [OP Stack][monorepo]'s interactive dispute protocol.

_TL;DR:_

- It's Rust code
- ...that was [originally Go code][cannon]
- ...that runs an EVM
- ...emulating a MIPS machine
- ...running [compiled Go code][op-program]
- ...emulating a MIPS64 machine
- ...that was originally a MIPS32 machine
- ...running compiled [Rust][kona] or [Go][op-program] code
- ...that runs an EVM

## Overview

- [`howitzer`](./bin) - The binary for executing MIPS64 programs natively on top of Howitzer with a detached preimage server.
- [`howitzer-kernel`](./crates/kernel) - High-level library for running the Howitzer FPVM with a detached preimage server.
- [`howitzer-fpvm`](./crates/fpvm) - Contains the native implementation of the MIPS thread context emulator.
- [`howitzer-contracts`](https://github.com/ethereum-optimism/optimism/tree/develop/packages/contracts-bedrock/src/cannon) - [*in OP monorepo*] Contains the Solidity implementation of the MIPS thread context and the Preimage Oracle. (TODO: Will be replaced with Howitzer contracts, as the VM architectures will differ.)
- [`howitzer-contracts`](./contracts) - Contains the EVM implementation of the MIPS thread context emulator.

## Credits

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

## Benchmarks

### `howitzer-fpvm` benchmarks
## Docker

_TODO_
The docker image for `howitzer` is located in the [docker](./docker) directory, and can be built using the
script provided.

## Contributing

To get started, a few dependencies are required:

- [Rust toolchain][rustup]
- Recommended: [`cargo-nextest`][nextest]
- [Just][just]
- [Go toolchain][golang]
- [binutils][binutils]

### Testing

```sh
# With `cargo-nextest`
cargo +nightly nextest run --release --all --all-features
# Without `cargo-nextest`
cargo +nightly t --release --all --all-features
just test
```

### Linting and Formatting

```sh
cargo +nightly fmt --all -- && cargo +nightly clippy --all --all-features -- -D warnings
just lint
```

### Running Benchmarks

```sh
cargo +nightly bench --all --all-features
just bench
```

## Documentation
Expand All @@ -100,20 +90,23 @@ The specification for both Cannon and the preimage oracle can be found in the [O
- [Cannon specification][cannon-specs]
- [Preimage oracle specification][fpp-specs]

## Docker
## Credits

The docker image for `howitzer` is located in the [docker](./docker) directory, and can be built using the
script provided.
This repository is heavily inspired by the original [Cannon][cannon] VM, built by [George Hotz][geohot] and members of the
[OP Labs][op-labs] team. The original implementation is written in Go, and can be found [in the Optimism monorepo][cannon]. All
credits for the original idea and reference implementation of this concept go to these folks.

[geohot]: https://github.com/geohot
[op-labs]: https://oplabs.co
[monorepo]: https://github.com/ethereum-optimism/optimism
[cannon]: https://github.com/ethereum-optimism/optimism/tree/develop/cannon
[kona]: https://github.com/ethereum-optimism/kona
[op-program]: https://github.com/ethereum-optimism/optimism/tree/develop/op-program
[op-challenger]: https://github.com/ethereum-optimism/optimism/tree/develop/op-challenger
[fpp-specs]: https://specs.optimism.io/fault-proof/index.html
[cannon-specs]: https://github.com/ethereum-optimism/optimism/blob/develop/specs/cannon-fault-proof-vm.md
[rustup]: https://rustup.rs/
[golang]: https://go.dev/doc/install
[binutils]: https://www.gnu.org/software/binutils/
[nextest]: https://nexte.st/
[fpp-specs]: https://github.com/ethereum-optimism/optimism/blob/develop/specs/fault-proof.md
[cannon-specs]: https://github.com/ethereum-optimism/optimism/blob/develop/specs/cannon-fault-proof-vm.md
[just]: https://github.com/casey/just
14 changes: 14 additions & 0 deletions contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Compiler files
cache/
out/

# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/

# Docs
docs/

# Dotenv file
.env
3 changes: 3 additions & 0 deletions contracts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `howitzer-contracts`

_TODO_
9 changes: 9 additions & 0 deletions contracts/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
optimizer = true
optimizer_runs = 999_999_999
via_ir = true
evm_version = "cancun"
ignored_error_codes = ["transient-storage"]
1 change: 1 addition & 0 deletions contracts/lib/forge-std
Submodule forge-std added at 07263d
14 changes: 14 additions & 0 deletions contracts/src/Counter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

contract Counter {
uint256 public number;

function setNumber(uint256 newNumber) public {
number = newNumber;
}

function increment() public {
number++;
}
}
24 changes: 24 additions & 0 deletions contracts/test/Counter.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import {Test, console} from "forge-std/Test.sol";
import {Counter} from "../src/Counter.sol";

contract CounterTest is Test {
Counter public counter;

function setUp() public {
counter = new Counter();
counter.setNumber(0);
}

function test_Increment() public {
counter.increment();
assertEq(counter.number(), 1);
}

function testFuzz_SetNumber(uint256 x) public {
counter.setNumber(x);
assertEq(counter.number(), x);
}
}
Loading