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

Add Sov Labs Protocol Units #6

Closed
wants to merge 9 commits into from
Closed
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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"rust-analyzer.showUnlinkedFileNotification": false
}
34 changes: 32 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ license = "Apache-2.0"
[workspace]
resolver = "2"
members = [
"protocol-units/data-availability",
"protocol-units/data-availability/rollup",
"protocol-units/data-availability/stf",
"protocol-units/zkfp/host",
"protocol-units/zkfp/methods",
"protocol-units/zkfp/methods/guest"
Expand All @@ -19,12 +20,20 @@ exclude = [

[workspace.dependencies]
anyhow = "1.0"
async-trait = "0.1.77"
borsh = { version = "0.10.3", features = ["rc", "bytes"] }
clap = { version = "4.4.10", features = ["derive"] }
jsonrpsee = { version = "0.20.1", features = ["jsonrpsee-types"] }
# To try (experimental) std support, add `features = [ "std" ]` to risc0-zkvm
risc0-zkvm = { version = "0.20.1", features = ["std"] }
tracing = "0.1.40" #soverign labs requires this
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
serde = "1.0"
serde = { version = "1.0.192", features = ["derive", "rc"] }
serde_json = "1.0"
tokio = "1.26.0"
tempfile = "3.2.0"


# Move dependencies
move-vm-runtime = { path = "protocol-units/zkfp/vendors/move/language/move-vm/runtime" }
move-vm-test-utils = { path = "protocol-units/zkfp/vendors/move/language/move-vm/test-utils" }
Expand All @@ -34,6 +43,27 @@ move-core-types = { path = "protocol-units/zkfp/vendors/move/language/move-core/
move-compiler = { path = "protocol-units/zkfp/vendors/move/language/move-compiler" }
move-stdlib = { path = "protocol-units/zkfp/vendors/move/language/move-stdlib" }

# Sovereign SDK dependencies
sov-modules-api = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-state = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-accounts = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-bank = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-ledger-rpc = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-sequencer-registry = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-modules-stf-blueprint = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-modules-rollup-blueprint = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-stf-runner = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-db = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-sequencer = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-rollup-interface = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-risc0-adapter = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-first-read-last-write-cache = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-cli = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-mock-da = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-celestia-adapter = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-prover-storage-manager = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }

risc0-build = "0.20.1"

# Always optimize; building and running the guest takes much longer without optimization.
[profile.dev]
Expand Down
5 changes: 0 additions & 5 deletions protocol-units/data-availability/Cargo.toml

This file was deleted.

16 changes: 16 additions & 0 deletions protocol-units/data-availability/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-celestia", "guest-mock"]

[features]
bench = []
24 changes: 24 additions & 0 deletions protocol-units/data-availability/provers/risc0/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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 ROLLUP_ELF: &[u8] = &[];
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()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[package]
name = "sov-demo-prover-guest-celestia"
version = "0.3.0"
edition = "2021"
resolver = "2"

[workspace]

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

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

sov-rollup-interface = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-celestia-adapter = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-modules-api = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-modules-stf-blueprint = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-risc0-adapter = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-state = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }

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

# Uncomment to apply the v0.19 build script downlaod issue hotfix.
risc0-circuit-recursion = { git = "https://github.com/neysofu/risc0-hotfixes", rev = "v0.19.2-hotfix" }
risc0-zkvm = { git = "https://github.com/neysofu/risc0-hotfixes", rev = "v0.19.2-hotfix" }
risc0-zkvm-platform = { git = "https://github.com/neysofu/risc0-hotfixes", rev = "v0.19.2-hotfix" }
risc0-circuit-rv32im = { git = "https://github.com/neysofu/risc0-hotfixes", rev = "v0.19.2-hotfix" }


[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
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// TODO: Rename this file to change the name of this method from METHOD_NAME

#![no_main]

use sov_celestia_adapter::types::Namespace;
use sov_celestia_adapter::verifier::CelestiaVerifier;
use sov_modules_api::default_context::ZkDefaultContext;
use sov_modules_stf_blueprint::kernels::basic::BasicKernel;
use sov_modules_stf_blueprint::StfBlueprint;
use sov_risc0_adapter::guest::Risc0Guest;
use sov_state::ZkStorage;
use stf_starter::runtime::Runtime;
use stf_starter::StfVerifier;

/// The namespace for the rollup on Celestia. Must be kept in sync with the "rollup/src/lib.rs"
const ROLLUP_NAMESPACE: Namespace = Namespace::const_v0(*b"sov-celest");

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

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

let stf_verifier = StfVerifier::new(
stf,
CelestiaVerifier {
rollup_namespace: ROLLUP_NAMESPACE,
},
);
stf_verifier
.run_block(guest, storage)
.expect("Prover must be honest");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[workspace]

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

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

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


sov-rollup-interface = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-mock-da = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-modules-stf-blueprint = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-modules-api = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-risc0-adapter = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }
sov-state = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "13e4077c329ff14954b32e3180d43a6d86fa3172" }

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

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

# Uncomment to apply the v0.19 build script downlaod issue hotfix.
risc0-circuit-recursion = { git = "https://github.com/neysofu/risc0-hotfixes", rev = "v0.19.2-hotfix" }
risc0-zkvm = { git = "https://github.com/neysofu/risc0-hotfixes", rev = "v0.19.2-hotfix" }
risc0-zkvm-platform = { git = "https://github.com/neysofu/risc0-hotfixes", rev = "v0.19.2-hotfix" }
risc0-circuit-rv32im = { git = "https://github.com/neysofu/risc0-hotfixes", rev = "v0.19.2-hotfix" }


[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
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#![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_mock_da::MockDaVerifier;
use sov_modules_api::default_context::ZkDefaultContext;
use sov_modules_stf_blueprint::kernels::basic::BasicKernel;
use sov_modules_stf_blueprint::StfBlueprint;
use sov_risc0_adapter::guest::Risc0Guest;
use sov_state::ZkStorage;
use stf_starter::runtime::Runtime;
use stf_starter::StfVerifier;

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

pub fn main() {
let guest = Risc0Guest::new();
let storage = ZkStorage::new();
#[cfg(feature = "bench")]
let start_cycles = env::get_cycle_count();

let stf: StfBlueprint<ZkDefaultContext, _, _, Runtime<_, _>> = StfBlueprint::new();
let stf_verifier = StfVerifier::new(stf, MockDaVerifier {});

stf_verifier
.run_block(guest, storage)
.expect("Prover must be honest");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include!(concat!(env!("OUT_DIR"), "/methods.rs"));
61 changes: 61 additions & 0 deletions protocol-units/data-availability/rollup/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
[package]
name = "rollup"
version = "0.1.0"
edition = "2021"
resolver = "2"
description = "Sovereign Labs Rollup"

[dependencies]
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 }

# Sovereign Labs dependencies
sov-modules-api = { workspace = true, features = ["native"] }
sov-state = { workspace = true }
sov-prover-storage-manager = { 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-blueprint = { workspace = true }
sov-modules-stf-blueprint = { 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 }
sov-mock-da = { workspace = true, features = ["native"], optional=true }
sov-celestia-adapter = { workspace = true, features = ["native"], optional=true }

risc0-starter = { path = "../provers/risc0" }
stf = { 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 = ["mock_da"] # set mock_da as the default feature
mock_da = ["sov-mock-da"]
celestia_da = ["sov-celestia-adapter"]

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

# [[bin]]
# name = "starter-cli-wallet"
# path = "src/bin/starter_cli_wallet.rs"
Loading
Loading