Skip to content

Commit

Permalink
Implement starter rollup
Browse files Browse the repository at this point in the history
  • Loading branch information
bkolad committed Oct 27, 2023
1 parent da568dc commit 0e4f534
Show file tree
Hide file tree
Showing 32 changed files with 1,099 additions and 1 deletion.
29 changes: 29 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Rust

on:
workflow_dispatch:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
- name: Install cargo-risc0 # Risc0 v0.17 and higher require a cargo extension to build the guest code
run: cargo install cargo-risczero
- name: Install risc0-zkvm toolchain # Use the risc0 cargo extension to install the risc0 std library for the current toolchain
run: cargo risczero install
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/target/
/rollup-starter-data/
/crates/provers/risc0/guest-mock/target
Cargo.lock
50 changes: 50 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[workspace]

resolver = "2"

members = [
"crates/rollup",
"crates/stf",
]

[workspace.package]
version = "0.3.0"
edition = "2021"
license = "MIT OR Apache-2.0"
authors = ["Informal Systems <[email protected]>", "Sovereign Labs <[email protected]>"]
publish = false
rust-version = "1.73"

[workspace.dependencies]
sov-modules-api = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "nightly" }
sov-state = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "nightly" }
sov-accounts = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "nightly" }
sov-bank = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "nightly" }
sov-ledger-rpc = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "nightly" }
sov-sequencer-registry = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "nightly" }
sov-modules-stf-template = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "nightly" }
sov-modules-rollup-template = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "nightly" }
sov-stf-runner = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "nightly" }
sov-db = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "nightly" }
sov-sequencer = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "nightly" }
sov-rollup-interface = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "nightly" }
sov-risc0-adapter = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "nightly" }
sov-first-read-last-write-cache = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "nightly" }
sov-cli = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "nightly" }
stf-starter = { path = "./crates/stf" }

serde = { version = "1.0.188", features = ["derive", "rc"] }
serde_json = { version = "1.0" }


anyhow = "1.0.68"
clap = { version = "4.2.7", features = ["derive"] }
async-trait = "0.1.71"
borsh = { version = "0.10.3", features = ["rc", "bytes"] }
tracing = "0.1.40"
tokio = { version = "1", features = ["full"] }
tempfile = "3.5"
jsonrpsee = { version = "0.20.1", features = ["jsonrpsee-types"] }

risc0-build = "0.18"

30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
# sov-rollup-starter

# This is still work in progress.

This package is a convenient starting point for building a rollup using the Sovereign SDK:


# How to run the sov-rollup-starter:
1. `cd crates/rollup/`

2. Starting the node:
If you want to run a fresh rollup remove the `rollup-starter-data` folder.
This will compile and start the rollup node:

```shell
cargo run --bin node
```


3. In another shell run:

```shell
make test-create-token
```

4. Test if token creation succeeded

```shell
make test-bank-supply-of
```
30 changes: 30 additions & 0 deletions constants.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"comment": "Sovereign SDK constants",
"gas": {
"Bank": {
"create_token": [
4,
4
],
"transfer": [
5,
5
],
"burn": [
2,
2
],
"mint": [
2,
2
],
"freeze": [
1,
1
]
}
},
"constants": {
"DEFERRED_SLOTS_COUNT": 2
}
}
2 changes: 2 additions & 0 deletions crates/provers/risc0/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[patch.crates-io]
cc = { git = "https://github.com/rust-lang/cc-rs", rev = "e5bbdfa" }
16 changes: 16 additions & 0 deletions crates/provers/risc0/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "risc0-starter"
version = "0.3.0"
edition = "2021"
resolver = "2"
license = "MIT OR Apache-2.0"
publish = false

[build-dependencies]
risc0-build = { workspace = true }

[package.metadata.risc0]
methods = ["guest-mock"]

[features]
bench = []
23 changes: 23 additions & 0 deletions crates/provers/risc0/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use std::collections::HashMap;

fn main() {
if std::env::var("SKIP_GUEST_BUILD").is_ok() {
println!("Skipping guest build for CI run");
let out_dir = std::env::var_os("OUT_DIR").unwrap();
let out_dir = std::path::Path::new(&out_dir);
let methods_path = out_dir.join("methods.rs");

let elf = r#"
pub const MOCK_DA_ELF: &[u8] = &[];
"#;

std::fs::write(methods_path, elf).expect("Failed to write mock rollup elf");
} else {
let guest_pkg_to_options = get_guest_options();
risc0_build::embed_methods_with_options(guest_pkg_to_options);
}
}

fn get_guest_options() -> HashMap<&'static str, risc0_build::GuestOptions> {
HashMap::new()
}
40 changes: 40 additions & 0 deletions crates/provers/risc0/guest-mock/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[workspace]

[package]
name = "guest-mock-starter"
version = "0.3.0"
edition = "2021"
resolver = "2"

[dependencies]
anyhow = "1.0.68"
risc0-zkvm = { version = "0.18", default-features = false, features = ["std"] }
risc0-zkvm-platform = "0.18"

serde = { version = "1.0.188", features = ["derive", "rc"] }


sov-rollup-interface = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "nightly", features = ["mocks"] }
sov-modules-stf-template = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "nightly" }
sov-modules-api = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "nightly" }
sov-risc0-adapter = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "nightly" }
sov-state = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "nightly" }

stf-starter = { path = "../../../stf" }

[patch.crates-io]
sha2 = { git = "https://github.com/risc0/RustCrypto-hashes", tag = "sha2/v0.10.6-risc0" }


[profile.dev]
opt-level = 3

[profile.dev.build-override]
opt-level = 3

[profile.release]
debug = 1
lto = true

[profile.release.build-override]
opt-level = 3
25 changes: 25 additions & 0 deletions crates/provers/risc0/guest-mock/src/bin/mock_da.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#![no_main]
//! This binary implements the verification logic for the rollup. This is the code that runs inside
//! of the zkvm in order to generate proofs for the rollup.
use sov_modules_api::default_context::ZkDefaultContext;
use sov_modules_stf_template::AppTemplate;
use sov_risc0_adapter::guest::Risc0Guest;
use sov_rollup_interface::mocks::MockDaVerifier;
use sov_state::ZkStorage;
use stf_starter::runtime::Runtime;
use stf_starter::AppVerifier;

risc0_zkvm::guest::entry!(main);

pub fn main() {
let guest = Risc0Guest::new();
let storage = ZkStorage::new();
let app: AppTemplate<ZkDefaultContext, _, _, Runtime<_, _>> = AppTemplate::new();

let mut stf_verifier = AppVerifier::new(app, MockDaVerifier {});

stf_verifier
.run_block(guest, storage)
.expect("Prover must be honest");
}
1 change: 1 addition & 0 deletions crates/provers/risc0/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include!(concat!(env!("OUT_DIR"), "/methods.rs"));
62 changes: 62 additions & 0 deletions crates/rollup/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[package]
name = "sov-rollup-starter"
version = { workspace = true }
edition = { workspace = true }
resolver = "2"
authors = { workspace = true }
license = { workspace = true }
homepage = "sovereign.xyz"
publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
sov-modules-api = { workspace = true, features = ["native"] }
sov-state = { workspace = true }
sov-accounts = { workspace = true, features = ["native"] }
sov-bank = { workspace = true, features = ["native"] }
sov-ledger-rpc = { workspace = true, features = ["server"] }
sov-sequencer-registry = { workspace = true, features = ["native"] }
sov-modules-rollup-template = { workspace = true }
sov-modules-stf-template = { workspace = true, features = ["native"] }
sov-stf-runner = { workspace = true, features = ["native"] }
sov-cli = { workspace = true, optional = true }

sov-db = { workspace = true }
sov-sequencer = { workspace = true }
sov-rollup-interface = { workspace = true, features = ["mocks"] }


anyhow = { workspace = true }
async-trait = { workspace = true }
borsh = { workspace = true }
clap = { workspace = true }
serde = { workspace = true }
tracing = { workspace = true }
serde_json = { workspace = true }
jsonrpsee = { workspace = true }
tokio = { workspace = true }

risc0-starter = { path = "../provers/risc0" }
stf-starter = { path = "../stf", features = ["native"] }


sov-risc0-adapter = { workspace = true, features = ["native"] }

# binary dependencies
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }

[dev-dependencies]
tempfile = { workspace = true }


[features]
default = []

[[bin]]
name = "node"
path = "src/bin/node.rs"

[[bin]]
name = "starter-cli-wallet"
path = "src/bin/starter_cli_wallet.rs"
23 changes: 23 additions & 0 deletions crates/rollup/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
PROJECT_ROOT := $(shell git rev-parse --show-toplevel)
SOV_CLI_REL_PATH := $(PROJECT_ROOT)/target/debug/starter-cli-wallet

build-sov-cli:
cargo build --bin starter-cli-wallet

set-rpc-url: build-sov-cli
$(SOV_CLI_REL_PATH) rpc set-url http://127.0.0.1:12345

import-keys: build-sov-cli
$(SOV_CLI_REL_PATH) keys import --nickname DANGER__DO_NOT_USE_WITH_REAL_MONEY --path ../../test-data/keys/token_deployer_private_key.json


test-generate-create-token-tx: build-sov-cli
$(SOV_CLI_REL_PATH) transactions import from-file bank --path ../../test-data/requests/create_token.json


test-create-token: set-rpc-url test-generate-create-token-tx import-keys
$(SOV_CLI_REL_PATH) rpc submit-batch by-nickname DANGER__DO_NOT_USE_WITH_REAL_MONEY


test-bank-supply-of:
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"bank_supplyOf","params":["sov1zdwj8thgev2u3yyrrlekmvtsz4av4tp3m7dm5mx5peejnesga27svq9m72"],"id":1}' http://127.0.0.1:12345
Loading

0 comments on commit 0e4f534

Please sign in to comment.