Skip to content

Commit

Permalink
Update sov-rollup-starter with RollupTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
bkolad committed Oct 20, 2023
1 parent 25876a2 commit 9063fa7
Show file tree
Hide file tree
Showing 20 changed files with 222 additions and 242 deletions.
1 change: 1 addition & 0 deletions examples/demo-rollup/src/celestia_rollup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl RollupTemplate for CelestiaDemoRollup {
fn create_genesis_config(
&self,
genesis_paths: &Self::GenesisPaths,
_rollup_config: &RollupConfig<Self::DaConfig>,
) -> <Self::NativeRuntime as sov_modules_stf_template::Runtime<
Self::NativeContext,
Self::DaSpec,
Expand Down
10 changes: 4 additions & 6 deletions examples/demo-rollup/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use clap::Parser;
use demo_stf::genesis_config::GenesisPaths;
use sov_demo_rollup::{CelestiaDemoRollup, MockDemoRollup};
use sov_modules_rollup_template::{Rollup, RollupProverConfig, RollupTemplate};
use sov_risc0_adapter::host::Risc0Host;
use sov_rollup_interface::mocks::MockDaConfig;
use sov_rollup_interface::zk::ZkvmHost;
use sov_stf_runner::{from_toml_path, RollupConfig};
use tracing::log::debug;
use tracing_subscriber::prelude::*;
Expand Down Expand Up @@ -46,7 +44,7 @@ async fn main() -> Result<(), anyhow::Error> {

match args.da_layer.as_str() {
"mock" => {
let rollup = new_rollup_with_mock_da::<Risc0Host<'static>>(
let rollup = new_rollup_with_mock_da(
&GenesisPaths::from_dir("../test-data/genesis/integration-tests"),
rollup_config_path,
Some(RollupProverConfig::Execute),
Expand All @@ -55,7 +53,7 @@ async fn main() -> Result<(), anyhow::Error> {
rollup.run().await
}
"celestia" => {
let rollup = new_rollup_with_celestia_da::<Risc0Host<'static>>(
let rollup = new_rollup_with_celestia_da(
&GenesisPaths::from_dir("../test-data/genesis/demo-tests"),
rollup_config_path,
Some(RollupProverConfig::Execute),
Expand All @@ -67,7 +65,7 @@ async fn main() -> Result<(), anyhow::Error> {
}
}

pub async fn new_rollup_with_celestia_da<Vm: ZkvmHost>(
async fn new_rollup_with_celestia_da(
genesis_paths: &GenesisPaths<PathBuf>,
rollup_config_path: &str,
prover_config: Option<RollupProverConfig>,
Expand All @@ -86,7 +84,7 @@ pub async fn new_rollup_with_celestia_da<Vm: ZkvmHost>(
.await
}

pub async fn new_rollup_with_mock_da<Vm: ZkvmHost>(
async fn new_rollup_with_mock_da(
genesis_paths: &GenesisPaths<PathBuf>,
rollup_config_path: &str,
prover_config: Option<RollupProverConfig>,
Expand Down
13 changes: 5 additions & 8 deletions examples/demo-rollup/src/mock_rollup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ use sov_modules_api::Spec;
use sov_modules_rollup_template::RollupTemplate;
use sov_modules_stf_template::Runtime as RuntimeTrait;
use sov_risc0_adapter::host::Risc0Host;
use sov_rollup_interface::mocks::{
MockAddress, MockDaConfig, MockDaService, MockDaSpec, MOCK_SEQUENCER_DA_ADDRESS,
};
use sov_rollup_interface::mocks::{MockDaConfig, MockDaService, MockDaSpec};
use sov_rollup_interface::services::da::DaService;
use sov_state::{ProverStorage, Storage, ZkStorage};
use sov_stf_runner::RollupConfig;
Expand Down Expand Up @@ -41,15 +39,14 @@ impl RollupTemplate for MockDemoRollup {
fn create_genesis_config(
&self,
genesis_paths: &Self::GenesisPaths,
rollup_config: &RollupConfig<Self::DaConfig>,
) -> <Self::NativeRuntime as RuntimeTrait<Self::NativeContext, Self::DaSpec>>::GenesisConfig
{
let sequencer_da_address = MockAddress::from(MOCK_SEQUENCER_DA_ADDRESS);

#[cfg(feature = "experimental")]
let eth_signer = read_eth_tx_signers();

get_genesis_config(
sequencer_da_address,
rollup_config.da.sender_address,
genesis_paths,
#[cfg(feature = "experimental")]
eth_signer.signers(),
Expand All @@ -58,9 +55,9 @@ impl RollupTemplate for MockDemoRollup {

async fn create_da_service(
&self,
_rollup_config: &RollupConfig<Self::DaConfig>,
rollup_config: &RollupConfig<Self::DaConfig>,
) -> Self::DaService {
MockDaService::new(MockAddress::from(MOCK_SEQUENCER_DA_ADDRESS))
MockDaService::new(rollup_config.da.sender_address)
}

fn create_vm(&self) -> Self::Vm {
Expand Down
46 changes: 23 additions & 23 deletions examples/demo-rollup/tests/bank/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,29 @@ use crate::test_helpers::start_rollup;
const TOKEN_SALT: u64 = 0;
const TOKEN_NAME: &str = "test_token";

#[tokio::test]
async fn bank_tx_tests() -> Result<(), anyhow::Error> {
let (port_tx, port_rx) = tokio::sync::oneshot::channel();

let rollup_task = tokio::spawn(async {
start_rollup(
port_tx,
GenesisPaths::from_dir("../test-data/genesis/integration-tests"),
Some(RollupProverConfig::Execute),
)
.await;
});

let port = port_rx.await.unwrap();

// If the rollup throws an error, return it and stop trying to send the transaction
tokio::select! {
err = rollup_task => err?,
res = send_test_create_token_tx(port) => res?,
};
Ok(())
}

async fn send_test_create_token_tx(rpc_address: SocketAddr) -> Result<(), anyhow::Error> {
let key = DefaultPrivateKey::generate();
let user_address: <DefaultContext as Spec>::Address = key.to_address();
Expand Down Expand Up @@ -65,26 +88,3 @@ async fn send_test_create_token_tx(rpc_address: SocketAddr) -> Result<(), anyhow
assert_eq!(balance_response.amount.unwrap_or_default(), 1000);
Ok(())
}

#[tokio::test]
async fn bank_tx_tests() -> Result<(), anyhow::Error> {
let (port_tx, port_rx) = tokio::sync::oneshot::channel();

let rollup_task = tokio::spawn(async {
start_rollup(
port_tx,
GenesisPaths::from_dir("../test-data/genesis/integration-tests"),
Some(RollupProverConfig::Execute),
)
.await;
});

let port = port_rx.await.unwrap();

// If the rollup throws an error, return it and stop trying to send the transaction
tokio::select! {
err = rollup_task => err?,
res = send_test_create_token_tx(port) => res?,
};
Ok(())
}
3 changes: 2 additions & 1 deletion module-system/sov-modules-rollup-template/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub trait RollupTemplate: Sized + Send + Sync {
fn create_genesis_config(
&self,
genesis_paths: &Self::GenesisPaths,
rollup_config: &RollupConfig<Self::DaConfig>,
) -> <Self::NativeRuntime as RuntimeTrait<Self::NativeContext, Self::DaSpec>>::GenesisConfig;

/// Creates instance of DA Service.
Expand Down Expand Up @@ -95,7 +96,7 @@ pub trait RollupTemplate: Sized + Send + Sync {
{
let da_service = self.create_da_service(&rollup_config).await;
let ledger_db = self.create_ledger_db(&rollup_config);
let genesis_config = self.create_genesis_config(genesis_paths);
let genesis_config = self.create_genesis_config(genesis_paths, &rollup_config);

let prover = prover_config.map(|pc| {
configure_prover(
Expand Down
1 change: 1 addition & 0 deletions sov-rollup-starter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rollup-starter-data
3 changes: 3 additions & 0 deletions sov-rollup-starter/provers/risc0/guest-mock/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion sov-rollup-starter/provers/risc0/guest-mock/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ resolver = "2"
anyhow = "1.0.68"
risc0-zkvm = { version = "0.18", default-features = false, features = ["std"] }
risc0-zkvm-platform = "0.18"
stf-starter = { path = "../../../stf" }
sov-risc0-adapter = { path = "../../../../adapters/risc0" }
sov-rollup-interface = { path = "../../../../rollup-interface", features = ["mocks"] }

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

sov-modules-api = { path = "../../../../module-system/sov-modules-api" }
sov-state = { path = "../../../../module-system/sov-state" }
sov-modules-stf-template = { path = "../../../../module-system/sov-modules-stf-template" }

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

Expand Down
21 changes: 20 additions & 1 deletion sov-rollup-starter/provers/risc0/guest-mock/src/bin/mock_da.rs
Original file line number Diff line number Diff line change
@@ -1,6 +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() {}
pub fn main() {
let guest = Risc0Guest::new();
let storage = ZkStorage::new();
let app: AppTemplate<ZkDefaultContext, _, _, Runtime<_, _>> = AppTemplate::new(storage);

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

stf_verifier
.run_block(guest)
.expect("Prover must be honest");
}
2 changes: 1 addition & 1 deletion sov-rollup-starter/rollup_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sender_address = "01010101010101010101010101010101010101010101010101010101010101

[storage]
# The path to the rollup's data directory. Paths that do not begin with `/` are interpreted as relative paths.
path = "demo_data"
path = "rollup-starter-data"

# We define the rollup's genesis to occur at block number `start_height`. The rollup will ignore
# any blocks before this height
Expand Down
83 changes: 44 additions & 39 deletions sov-rollup-starter/src/bin/node.rs
Original file line number Diff line number Diff line change
@@ -1,54 +1,59 @@
//! This binary runs the rollup full node.
/*
use std::env;
use std::path::PathBuf;
use std::str::FromStr;

use anyhow::Context;
use sov_risc0_adapter::host::Risc0Host;
use sov_rollup_interface::mocks::{MockAddress, MOCK_SEQUENCER_DA_ADDRESS};
use sov_rollup_starter::da::{start_da_service, DaConfig};
use sov_rollup_starter::rollup::Rollup;
use clap::Parser;
use sov_modules_rollup_template::{Rollup, RollupProverConfig, RollupTemplate};
use sov_rollup_interface::mocks::MockDaConfig;
use sov_rollup_starter::rollup::StarterRollup;
use sov_stf_runner::{from_toml_path, RollupConfig};
use stf_starter::{get_genesis_config, GenesisPaths};
use stf_starter::genesis_config::GenesisPaths;
use tracing::info;
use tracing_subscriber::filter::LevelFilter;
use tracing_subscriber::EnvFilter;*/
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, EnvFilter};

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
/// The path to the rollup config.
#[arg(long, default_value = "rollup_config.toml")]
rollup_config_path: String,
}

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
/*// Initialize a logger for the demo
let subscriber = tracing_subscriber::fmt()
.with_env_filter(
EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into()) // If no logging config is set. default to `info` level logs
.from_env_lossy(), // Parse the log level from the RUST_LOG env var if set
) // Try to override logging config from RUST_LOG env var
.finish();
tracing::subscriber::set_global_default(subscriber)
.context("Unable to set global default subscriber")?;
// Read the rollup config from a file
let rollup_config_path = env::args()
.nth(1)
.map(PathBuf::from)
.unwrap_or_else(|| PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("rollup_config.toml"));
// Initializing logging
tracing_subscriber::registry()
.with(fmt::layer())
.with(EnvFilter::from_str("debug,hyper=info").unwrap())
.init();

let args = Args::parse();
let rollup_config_path = args.rollup_config_path.as_str();

let rollup = new_rollup_with_mock_da(
&GenesisPaths::from_dir("test-data/genesis/"),
rollup_config_path,
Some(RollupProverConfig::Execute),
)
.await?;
rollup.run().await
}

async fn new_rollup_with_mock_da(
genesis_paths: &GenesisPaths<PathBuf>,
rollup_config_path: &str,
prover_config: Option<RollupProverConfig>,
) -> Result<Rollup<StarterRollup>, anyhow::Error> {
info!("Reading rollup config from {rollup_config_path:?}");

let rollup_config: RollupConfig<DaConfig> =
let rollup_config: RollupConfig<MockDaConfig> =
from_toml_path(rollup_config_path).context("Failed to read rollup configuration")?;
info!("Initializing DA service");
let da_service = start_da_service(&rollup_config).await;
let sequencer_da_address = MockAddress::from(MOCK_SEQUENCER_DA_ADDRESS);
let genesis_paths = GenesisPaths::from_dir("../../test-data/genesis/");
let genesis_config = get_genesis_config(sequencer_da_address, &genesis_paths);
// Start rollup
let rollup: Rollup<Risc0Host, _> =
Rollup::new(da_service, genesis_config, rollup_config, None)?;
rollup.run().await?;*/

Ok(())
let starter_rollup = StarterRollup {};
starter_rollup
.create_new_rollup(genesis_paths, rollup_config, prover_config)
.await
}
11 changes: 0 additions & 11 deletions sov-rollup-starter/src/da.rs

This file was deleted.

3 changes: 1 addition & 2 deletions sov-rollup-starter/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![deny(missing_docs)]
#![doc = include_str!("../README.md")]
pub mod da;
mod register_rpc;
mod register_sequencer;
pub mod rollup;
22 changes: 0 additions & 22 deletions sov-rollup-starter/src/register_rpc.rs

This file was deleted.

Loading

0 comments on commit 9063fa7

Please sign in to comment.