Skip to content

Commit 35379ab

Browse files
authored
Update sov-rollup-starter with RollupTemplate (#1082)
* fix * Update sov-rollup-starter with RollupTemplate * make create_native_storage fallible * change logging level * change logging level * cleanup * Fix lint
1 parent 9908444 commit 35379ab

File tree

22 files changed

+288
-309
lines changed

22 files changed

+288
-309
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/demo-rollup/src/celestia_rollup.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ impl RollupTemplate for CelestiaDemoRollup {
4242
fn create_genesis_config(
4343
&self,
4444
genesis_paths: &Self::GenesisPaths,
45+
_rollup_config: &RollupConfig<Self::DaConfig>,
4546
) -> <Self::NativeRuntime as sov_modules_stf_template::Runtime<
4647
Self::NativeContext,
4748
Self::DaSpec,
@@ -92,11 +93,11 @@ impl RollupTemplate for CelestiaDemoRollup {
9293
fn create_native_storage(
9394
&self,
9495
rollup_config: &sov_stf_runner::RollupConfig<Self::DaConfig>,
95-
) -> <Self::NativeContext as sov_modules_api::Spec>::Storage {
96+
) -> Result<<Self::NativeContext as sov_modules_api::Spec>::Storage, anyhow::Error> {
9697
let storage_config = StorageConfig {
9798
path: rollup_config.storage.path.clone(),
9899
};
99-
ProverStorage::with_config(storage_config).expect("Failed to open prover storage")
100+
ProverStorage::with_config(storage_config)
100101
}
101102

102103
fn create_rpc_methods(

examples/demo-rollup/src/main.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ use clap::Parser;
66
use demo_stf::genesis_config::GenesisPaths;
77
use sov_demo_rollup::{CelestiaDemoRollup, MockDemoRollup};
88
use sov_modules_rollup_template::{Rollup, RollupProverConfig, RollupTemplate};
9-
use sov_risc0_adapter::host::Risc0Host;
109
use sov_rollup_interface::mocks::MockDaConfig;
11-
use sov_rollup_interface::zk::ZkvmHost;
1210
use sov_stf_runner::{from_toml_path, RollupConfig};
1311
use tracing::log::debug;
1412
use tracing_subscriber::prelude::*;
@@ -46,7 +44,7 @@ async fn main() -> Result<(), anyhow::Error> {
4644

4745
match args.da_layer.as_str() {
4846
"mock" => {
49-
let rollup = new_rollup_with_mock_da::<Risc0Host<'static>>(
47+
let rollup = new_rollup_with_mock_da(
5048
&GenesisPaths::from_dir("../test-data/genesis/integration-tests"),
5149
rollup_config_path,
5250
Some(RollupProverConfig::Execute),
@@ -55,7 +53,7 @@ async fn main() -> Result<(), anyhow::Error> {
5553
rollup.run().await
5654
}
5755
"celestia" => {
58-
let rollup = new_rollup_with_celestia_da::<Risc0Host<'static>>(
56+
let rollup = new_rollup_with_celestia_da(
5957
&GenesisPaths::from_dir("../test-data/genesis/demo-tests"),
6058
rollup_config_path,
6159
Some(RollupProverConfig::Execute),
@@ -67,7 +65,7 @@ async fn main() -> Result<(), anyhow::Error> {
6765
}
6866
}
6967

70-
pub async fn new_rollup_with_celestia_da<Vm: ZkvmHost>(
68+
async fn new_rollup_with_celestia_da(
7169
genesis_paths: &GenesisPaths<PathBuf>,
7270
rollup_config_path: &str,
7371
prover_config: Option<RollupProverConfig>,
@@ -86,7 +84,7 @@ pub async fn new_rollup_with_celestia_da<Vm: ZkvmHost>(
8684
.await
8785
}
8886

89-
pub async fn new_rollup_with_mock_da<Vm: ZkvmHost>(
87+
async fn new_rollup_with_mock_da(
9088
genesis_paths: &GenesisPaths<PathBuf>,
9189
rollup_config_path: &str,
9290
prover_config: Option<RollupProverConfig>,

examples/demo-rollup/src/mock_rollup.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ use sov_modules_api::Spec;
99
use sov_modules_rollup_template::RollupTemplate;
1010
use sov_modules_stf_template::Runtime as RuntimeTrait;
1111
use sov_risc0_adapter::host::Risc0Host;
12-
use sov_rollup_interface::mocks::{
13-
MockAddress, MockDaConfig, MockDaService, MockDaSpec, MOCK_SEQUENCER_DA_ADDRESS,
14-
};
12+
use sov_rollup_interface::mocks::{MockDaConfig, MockDaService, MockDaSpec};
1513
use sov_rollup_interface::services::da::DaService;
1614
use sov_state::{ProverStorage, Storage, ZkStorage};
1715
use sov_stf_runner::RollupConfig;
@@ -41,15 +39,14 @@ impl RollupTemplate for MockDemoRollup {
4139
fn create_genesis_config(
4240
&self,
4341
genesis_paths: &Self::GenesisPaths,
42+
rollup_config: &RollupConfig<Self::DaConfig>,
4443
) -> <Self::NativeRuntime as RuntimeTrait<Self::NativeContext, Self::DaSpec>>::GenesisConfig
4544
{
46-
let sequencer_da_address = MockAddress::from(MOCK_SEQUENCER_DA_ADDRESS);
47-
4845
#[cfg(feature = "experimental")]
4946
let eth_signer = read_eth_tx_signers();
5047

5148
get_genesis_config(
52-
sequencer_da_address,
49+
rollup_config.da.sender_address,
5350
genesis_paths,
5451
#[cfg(feature = "experimental")]
5552
eth_signer.signers(),
@@ -58,9 +55,9 @@ impl RollupTemplate for MockDemoRollup {
5855

5956
async fn create_da_service(
6057
&self,
61-
_rollup_config: &RollupConfig<Self::DaConfig>,
58+
rollup_config: &RollupConfig<Self::DaConfig>,
6259
) -> Self::DaService {
63-
MockDaService::new(MockAddress::from(MOCK_SEQUENCER_DA_ADDRESS))
60+
MockDaService::new(rollup_config.da.sender_address)
6461
}
6562

6663
fn create_vm(&self) -> Self::Vm {
@@ -81,11 +78,11 @@ impl RollupTemplate for MockDemoRollup {
8178
fn create_native_storage(
8279
&self,
8380
rollup_config: &RollupConfig<Self::DaConfig>,
84-
) -> <Self::NativeContext as Spec>::Storage {
81+
) -> Result<<Self::NativeContext as sov_modules_api::Spec>::Storage, anyhow::Error> {
8582
let storage_config = StorageConfig {
8683
path: rollup_config.storage.path.clone(),
8784
};
88-
ProverStorage::with_config(storage_config).expect("Failed to open prover storage")
85+
ProverStorage::with_config(storage_config)
8986
}
9087

9188
fn create_rpc_methods(

examples/demo-rollup/tests/bank/mod.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,29 @@ use crate::test_helpers::start_rollup;
1818
const TOKEN_SALT: u64 = 0;
1919
const TOKEN_NAME: &str = "test_token";
2020

21+
#[tokio::test]
22+
async fn bank_tx_tests() -> Result<(), anyhow::Error> {
23+
let (port_tx, port_rx) = tokio::sync::oneshot::channel();
24+
25+
let rollup_task = tokio::spawn(async {
26+
start_rollup(
27+
port_tx,
28+
GenesisPaths::from_dir("../test-data/genesis/integration-tests"),
29+
Some(RollupProverConfig::Execute),
30+
)
31+
.await;
32+
});
33+
34+
let port = port_rx.await.unwrap();
35+
36+
// If the rollup throws an error, return it and stop trying to send the transaction
37+
tokio::select! {
38+
err = rollup_task => err?,
39+
res = send_test_create_token_tx(port) => res?,
40+
};
41+
Ok(())
42+
}
43+
2144
async fn send_test_create_token_tx(rpc_address: SocketAddr) -> Result<(), anyhow::Error> {
2245
let key = DefaultPrivateKey::generate();
2346
let user_address: <DefaultContext as Spec>::Address = key.to_address();
@@ -65,26 +88,3 @@ async fn send_test_create_token_tx(rpc_address: SocketAddr) -> Result<(), anyhow
6588
assert_eq!(balance_response.amount.unwrap_or_default(), 1000);
6689
Ok(())
6790
}
68-
69-
#[tokio::test]
70-
async fn bank_tx_tests() -> Result<(), anyhow::Error> {
71-
let (port_tx, port_rx) = tokio::sync::oneshot::channel();
72-
73-
let rollup_task = tokio::spawn(async {
74-
start_rollup(
75-
port_tx,
76-
GenesisPaths::from_dir("../test-data/genesis/integration-tests"),
77-
Some(RollupProverConfig::Execute),
78-
)
79-
.await;
80-
});
81-
82-
let port = port_rx.await.unwrap();
83-
84-
// If the rollup throws an error, return it and stop trying to send the transaction
85-
tokio::select! {
86-
err = rollup_task => err?,
87-
res = send_test_create_token_tx(port) => res?,
88-
};
89-
Ok(())
90-
}

module-system/sov-modules-rollup-template/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ pub trait RollupTemplate: Sized + Send + Sync {
5252
fn create_genesis_config(
5353
&self,
5454
genesis_paths: &Self::GenesisPaths,
55+
rollup_config: &RollupConfig<Self::DaConfig>,
5556
) -> <Self::NativeRuntime as RuntimeTrait<Self::NativeContext, Self::DaSpec>>::GenesisConfig;
5657

5758
/// Creates instance of DA Service.
@@ -70,7 +71,7 @@ pub trait RollupTemplate: Sized + Send + Sync {
7071
fn create_native_storage(
7172
&self,
7273
rollup_config: &RollupConfig<Self::DaConfig>,
73-
) -> <Self::NativeContext as Spec>::Storage;
74+
) -> Result<<Self::NativeContext as Spec>::Storage, anyhow::Error>;
7475

7576
/// Creates instance of ZkVm.
7677
fn create_vm(&self) -> Self::Vm;
@@ -95,7 +96,7 @@ pub trait RollupTemplate: Sized + Send + Sync {
9596
{
9697
let da_service = self.create_da_service(&rollup_config).await;
9798
let ledger_db = self.create_ledger_db(&rollup_config);
98-
let genesis_config = self.create_genesis_config(genesis_paths);
99+
let genesis_config = self.create_genesis_config(genesis_paths, &rollup_config);
99100

100101
let prover = prover_config.map(|pc| {
101102
configure_prover(
@@ -106,7 +107,7 @@ pub trait RollupTemplate: Sized + Send + Sync {
106107
)
107108
});
108109

109-
let storage = self.create_native_storage(&rollup_config);
110+
let storage = self.create_native_storage(&rollup_config)?;
110111

111112
let prev_root = ledger_db
112113
.get_head_slot()?

sov-rollup-starter/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rollup-starter-data

sov-rollup-starter/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ sov-accounts = { path = "../module-system/module-implementations/sov-accounts",
1818
sov-bank = { path = "../module-system/module-implementations/sov-bank", features = ["native"] }
1919
sov-ledger-rpc = { path = "../full-node/sov-ledger-rpc", features = ["server"] }
2020
sov-sequencer-registry = { path = "../module-system/module-implementations/sov-sequencer-registry", features = ["native"] }
21+
sov-modules-rollup-template = { path = "../module-system/sov-modules-rollup-template" }
2122
sov-modules-stf-template = { path = "../module-system/sov-modules-stf-template/", features = ["native"] }
2223
sov-stf-runner = { path = "../full-node/sov-stf-runner", features = ["native"] }
24+
async-trait = { workspace = true }
2325
borsh = { workspace = true }
2426
clap = { workspace = true }
2527
serde = { workspace = true }

sov-rollup-starter/provers/risc0/guest-mock/Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sov-rollup-starter/provers/risc0/guest-mock/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ resolver = "2"
1010
anyhow = "1.0.68"
1111
risc0-zkvm = { version = "0.18", default-features = false, features = ["std"] }
1212
risc0-zkvm-platform = "0.18"
13-
stf-starter = { path = "../../../stf" }
1413
sov-risc0-adapter = { path = "../../../../adapters/risc0" }
1514
sov-rollup-interface = { path = "../../../../rollup-interface", features = ["mocks"] }
1615

16+
stf-starter = { path = "../../../stf" }
17+
18+
sov-modules-api = { path = "../../../../module-system/sov-modules-api" }
19+
sov-state = { path = "../../../../module-system/sov-state" }
20+
sov-modules-stf-template = { path = "../../../../module-system/sov-modules-stf-template" }
21+
1722
[patch.crates-io]
1823
sha2 = { git = "https://github.com/risc0/RustCrypto-hashes", tag = "sha2/v0.10.6-risc0" }
1924

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
#![no_main]
22
//! This binary implements the verification logic for the rollup. This is the code that runs inside
33
//! of the zkvm in order to generate proofs for the rollup.
4+
5+
use sov_modules_api::default_context::ZkDefaultContext;
6+
use sov_modules_stf_template::AppTemplate;
7+
use sov_risc0_adapter::guest::Risc0Guest;
8+
use sov_rollup_interface::mocks::MockDaVerifier;
9+
use sov_state::ZkStorage;
10+
use stf_starter::runtime::Runtime;
11+
use stf_starter::AppVerifier;
12+
413
risc0_zkvm::guest::entry!(main);
514

6-
pub fn main() {}
15+
pub fn main() {
16+
let guest = Risc0Guest::new();
17+
let storage = ZkStorage::new();
18+
let app: AppTemplate<ZkDefaultContext, _, _, Runtime<_, _>> = AppTemplate::new(storage);
19+
20+
let mut stf_verifier = AppVerifier::new(app, MockDaVerifier {});
21+
22+
stf_verifier
23+
.run_block(guest)
24+
.expect("Prover must be honest");
25+
}

sov-rollup-starter/rollup_config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ sender_address = "01010101010101010101010101010101010101010101010101010101010101
33

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

88
# We define the rollup's genesis to occur at block number `start_height`. The rollup will ignore
99
# any blocks before this height

0 commit comments

Comments
 (0)