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

Update sov-rollup-starter with RollupTemplate #1082

Merged
merged 8 commits into from
Oct 20, 2023
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
2 changes: 2 additions & 0 deletions Cargo.lock

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

5 changes: 3 additions & 2 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 Expand Up @@ -92,11 +93,11 @@ impl RollupTemplate for CelestiaDemoRollup {
fn create_native_storage(
&self,
rollup_config: &sov_stf_runner::RollupConfig<Self::DaConfig>,
) -> <Self::NativeContext as sov_modules_api::Spec>::Storage {
) -> Result<<Self::NativeContext as sov_modules_api::Spec>::Storage, anyhow::Error> {
let storage_config = StorageConfig {
path: rollup_config.storage.path.clone(),
};
ProverStorage::with_config(storage_config).expect("Failed to open prover storage")
ProverStorage::with_config(storage_config)
}

fn create_rpc_methods(
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
17 changes: 7 additions & 10 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 All @@ -81,11 +78,11 @@ impl RollupTemplate for MockDemoRollup {
fn create_native_storage(
&self,
rollup_config: &RollupConfig<Self::DaConfig>,
) -> <Self::NativeContext as Spec>::Storage {
) -> Result<<Self::NativeContext as sov_modules_api::Spec>::Storage, anyhow::Error> {
let storage_config = StorageConfig {
path: rollup_config.storage.path.clone(),
};
ProverStorage::with_config(storage_config).expect("Failed to open prover storage")
ProverStorage::with_config(storage_config)
}

fn create_rpc_methods(
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(())
}
7 changes: 4 additions & 3 deletions 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 All @@ -70,7 +71,7 @@ pub trait RollupTemplate: Sized + Send + Sync {
fn create_native_storage(
&self,
rollup_config: &RollupConfig<Self::DaConfig>,
) -> <Self::NativeContext as Spec>::Storage;
) -> Result<<Self::NativeContext as Spec>::Storage, anyhow::Error>;

/// Creates instance of ZkVm.
fn create_vm(&self) -> Self::Vm;
Expand All @@ -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 All @@ -106,7 +107,7 @@ pub trait RollupTemplate: Sized + Send + Sync {
)
});

let storage = self.create_native_storage(&rollup_config);
let storage = self.create_native_storage(&rollup_config)?;

let prev_root = ledger_db
.get_head_slot()?
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
2 changes: 2 additions & 0 deletions sov-rollup-starter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ sov-accounts = { path = "../module-system/module-implementations/sov-accounts",
sov-bank = { path = "../module-system/module-implementations/sov-bank", features = ["native"] }
sov-ledger-rpc = { path = "../full-node/sov-ledger-rpc", features = ["server"] }
sov-sequencer-registry = { path = "../module-system/module-implementations/sov-sequencer-registry", features = ["native"] }
sov-modules-rollup-template = { path = "../module-system/sov-modules-rollup-template" }
sov-modules-stf-template = { path = "../module-system/sov-modules-stf-template/", features = ["native"] }
sov-stf-runner = { path = "../full-node/sov-stf-runner", features = ["native"] }
async-trait = { workspace = true }
borsh = { workspace = true }
clap = { workspace = true }
serde = { workspace = true }
Expand Down
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
Loading
Loading