From 86fd8f746f3742100ad947a46a4c2cce5ce63e11 Mon Sep 17 00:00:00 2001 From: Richard Melkonian Date: Tue, 27 Feb 2024 15:57:13 +0000 Subject: [PATCH 1/9] create initial structure and deps --- Cargo.toml | 21 ++++++ protocol-units/data-availability/Cargo.toml | 11 ++- protocol-units/data-availability/src/main.rs | 74 +++++++++++++++++++- 3 files changed, 104 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1133acce0..2e96b1911 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,10 +19,12 @@ exclude = [ [workspace.dependencies] anyhow = "1.0" +clap = { version = "4.4.10", features = ["derive"] } # To try (experimental) std support, add `features = [ "std" ]` to risc0-zkvm risc0-zkvm = { version = "0.20.1", features = ["std"] } tracing-subscriber = { version = "0.3", features = ["env-filter"] } serde = "1.0" +tokio = "1.26.0" tempfile = "3.2.0" # Move dependencies @@ -34,6 +36,25 @@ 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" } # Always optimize; building and running the guest takes much longer without optimization. [profile.dev] diff --git a/protocol-units/data-availability/Cargo.toml b/protocol-units/data-availability/Cargo.toml index 1c77f6cd5..67a98c969 100644 --- a/protocol-units/data-availability/Cargo.toml +++ b/protocol-units/data-availability/Cargo.toml @@ -2,4 +2,13 @@ name = "data-availability" version = "0.1.0" edition = "2021" -description = "Data Availability adapters for the Movement SDK" \ No newline at end of file +description = "Data Availability adapters for the Movement SDK" + +[dependencies] +anyhow = { workspace = true } +clap = { workspace = true } +tokio = { workspace = true } +tracing-subscriber = { workspace = true } + +# Sovereign SDK dependencies +sov-rollup-interface = { workspace = true } \ No newline at end of file diff --git a/protocol-units/data-availability/src/main.rs b/protocol-units/data-availability/src/main.rs index e71fdf554..5300fbe72 100644 --- a/protocol-units/data-availability/src/main.rs +++ b/protocol-units/data-availability/src/main.rs @@ -1 +1,73 @@ -fn main() {} \ No newline at end of file +use std::env; +use std::str::FromStr; +use clap::{Parser, Subcommand, ValueEnum}; + +use tracing_subscriber::layer::SubscriberExt; +use tracing_subscriber::util::SubscriberInitExt; +use tracing_subscriber::{fmt, EnvFilter}; + +#[derive(Parser, Debug, Clone)] +#[clap(name = "data-availability", version, author, about)] +struct Args { + /// The data availability layer to use. + #[clap(short, long, help = "The data availability layer to use.")] + da_layer: SupportedDaLayer, + + /// The path to the rollup config. + #[clap(long, default_value = "mock_rollup_config.toml")] + rollup_config_path: String, +} + +#[derive(Debug, Subcommand, Clone, ValueEnum)] +enum SupportedDaLayer { + Mock, + Ethereum, +} + +#[tokio::main] +async fn main() -> Result<(), anyhow::Error> { + init_logging(); + Ok(()) +} + +pub fn init_logging() { + tracing_subscriber::registry() + .with(fmt::layer()) + .with( + EnvFilter::from_str( + &env::var("RUST_LOG") + .unwrap_or_else(|_| "debug,hyper=info,risc0_zkvm=info".to_string()), + ) + .unwrap(), + ) + .init(); + + let args = Args::parse(); + let rollup_config_path = args.rollup_config_path.as_str(); + + match args.da_layer { + SupportedDaLayer::Mock => { + let rollup = new_rollup_with_mock_da( + &GenesisPaths::from_dir("../test-data/genesis/demo-tests/mock"), + &BasicKernelGenesisPaths { + chain_state: "../test-data/genesis/demo-tests/mock/chain_state.json".into(), + }, + rollup_config_path, + RollupProverConfig::Execute, + ) + .await?; + rollup.run().await?; + } + SupportedDaLayer::Ethereum => { + } + } +} + +async fn new_rollup_with_mock_da( + rt_genesis_paths: &GenesisPaths, + kernel_genesis_paths: &BasicKernelGenesisPaths, + rollup_config_path: &str, + prover_config: RollupProverConfig, +) -> Result, anyhow::Error> { + +} From e09c2e1092bb926bf84cbc13e296206ce1b4f995 Mon Sep 17 00:00:00 2001 From: Richard Melkonian Date: Tue, 27 Feb 2024 16:35:33 +0000 Subject: [PATCH 2/9] create da sub-packages --- .vscode/settings.json | 3 +++ Cargo.toml | 3 ++- protocol-units/data-availability/Cargo.toml | 17 ++++++++--------- .../data-availability/rollup/Cargo.toml | 11 +++++++++++ .../data-availability/{ => rollup}/src/main.rs | 0 protocol-units/data-availability/stf/Cargo.toml | 6 ++++++ .../data-availability/stf/src/main.rs | 1 + protocol-units/zkfp/host/Cargo.toml | 2 +- 8 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 protocol-units/data-availability/rollup/Cargo.toml rename protocol-units/data-availability/{ => rollup}/src/main.rs (100%) create mode 100644 protocol-units/data-availability/stf/Cargo.toml create mode 100644 protocol-units/data-availability/stf/src/main.rs diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..4d9636b55 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "rust-analyzer.showUnlinkedFileNotification": false +} \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 2e96b1911..b97efaa4d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/protocol-units/data-availability/Cargo.toml b/protocol-units/data-availability/Cargo.toml index 67a98c969..f004d3d0c 100644 --- a/protocol-units/data-availability/Cargo.toml +++ b/protocol-units/data-availability/Cargo.toml @@ -1,14 +1,13 @@ [package] -name = "data-availability" +name = "data-availbility" version = "0.1.0" edition = "2021" -description = "Data Availability adapters for the Movement SDK" +description = "Data Availability modules for Movement SDK" -[dependencies] -anyhow = { workspace = true } -clap = { workspace = true } -tokio = { workspace = true } -tracing-subscriber = { workspace = true } +[[bin]] +name = "rollup" +path = "rollup/src/main.rs" -# Sovereign SDK dependencies -sov-rollup-interface = { workspace = true } \ No newline at end of file +[[bin]] +name = "stf" +path = "stf/src/main.rs" diff --git a/protocol-units/data-availability/rollup/Cargo.toml b/protocol-units/data-availability/rollup/Cargo.toml new file mode 100644 index 000000000..38b9194c3 --- /dev/null +++ b/protocol-units/data-availability/rollup/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "rollup" +version = "0.1.0" +edition = "2021" +description = "Sovereign Labs Rollup" + +[dependencies] +anyhow = { workspace = true } +clap = { workspace = true } +tokio = { workspace = true } +tracing-subscriber = { workspace = true } diff --git a/protocol-units/data-availability/src/main.rs b/protocol-units/data-availability/rollup/src/main.rs similarity index 100% rename from protocol-units/data-availability/src/main.rs rename to protocol-units/data-availability/rollup/src/main.rs diff --git a/protocol-units/data-availability/stf/Cargo.toml b/protocol-units/data-availability/stf/Cargo.toml new file mode 100644 index 000000000..61541ee8a --- /dev/null +++ b/protocol-units/data-availability/stf/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "stf" +version = "0.1.0" +edition = "2021" +description = "State Transition Function (STF) implemented with Sovereign Labs for Movement SDK" + diff --git a/protocol-units/data-availability/stf/src/main.rs b/protocol-units/data-availability/stf/src/main.rs new file mode 100644 index 000000000..0ab1871b4 --- /dev/null +++ b/protocol-units/data-availability/stf/src/main.rs @@ -0,0 +1 @@ +fn main () {} \ No newline at end of file diff --git a/protocol-units/zkfp/host/Cargo.toml b/protocol-units/zkfp/host/Cargo.toml index e5b489713..317c81450 100644 --- a/protocol-units/zkfp/host/Cargo.toml +++ b/protocol-units/zkfp/host/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "host" -version = "0.0.0" +version = "0.1.0" edition = "2021" [dependencies] From 125a9d39babab5690c2ae3e7fdad19bfaadb2e9b Mon Sep 17 00:00:00 2001 From: Richard Melkonian Date: Tue, 27 Feb 2024 16:44:00 +0000 Subject: [PATCH 3/9] add test-data json --- .../test-data/genesis/celestia/accounts.json | 3 +++ .../test-data/genesis/celestia/bank.json | 17 +++++++++++++++++ .../test-data/genesis/celestia/chain_state.json | 7 +++++++ .../genesis/celestia/sequencer_registry.json | 9 +++++++++ .../test-data/genesis/mock/accounts.json | 0 .../test-data/genesis/mock/bank.json | 0 .../test-data/genesis/mock/chain_state.json | 7 +++++++ .../genesis/mock/sequencer_registry.json | 9 +++++++++ .../keys/token_deployer_private_key.json | 9 +++++++++ .../test-data/keys/tx_signer_private_key.json | 9 +++++++++ .../test-data/requests/create_token.json | 12 ++++++++++++ .../test-data/requests/transfer.json | 9 +++++++++ 12 files changed, 91 insertions(+) create mode 100644 protocol-units/data-availability/test-data/genesis/celestia/accounts.json create mode 100644 protocol-units/data-availability/test-data/genesis/celestia/bank.json create mode 100644 protocol-units/data-availability/test-data/genesis/celestia/chain_state.json create mode 100644 protocol-units/data-availability/test-data/genesis/celestia/sequencer_registry.json create mode 100644 protocol-units/data-availability/test-data/genesis/mock/accounts.json create mode 100644 protocol-units/data-availability/test-data/genesis/mock/bank.json create mode 100644 protocol-units/data-availability/test-data/genesis/mock/chain_state.json create mode 100644 protocol-units/data-availability/test-data/genesis/mock/sequencer_registry.json create mode 100644 protocol-units/data-availability/test-data/keys/token_deployer_private_key.json create mode 100644 protocol-units/data-availability/test-data/keys/tx_signer_private_key.json create mode 100644 protocol-units/data-availability/test-data/requests/create_token.json create mode 100644 protocol-units/data-availability/test-data/requests/transfer.json diff --git a/protocol-units/data-availability/test-data/genesis/celestia/accounts.json b/protocol-units/data-availability/test-data/genesis/celestia/accounts.json new file mode 100644 index 000000000..e89f762fc --- /dev/null +++ b/protocol-units/data-availability/test-data/genesis/celestia/accounts.json @@ -0,0 +1,3 @@ +{ + "pub_keys": [] +} \ No newline at end of file diff --git a/protocol-units/data-availability/test-data/genesis/celestia/bank.json b/protocol-units/data-availability/test-data/genesis/celestia/bank.json new file mode 100644 index 000000000..ba3101944 --- /dev/null +++ b/protocol-units/data-availability/test-data/genesis/celestia/bank.json @@ -0,0 +1,17 @@ +{ + "tokens": [ + { + "token_name": "sov-demo-token", + "address_and_balances": [ + [ + "sov1l6n2cku82yfqld30lanm2nfw43n2auc8clw7r5u5m6s7p8jrm4zqrr8r94", + 100000000 + ] + ], + "authorized_minters": [ + "sov1l6n2cku82yfqld30lanm2nfw43n2auc8clw7r5u5m6s7p8jrm4zqrr8r94" + ], + "salt": 0 + } + ] + } \ No newline at end of file diff --git a/protocol-units/data-availability/test-data/genesis/celestia/chain_state.json b/protocol-units/data-availability/test-data/genesis/celestia/chain_state.json new file mode 100644 index 000000000..97c8a267e --- /dev/null +++ b/protocol-units/data-availability/test-data/genesis/celestia/chain_state.json @@ -0,0 +1,7 @@ +{ + "initial_slot_height": 0, + "current_time": { + "secs": 0, + "nanos": 0 + } +} \ No newline at end of file diff --git a/protocol-units/data-availability/test-data/genesis/celestia/sequencer_registry.json b/protocol-units/data-availability/test-data/genesis/celestia/sequencer_registry.json new file mode 100644 index 000000000..f25583046 --- /dev/null +++ b/protocol-units/data-availability/test-data/genesis/celestia/sequencer_registry.json @@ -0,0 +1,9 @@ +{ + "seq_rollup_address": "sov1l6n2cku82yfqld30lanm2nfw43n2auc8clw7r5u5m6s7p8jrm4zqrr8r94", + "seq_da_address": "celestia1a68m2l85zn5xh0l07clk4rfvnezhywc53g8x7s", + "coins_to_lock": { + "amount": 50, + "token_address": "sov1zsnx7n2wjvtkr0ttscfgt06pjca3v2e6stxeu49qwynavmk7a8xqlxkkjp" + }, + "is_preferred_sequencer": true + } \ No newline at end of file diff --git a/protocol-units/data-availability/test-data/genesis/mock/accounts.json b/protocol-units/data-availability/test-data/genesis/mock/accounts.json new file mode 100644 index 000000000..e69de29bb diff --git a/protocol-units/data-availability/test-data/genesis/mock/bank.json b/protocol-units/data-availability/test-data/genesis/mock/bank.json new file mode 100644 index 000000000..e69de29bb diff --git a/protocol-units/data-availability/test-data/genesis/mock/chain_state.json b/protocol-units/data-availability/test-data/genesis/mock/chain_state.json new file mode 100644 index 000000000..97c8a267e --- /dev/null +++ b/protocol-units/data-availability/test-data/genesis/mock/chain_state.json @@ -0,0 +1,7 @@ +{ + "initial_slot_height": 0, + "current_time": { + "secs": 0, + "nanos": 0 + } +} \ No newline at end of file diff --git a/protocol-units/data-availability/test-data/genesis/mock/sequencer_registry.json b/protocol-units/data-availability/test-data/genesis/mock/sequencer_registry.json new file mode 100644 index 000000000..c8fb0cc85 --- /dev/null +++ b/protocol-units/data-availability/test-data/genesis/mock/sequencer_registry.json @@ -0,0 +1,9 @@ +{ + "seq_rollup_address": "sov1l6n2cku82yfqld30lanm2nfw43n2auc8clw7r5u5m6s7p8jrm4zqrr8r94", + "seq_da_address": "0000000000000000000000000000000000000000000000000000000000000000", + "coins_to_lock": { + "amount": 50, + "token_address": "sov1zsnx7n2wjvtkr0ttscfgt06pjca3v2e6stxeu49qwynavmk7a8xqlxkkjp" + }, + "is_preferred_sequencer": true +} \ No newline at end of file diff --git a/protocol-units/data-availability/test-data/keys/token_deployer_private_key.json b/protocol-units/data-availability/test-data/keys/token_deployer_private_key.json new file mode 100644 index 000000000..c8fb0cc85 --- /dev/null +++ b/protocol-units/data-availability/test-data/keys/token_deployer_private_key.json @@ -0,0 +1,9 @@ +{ + "seq_rollup_address": "sov1l6n2cku82yfqld30lanm2nfw43n2auc8clw7r5u5m6s7p8jrm4zqrr8r94", + "seq_da_address": "0000000000000000000000000000000000000000000000000000000000000000", + "coins_to_lock": { + "amount": 50, + "token_address": "sov1zsnx7n2wjvtkr0ttscfgt06pjca3v2e6stxeu49qwynavmk7a8xqlxkkjp" + }, + "is_preferred_sequencer": true +} \ No newline at end of file diff --git a/protocol-units/data-availability/test-data/keys/tx_signer_private_key.json b/protocol-units/data-availability/test-data/keys/tx_signer_private_key.json new file mode 100644 index 000000000..7ba16cd3c --- /dev/null +++ b/protocol-units/data-availability/test-data/keys/tx_signer_private_key.json @@ -0,0 +1,9 @@ +{ + "private_key": { + "key_pair": [ + 39, 195, 119, 77, 82, 231, 30, 162, 102, 169, 197, 37, 108, 217, 139, 154, + 230, 126, 98, 242, 174, 94, 211, 74, 102, 141, 184, 234, 168, 62, 27, 172 + ] + }, + "address": "sov1dnhqk4mdsj2kwv4xymt8a624xuahfx8906j9usdkx7ensfghndkq8p33f7" +} \ No newline at end of file diff --git a/protocol-units/data-availability/test-data/requests/create_token.json b/protocol-units/data-availability/test-data/requests/create_token.json new file mode 100644 index 000000000..fb6e8e7aa --- /dev/null +++ b/protocol-units/data-availability/test-data/requests/create_token.json @@ -0,0 +1,12 @@ +{ + "CreateToken": { + "salt": 11, + "token_name": "sov-test-token", + "initial_balance": 1000, + "minter_address": "sov15vspj48hpttzyvxu8kzq5klhvaczcpyxn6z6k0hwpwtzs4a6wkvqwr57gc", + "authorized_minters": [ + "sov1l6n2cku82yfqld30lanm2nfw43n2auc8clw7r5u5m6s7p8jrm4zqrr8r94", + "sov15vspj48hpttzyvxu8kzq5klhvaczcpyxn6z6k0hwpwtzs4a6wkvqwr57gc" + ] + } +} \ No newline at end of file diff --git a/protocol-units/data-availability/test-data/requests/transfer.json b/protocol-units/data-availability/test-data/requests/transfer.json new file mode 100644 index 000000000..234a3684b --- /dev/null +++ b/protocol-units/data-availability/test-data/requests/transfer.json @@ -0,0 +1,9 @@ +{ + "Transfer": { + "to": "sov1l6n2cku82yfqld30lanm2nfw43n2auc8clw7r5u5m6s7p8jrm4zqklh0qh", + "coins": { + "amount": 200, + "token_address": "sov1zdwj8thgev2u3yyrrlekmvtsz4av4tp3m7dm5mx5peejnesga27svq9m72" + } + } +} \ No newline at end of file From cc691c20aaace2ccb826c4c97e091a59479a84ea Mon Sep 17 00:00:00 2001 From: Richard Melkonian Date: Tue, 27 Feb 2024 18:11:26 +0000 Subject: [PATCH 4/9] manicure deps --- Cargo.toml | 1 + .../data-availability/rollup/Cargo.toml | 12 +++ .../rollup/src/celestia_rollup.rs | 36 +++++++++ .../data-availability/rollup/src/lib.rs | 5 ++ .../data-availability/rollup/src/main.rs | 73 ------------------- .../rollup/src/mock_rollup.rs | 19 +++++ 6 files changed, 73 insertions(+), 73 deletions(-) create mode 100644 protocol-units/data-availability/rollup/src/celestia_rollup.rs create mode 100644 protocol-units/data-availability/rollup/src/lib.rs delete mode 100644 protocol-units/data-availability/rollup/src/main.rs create mode 100644 protocol-units/data-availability/rollup/src/mock_rollup.rs diff --git a/Cargo.toml b/Cargo.toml index b97efaa4d..67a5cfa97 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ exclude = [ [workspace.dependencies] anyhow = "1.0" +async-trait = "0.1.77" clap = { version = "4.4.10", features = ["derive"] } # To try (experimental) std support, add `features = [ "std" ]` to risc0-zkvm risc0-zkvm = { version = "0.20.1", features = ["std"] } diff --git a/protocol-units/data-availability/rollup/Cargo.toml b/protocol-units/data-availability/rollup/Cargo.toml index 38b9194c3..dc5dd24e0 100644 --- a/protocol-units/data-availability/rollup/Cargo.toml +++ b/protocol-units/data-availability/rollup/Cargo.toml @@ -5,7 +5,19 @@ edition = "2021" description = "Sovereign Labs Rollup" [dependencies] +async-trait = { workspace = true } anyhow = { workspace = true } clap = { workspace = true } tokio = { workspace = true } tracing-subscriber = { workspace = true } + +# Sovereign Labs dependencies +sov-celestia-adapter = { workspace = true, features = ["native"], optional = true} +sov-modules-api = { workspace = true } +sov-modules-rollup-blueprint = { workspace = true } +sov-modules-stf-blueprint = { workspace = true } +sov-risc0-adapter = { workspace = true } +sov-rollup-interface = { workspace = true } +sov-state = { workspace = true } +sov-stf-runner = { workspace = true } +stf = { path = "../stf" } diff --git a/protocol-units/data-availability/rollup/src/celestia_rollup.rs b/protocol-units/data-availability/rollup/src/celestia_rollup.rs new file mode 100644 index 000000000..55eb6ea08 --- /dev/null +++ b/protocol-units/data-availability/rollup/src/celestia_rollup.rs @@ -0,0 +1,36 @@ +use async_trait::async_trait; +use sov_celestia_adapter::types::Namespace; +use sov_celestia_adapter::verifier::{CelestiaSpec, CelestiaVerifier, RollupParams}; +use sov_celestia_adapter::{CelestiaConfig, CelestiaService}; +use sov_modules_api::default_context::{DefaultContext, ZkDefaultContext}; +use sov_modules_api::Address; +use sov_modules_api::Spec; +use sov_modules_rollup_blueprint::RollupBlueprint; +use sov_modules_stf_blueprint::kernels::basic::BasicKernel; +use sov_modules_stf_blueprint::StfBlueprint; +use sov_prover_storage_manager::ProverStorageManager; +use sov_risc0_adapter::host::Risc0Host; +use sov_rollup_interface::zk::ZkvmHost; +use sov_state::config::Config as StorageConfig; +use sov_state::Storage; +use sov_state::{DefaultStorageSpec, ZkStorage}; +use sov_stf_runner::ParallelProverService; +use sov_stf_runner::RollupConfig; +use sov_stf_runner::RollupProverConfig; +use stf::Runtime; + +/// The namespace for the rollup on Celestia. +const ROLLUP_NAMESPACE: Namespace = Namespace::const_v0(b"sov-celest"); + +/// The rollup stores the zk proofs in the namespace b"sov-test-p" on Celestia. +const ROLLUP_PROOF_NAMESPACE: Namespace = Namespace::const_v0(b"sov-test-p"); + +/// Rollup with [`CelestiaDaService`]. +pub struct CelestiaRollup {} + +/// This is the place, where all the rollup components come together and +/// they can be easily swapped with alternative implementations as needed. +#[async_trait] +impl RollupBlueprint for CelestiaRollup { + +} \ No newline at end of file diff --git a/protocol-units/data-availability/rollup/src/lib.rs b/protocol-units/data-availability/rollup/src/lib.rs new file mode 100644 index 000000000..701336a19 --- /dev/null +++ b/protocol-units/data-availability/rollup/src/lib.rs @@ -0,0 +1,5 @@ +//#[cfg(feature = "mock_da")] +pub mod mock_rollup; + +//#[cfg(feature = "celestia_da")] +pub mod celestia_rollup; \ No newline at end of file diff --git a/protocol-units/data-availability/rollup/src/main.rs b/protocol-units/data-availability/rollup/src/main.rs deleted file mode 100644 index 5300fbe72..000000000 --- a/protocol-units/data-availability/rollup/src/main.rs +++ /dev/null @@ -1,73 +0,0 @@ -use std::env; -use std::str::FromStr; -use clap::{Parser, Subcommand, ValueEnum}; - -use tracing_subscriber::layer::SubscriberExt; -use tracing_subscriber::util::SubscriberInitExt; -use tracing_subscriber::{fmt, EnvFilter}; - -#[derive(Parser, Debug, Clone)] -#[clap(name = "data-availability", version, author, about)] -struct Args { - /// The data availability layer to use. - #[clap(short, long, help = "The data availability layer to use.")] - da_layer: SupportedDaLayer, - - /// The path to the rollup config. - #[clap(long, default_value = "mock_rollup_config.toml")] - rollup_config_path: String, -} - -#[derive(Debug, Subcommand, Clone, ValueEnum)] -enum SupportedDaLayer { - Mock, - Ethereum, -} - -#[tokio::main] -async fn main() -> Result<(), anyhow::Error> { - init_logging(); - Ok(()) -} - -pub fn init_logging() { - tracing_subscriber::registry() - .with(fmt::layer()) - .with( - EnvFilter::from_str( - &env::var("RUST_LOG") - .unwrap_or_else(|_| "debug,hyper=info,risc0_zkvm=info".to_string()), - ) - .unwrap(), - ) - .init(); - - let args = Args::parse(); - let rollup_config_path = args.rollup_config_path.as_str(); - - match args.da_layer { - SupportedDaLayer::Mock => { - let rollup = new_rollup_with_mock_da( - &GenesisPaths::from_dir("../test-data/genesis/demo-tests/mock"), - &BasicKernelGenesisPaths { - chain_state: "../test-data/genesis/demo-tests/mock/chain_state.json".into(), - }, - rollup_config_path, - RollupProverConfig::Execute, - ) - .await?; - rollup.run().await?; - } - SupportedDaLayer::Ethereum => { - } - } -} - -async fn new_rollup_with_mock_da( - rt_genesis_paths: &GenesisPaths, - kernel_genesis_paths: &BasicKernelGenesisPaths, - rollup_config_path: &str, - prover_config: RollupProverConfig, -) -> Result, anyhow::Error> { - -} diff --git a/protocol-units/data-availability/rollup/src/mock_rollup.rs b/protocol-units/data-availability/rollup/src/mock_rollup.rs new file mode 100644 index 000000000..e56ba9ad3 --- /dev/null +++ b/protocol-units/data-availability/rollup/src/mock_rollup.rs @@ -0,0 +1,19 @@ +use async_trait::async_trait; +use sov_db::ledger_db::LedgerDB; +use sov_mock_da::{MockDaConfig, MockDaService, MockDaSpec}; +use sov_modules_api::default_context::{DefaultContext, ZkDefaultContext}; +use sov_modules_api::Address; +use sov_modules_api::Spec; +use sov_modules_rollup_blueprint::RollupBlueprint; +use sov_modules_stf_blueprint::kernels::basic::BasicKernel; +use sov_modules_stf_blueprint::StfBlueprint; +use sov_prover_storage_manager::ProverStorageManager; +use sov_risc0_adapter::host::Risc0Host; +use sov_rollup_interface::zk::ZkvmHost; +use sov_state::config::Config as StorageConfig; +use sov_state::Storage; +use sov_state::{DefaultStorageSpec, ZkStorage}; +use sov_stf_runner::ParallelProverService; +use sov_stf_runner::RollupConfig; +use sov_stf_runner::RollupProverConfig; +use stf_starter::Runtime; \ No newline at end of file From 5c1d65b0ac76b8acc824c5f669ab977e30e4bfb7 Mon Sep 17 00:00:00 2001 From: Richard Melkonian Date: Wed, 28 Feb 2024 14:31:32 +0000 Subject: [PATCH 5/9] add runtime --- Cargo.toml | 6 +- .../data-availability/stf/Cargo.toml | 13 +++ .../stf/src/genesis_config.rs | 37 ++++++++ .../data-availability/stf/src/lib.rs | 6 ++ .../data-availability/stf/src/main.rs | 1 - .../data-availability/stf/src/runtime.rs | 88 +++++++++++++++++++ 6 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 protocol-units/data-availability/stf/src/genesis_config.rs create mode 100644 protocol-units/data-availability/stf/src/lib.rs delete mode 100644 protocol-units/data-availability/stf/src/main.rs create mode 100644 protocol-units/data-availability/stf/src/runtime.rs diff --git a/Cargo.toml b/Cargo.toml index 67a5cfa97..fac60c7d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,14 +21,18 @@ 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-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" } diff --git a/protocol-units/data-availability/stf/Cargo.toml b/protocol-units/data-availability/stf/Cargo.toml index 61541ee8a..136162842 100644 --- a/protocol-units/data-availability/stf/Cargo.toml +++ b/protocol-units/data-availability/stf/Cargo.toml @@ -4,3 +4,16 @@ version = "0.1.0" edition = "2021" description = "State Transition Function (STF) implemented with Sovereign Labs for Movement SDK" +[dependencies] +anyhow = { workspace = true } +jsonrpsee = { workspace = true } +borsh = { workspace = true } +serde = { workspace = true } + +#Sovereign Labs Dependencies +sov-accounts = { workspace = true } +sov-bank = { workspace = true } +sov-sequencer-registry = { workspace = true } +sov-modules-api = { workspace = true } +sov-modules-stf-blueprint = { workspace = true } + diff --git a/protocol-units/data-availability/stf/src/genesis_config.rs b/protocol-units/data-availability/stf/src/genesis_config.rs new file mode 100644 index 000000000..3b09b697d --- /dev/null +++ b/protocol-units/data-availability/stf/src/genesis_config.rs @@ -0,0 +1,37 @@ +use anyhow::{bail, Context as _}; +use sov_modules_api::{Context, DaSpec}; +use sov_modules_stf_blueprint::Runtime as RuntimeTrait; +use std::path::{Path, PathBuf}; + +use crate::Runtime; + +/// Paths to genesis files +pub struct GenesisPaths { + /// Accounts genesis path + pub accounts_genesis_path: PathBuf, + /// Bank genesis path + pub bank_genesis_path: PathBuf, + /// Sequence genesis path + pub sequence_genesis_path: PathBuf, +} + +impl GenesisPaths { + /// Creates a new [`GenesisPaths`] from the files contained in the given + /// directory. + /// + /// Take a look at the contents of the `test_data` directory to see the + /// expected files. + pub fn from_dir(dir: impl AsRef) -> Self { + Self { + accounts_genesis_path: dir.as_ref().join("accounts_genesis.json"), + bank_genesis_path: dir.as_ref().join("bank_genesis.json"), + sequence_genesis_path: dir.as_ref().join("sequence_genesis.json"), + } + } +} + +/// Creates genesis configuration. +pub(crate) fn get_genesis_config( + genesis_paths: &GenesisPaths, +) -> Result< as RuntimeTrait>::GenesisConfig, anyhow::Error> { +} diff --git a/protocol-units/data-availability/stf/src/lib.rs b/protocol-units/data-availability/stf/src/lib.rs new file mode 100644 index 000000000..886c8a58b --- /dev/null +++ b/protocol-units/data-availability/stf/src/lib.rs @@ -0,0 +1,6 @@ +//! The rollup State Transition Function. + +//#[cfg(feature = "native")] +pub mod genesis_config; +//mod hooks; +pub mod runtime; \ No newline at end of file diff --git a/protocol-units/data-availability/stf/src/main.rs b/protocol-units/data-availability/stf/src/main.rs deleted file mode 100644 index 0ab1871b4..000000000 --- a/protocol-units/data-availability/stf/src/main.rs +++ /dev/null @@ -1 +0,0 @@ -fn main () {} \ No newline at end of file diff --git a/protocol-units/data-availability/stf/src/runtime.rs b/protocol-units/data-availability/stf/src/runtime.rs new file mode 100644 index 000000000..59da98b19 --- /dev/null +++ b/protocol-units/data-availability/stf/src/runtime.rs @@ -0,0 +1,88 @@ +#![allow(unused_doc_comments)] +//! This module implements the core logic of the rollup. +//! To add new functionality to your rollup: +//! 1. Add a new module dependency to your `Cargo.toml` file +//! 2. Add the module to the `Runtime` below +//! 3. Update `genesis.json` with any additional data required by your new module + +//#[cfg(feature = "native")] +pub use sov_accounts::{AccountsRpcImpl, AccountsRpcServer}; +//#[cfg(feature = "native")] +pub use sov_bank::{BankRpcImpl, BankRpcServer}; +use sov_modules_api::macros::DefaultRuntime; +//#[cfg(feature = "native")] +use sov_modules_api::Spec; +use sov_modules_api::{Context, DaSpec, DispatchCall, Genesis, MessageCodec}; +//#[cfg(feature = "native")] +pub use sov_sequencer_registry::{SequencerRegistryRpcImpl, SequencerRegistryRpcServer}; + +//#[cfg(feature = "native")] +use crate::genesis_config::{get_genesis_config, GenesisPaths}; + +/// The runtime defines the logic of the rollup. +/// +/// At a high level, the rollup node receives serialized "call messages" from the DA layer and executes them as atomic transactions. +/// Upon reception, the message is deserialized and forwarded to an appropriate module. +/// +/// The module-specific logic is implemented by module creators, but all the glue code responsible for message +/// deserialization/forwarding is handled by a rollup `runtime`. +/// +/// In order to define the runtime we need to specify all the modules supported by our rollup (see the `Runtime` struct bellow) +/// +/// The `Runtime` defines: +/// - how the rollup modules are wired up together. +/// - how the state of the rollup is initialized. +/// - how messages are dispatched to appropriate modules. +/// +/// Runtime lifecycle: +/// +/// 1. Initialization: +/// When a rollup is deployed for the first time, it needs to set its genesis state. +/// The `#[derive(Genesis)` macro will generate `Runtime::genesis(config)` method which returns +/// `Storage` with the initialized state. +/// +/// 2. Calls: +/// The `Module` interface defines a `call` method which accepts a module-defined type and triggers the specific `module logic.` +/// In general, the point of a call is to change the module state, but if the call throws an error, +/// no state is updated (the transaction is reverted). +/// +/// `#[derive(MessageCodec)` adds deserialization capabilities to the `Runtime` (by implementing the `decode_call` method). +/// `Runtime::decode_call` accepts a serialized call message and returns a type that implements the `DispatchCall` trait. +/// The `DispatchCall` implementation (derived by a macro) forwards the message to the appropriate module and executes its `call` method. +#[cfg_attr( + feature = "native", + derive(sov_modules_api::macros::CliWallet), + sov_modules_api::macros::expose_rpc +)] +#[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] +#[serialization(borsh::BorshDeserialize, borsh::BorshSerialize)] +#[cfg_attr(feature = "serde", serialization(serde::Serialize, serde::Deserialize))] +pub struct Runtime { + /// The `accounts` module is responsible for managing user accounts and their nonces. + pub accounts: sov_accounts::Accounts, + /// The `bank` module is responsible for minting, transferring and burning tokens. + pub bank: sov_bank::Bank, + /// The sequencer reqistry module is responsible for authorizing users to sequencer rollup transactions. + pub sequencer_registry: sov_sequencer_registry::SequencerRegistry, +} + +impl sov_modules_stf_blueprint::Runtime for Runtime +where + C: Context, + Da: DaSpec, +{ + type GenesisConfig = GenesisConfig; + + //# [cfg(feature = "native")] + fn rpc_methods(storage: ::Storage) -> jsonrpsee::RpcModule<()> { + get_rpc_methods::(storage.clone()) + } + + //# [cfg(feature = "native")] + fn genesis_config( + genesis_paths: &Self::GenesisPaths, + ) -> Result { + crate::genesis_config::get_genesis_config(genesis_paths) + } +} + From 48756442da5e6870f2e443b7d4bc6f0a403e9b16 Mon Sep 17 00:00:00 2001 From: Richard Melkonian Date: Wed, 28 Feb 2024 15:11:55 +0000 Subject: [PATCH 6/9] experimental runtime --- .../data-availability/stf/Cargo.toml | 1 + .../data-availability/stf/src/runtime.rs | 20 +++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/protocol-units/data-availability/stf/Cargo.toml b/protocol-units/data-availability/stf/Cargo.toml index 136162842..cbf301309 100644 --- a/protocol-units/data-availability/stf/Cargo.toml +++ b/protocol-units/data-availability/stf/Cargo.toml @@ -17,3 +17,4 @@ sov-sequencer-registry = { workspace = true } sov-modules-api = { workspace = true } sov-modules-stf-blueprint = { workspace = true } + diff --git a/protocol-units/data-availability/stf/src/runtime.rs b/protocol-units/data-availability/stf/src/runtime.rs index 59da98b19..872c9a8c2 100644 --- a/protocol-units/data-availability/stf/src/runtime.rs +++ b/protocol-units/data-availability/stf/src/runtime.rs @@ -9,7 +9,7 @@ pub use sov_accounts::{AccountsRpcImpl, AccountsRpcServer}; //#[cfg(feature = "native")] pub use sov_bank::{BankRpcImpl, BankRpcServer}; -use sov_modules_api::macros::DefaultRuntime; +use sov_modules_api::macros::{DefaultRuntime, CliWallet}; //#[cfg(feature = "native")] use sov_modules_api::Spec; use sov_modules_api::{Context, DaSpec, DispatchCall, Genesis, MessageCodec}; @@ -49,14 +49,18 @@ use crate::genesis_config::{get_genesis_config, GenesisPaths}; /// `#[derive(MessageCodec)` adds deserialization capabilities to the `Runtime` (by implementing the `decode_call` method). /// `Runtime::decode_call` accepts a serialized call message and returns a type that implements the `DispatchCall` trait. /// The `DispatchCall` implementation (derived by a macro) forwards the message to the appropriate module and executes its `call` method. -#[cfg_attr( - feature = "native", - derive(sov_modules_api::macros::CliWallet), - sov_modules_api::macros::expose_rpc +#[derive( + CliWallet, + Genesis, + DispatchCall, + MessageCodec, + DefaultRuntime, + borsh::BorshDeserialize, + borsh::BorshSerialize, + serde::Serialize, + serde::Deserialize )] -#[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] -#[serialization(borsh::BorshDeserialize, borsh::BorshSerialize)] -#[cfg_attr(feature = "serde", serialization(serde::Serialize, serde::Deserialize))] +#[sov_modules_api::macros::expose_rpc] pub struct Runtime { /// The `accounts` module is responsible for managing user accounts and their nonces. pub accounts: sov_accounts::Accounts, From 51fb46f1691d6948e2612183cdaae98e447581d3 Mon Sep 17 00:00:00 2001 From: Richard Melkonian Date: Mon, 4 Mar 2024 14:01:58 +0000 Subject: [PATCH 7/9] add stf hooks --- Cargo.toml | 1 + protocol-units/data-availability/Cargo.toml | 13 -- .../data-availability/rollup/Cargo.toml | 56 ++++++-- .../rollup/src/celestia_rollup.rs | 6 +- .../data-availability/rollup/src/lib.rs | 4 +- .../rollup/src/mock_rollup.rs | 2 +- .../data-availability/stf/Cargo.toml | 50 +++++-- .../stf/src/genesis_config.rs | 67 ++++++++-- .../data-availability/stf/src/hooks.rs | 123 ++++++++++++++++++ .../data-availability/stf/src/lib.rs | 18 ++- .../data-availability/stf/src/runtime.rs | 55 ++++---- 11 files changed, 314 insertions(+), 81 deletions(-) delete mode 100644 protocol-units/data-availability/Cargo.toml create mode 100644 protocol-units/data-availability/stf/src/hooks.rs diff --git a/Cargo.toml b/Cargo.toml index fac60c7d1..e7a44bc62 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ 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 = { version = "1.0.192", features = ["derive", "rc"] } serde_json = "1.0" diff --git a/protocol-units/data-availability/Cargo.toml b/protocol-units/data-availability/Cargo.toml deleted file mode 100644 index f004d3d0c..000000000 --- a/protocol-units/data-availability/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "data-availbility" -version = "0.1.0" -edition = "2021" -description = "Data Availability modules for Movement SDK" - -[[bin]] -name = "rollup" -path = "rollup/src/main.rs" - -[[bin]] -name = "stf" -path = "stf/src/main.rs" diff --git a/protocol-units/data-availability/rollup/Cargo.toml b/protocol-units/data-availability/rollup/Cargo.toml index dc5dd24e0..6ad6a9352 100644 --- a/protocol-units/data-availability/rollup/Cargo.toml +++ b/protocol-units/data-availability/rollup/Cargo.toml @@ -2,22 +2,60 @@ name = "rollup" version = "0.1.0" edition = "2021" +resolver = "2" description = "Sovereign Labs Rollup" [dependencies] -async-trait = { workspace = true } 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 } -tracing-subscriber = { workspace = true } # Sovereign Labs dependencies -sov-celestia-adapter = { workspace = true, features = ["native"], optional = true} -sov-modules-api = { workspace = true } +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 } -sov-risc0-adapter = { 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-state = { workspace = true } -sov-stf-runner = { workspace = true } -stf = { path = "../stf" } +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" \ No newline at end of file diff --git a/protocol-units/data-availability/rollup/src/celestia_rollup.rs b/protocol-units/data-availability/rollup/src/celestia_rollup.rs index 55eb6ea08..e864cfbdb 100644 --- a/protocol-units/data-availability/rollup/src/celestia_rollup.rs +++ b/protocol-units/data-availability/rollup/src/celestia_rollup.rs @@ -30,7 +30,7 @@ pub struct CelestiaRollup {} /// This is the place, where all the rollup components come together and /// they can be easily swapped with alternative implementations as needed. -#[async_trait] -impl RollupBlueprint for CelestiaRollup { +// #[async_trait] +// impl RollupBlueprint for CelestiaRollup { -} \ No newline at end of file +// } \ No newline at end of file diff --git a/protocol-units/data-availability/rollup/src/lib.rs b/protocol-units/data-availability/rollup/src/lib.rs index 701336a19..9e29b93d4 100644 --- a/protocol-units/data-availability/rollup/src/lib.rs +++ b/protocol-units/data-availability/rollup/src/lib.rs @@ -1,5 +1,5 @@ -//#[cfg(feature = "mock_da")] +#[cfg(feature = "mock_da")] pub mod mock_rollup; -//#[cfg(feature = "celestia_da")] +#[cfg(feature = "celestia_da")] pub mod celestia_rollup; \ No newline at end of file diff --git a/protocol-units/data-availability/rollup/src/mock_rollup.rs b/protocol-units/data-availability/rollup/src/mock_rollup.rs index e56ba9ad3..ec7376264 100644 --- a/protocol-units/data-availability/rollup/src/mock_rollup.rs +++ b/protocol-units/data-availability/rollup/src/mock_rollup.rs @@ -16,4 +16,4 @@ use sov_state::{DefaultStorageSpec, ZkStorage}; use sov_stf_runner::ParallelProverService; use sov_stf_runner::RollupConfig; use sov_stf_runner::RollupProverConfig; -use stf_starter::Runtime; \ No newline at end of file +//use stf_starter::Runtime; \ No newline at end of file diff --git a/protocol-units/data-availability/stf/Cargo.toml b/protocol-units/data-availability/stf/Cargo.toml index cbf301309..7a83c3f0a 100644 --- a/protocol-units/data-availability/stf/Cargo.toml +++ b/protocol-units/data-availability/stf/Cargo.toml @@ -1,20 +1,50 @@ [package] name = "stf" -version = "0.1.0" -edition = "2021" -description = "State Transition Function (STF) implemented with Sovereign Labs for Movement SDK" +resolver = "2" +homepage = "sovereign.xyz" +edition = { workspace = true } +publish = false [dependencies] -anyhow = { workspace = true } -jsonrpsee = { workspace = true } -borsh = { workspace = true } -serde = { workspace = true } +anyhow = { workspace = true } +serde = { workspace = true, features = ["derive", "rc"] } +serde_json = { workspace = true, optional = true } +jsonrpsee = { workspace = true, features = ["jsonrpsee-types"], optional = true } +borsh = { workspace = true, features = ["rc", "bytes"] } +clap = { workspace = true, features = ["derive"], optional = true } -#Sovereign Labs Dependencies +# Soverign Labs Dependencies +sov-modules-api = { workspace = true } +sov-state = { workspace = true } sov-accounts = { workspace = true } sov-bank = { workspace = true } sov-sequencer-registry = { workspace = true } -sov-modules-api = { workspace = true } +sov-mock-da = { workspace = true } sov-modules-stf-blueprint = { workspace = true } +sov-stf-runner = { workspace = true } +sov-sequencer = { workspace = true, optional = true } +sov-rollup-interface = { workspace = true } +tracing = "0.1.37" - +[features] +default = ["serde"] +native = [ + "sov-modules-api/native", + "sov-accounts/native", + "sov-bank/native", + "sov-sequencer-registry/native", + "sov-mock-da/native", + "sov-modules-stf-blueprint/native", + "sov-stf-runner/native", + "serde_json", + "jsonrpsee", + "sov-sequencer", + "clap", + "serde", +] +serde = [ + "sov-accounts/serde", + "sov-bank/serde", + "sov-modules-api/serde", + "sov-sequencer-registry/serde", +] \ No newline at end of file diff --git a/protocol-units/data-availability/stf/src/genesis_config.rs b/protocol-units/data-availability/stf/src/genesis_config.rs index 3b09b697d..8e72cbedf 100644 --- a/protocol-units/data-availability/stf/src/genesis_config.rs +++ b/protocol-units/data-availability/stf/src/genesis_config.rs @@ -1,18 +1,24 @@ +use std::path::{Path, PathBuf}; + use anyhow::{bail, Context as _}; +use sov_accounts::AccountConfig; +use sov_bank::BankConfig; use sov_modules_api::{Context, DaSpec}; use sov_modules_stf_blueprint::Runtime as RuntimeTrait; -use std::path::{Path, PathBuf}; +use sov_sequencer_registry::SequencerConfig; +use sov_stf_runner::read_json_file; +use super::GenesisConfig; use crate::Runtime; -/// Paths to genesis files +/// Paths to genesis files. pub struct GenesisPaths { - /// Accounts genesis path + /// Accounts genesis path. pub accounts_genesis_path: PathBuf, - /// Bank genesis path + /// Bank genesis path. pub bank_genesis_path: PathBuf, - /// Sequence genesis path - pub sequence_genesis_path: PathBuf, + /// Sequencer Registry genesis path. + pub sequencer_genesis_path: PathBuf, } impl GenesisPaths { @@ -23,9 +29,9 @@ impl GenesisPaths { /// expected files. pub fn from_dir(dir: impl AsRef) -> Self { Self { - accounts_genesis_path: dir.as_ref().join("accounts_genesis.json"), - bank_genesis_path: dir.as_ref().join("bank_genesis.json"), - sequence_genesis_path: dir.as_ref().join("sequence_genesis.json"), + accounts_genesis_path: dir.as_ref().join("accounts.json"), + bank_genesis_path: dir.as_ref().join("bank.json"), + sequencer_genesis_path: dir.as_ref().join("sequencer_registry.json"), } } } @@ -34,4 +40,47 @@ impl GenesisPaths { pub(crate) fn get_genesis_config( genesis_paths: &GenesisPaths, ) -> Result< as RuntimeTrait>::GenesisConfig, anyhow::Error> { + let genesis_config = + create_genesis_config(genesis_paths).context("Unable to read genesis configuration")?; + + validate_config(genesis_config) +} + +fn validate_config( + genesis_config: as RuntimeTrait>::GenesisConfig, +) -> Result< as RuntimeTrait>::GenesisConfig, anyhow::Error> { + let token_address = &sov_bank::get_genesis_token_address::( + &genesis_config.bank.tokens[0].token_name, + genesis_config.bank.tokens[0].salt, + ); + + let coins_token_addr = &genesis_config + .sequencer_registry + .coins_to_lock + .token_address; + + if coins_token_addr != token_address { + bail!( + "Wrong token address in `sequencer_registry_config` expected {} but found {}", + token_address, + coins_token_addr + ) + } + + Ok(genesis_config) } + +fn create_genesis_config( + genesis_paths: &GenesisPaths, +) -> anyhow::Result> { + let accounts_config: AccountConfig = read_json_file(&genesis_paths.accounts_genesis_path)?; + let bank_config: BankConfig = read_json_file(&genesis_paths.bank_genesis_path)?; + let sequencer_registry_config: SequencerConfig = + read_json_file(&genesis_paths.sequencer_genesis_path)?; + + Ok(GenesisConfig::new( + accounts_config, + bank_config, + sequencer_registry_config, + )) +} \ No newline at end of file diff --git a/protocol-units/data-availability/stf/src/hooks.rs b/protocol-units/data-availability/stf/src/hooks.rs new file mode 100644 index 000000000..bf0161c67 --- /dev/null +++ b/protocol-units/data-availability/stf/src/hooks.rs @@ -0,0 +1,123 @@ +//! This module implements the various "hooks" that are called by the STF during execution. +//! These hooks can be used to add custom logic at various points in the slot lifecycle: +//! - Before and after each transaction is executed. +//! - At the beginning and end of each batch ("blob") +//! - At the beginning and end of each slot (DA layer block) + +use super::runtime::Runtime; +use sov_accounts::AccountsTxHook; +use sov_bank::BankTxHook; +use sov_modules_api::hooks::{ApplyBlobHooks, FinalizeHook, SlotHooks, TxHooks}; +use sov_modules_api::transaction::Transaction; +use sov_modules_api::{AccessoryWorkingSet, BlobReaderTrait, Context, DaSpec, Spec, WorkingSet}; +use sov_modules_stf_blueprint::{RuntimeTxHook, SequencerOutcome}; +use sov_sequencer_registry::SequencerRegistry; +use sov_state::Storage; +use tracing::info; + +impl TxHooks for Runtime { + type Context = C; + type PreArg = RuntimeTxHook; + type PreResult = C; + + fn pre_dispatch_tx_hook( + &self, + tx: &Transaction, + working_set: &mut WorkingSet, + arg: &RuntimeTxHook, + ) -> anyhow::Result { + let RuntimeTxHook { height, sequencer } = arg; + let AccountsTxHook { sender, sequencer } = + self.accounts + .pre_dispatch_tx_hook(tx, working_set, sequencer)?; + + let hook = BankTxHook { sender, sequencer }; + self.bank.pre_dispatch_tx_hook(tx, working_set, &hook)?; + + Ok(C::new(hook.sender, hook.sequencer, *height)) + } + + fn post_dispatch_tx_hook( + &self, + tx: &Transaction, + ctx: &C, + working_set: &mut WorkingSet, + ) -> anyhow::Result<()> { + self.accounts.post_dispatch_tx_hook(tx, ctx, working_set)?; + self.bank.post_dispatch_tx_hook(tx, ctx, working_set)?; + Ok(()) + } +} + +impl ApplyBlobHooks for Runtime { + type Context = C; + type BlobResult = + SequencerOutcome<<::BlobTransaction as BlobReaderTrait>::Address>; + + fn begin_blob_hook( + &self, + blob: &mut Da::BlobTransaction, + working_set: &mut WorkingSet, + ) -> anyhow::Result<()> { + // Before executing each batch, check that the sender is regsitered as a sequencer + self.sequencer_registry.begin_blob_hook(blob, working_set) + } + + fn end_blob_hook( + &self, + result: Self::BlobResult, + working_set: &mut WorkingSet, + ) -> anyhow::Result<()> { + // After processing each blob, reward or slash the sequencer if appropriate + match result { + SequencerOutcome::Rewarded(_reward) => { + // TODO: Process reward here or above. + as ApplyBlobHooks>::end_blob_hook( + &self.sequencer_registry, + sov_sequencer_registry::SequencerOutcome::Completed, + working_set, + ) + } + SequencerOutcome::Ignored => Ok(()), + SequencerOutcome::Slashed { + reason, + sequencer_da_address, + } => { + info!("Sequencer {} slashed: {:?}", sequencer_da_address, reason); + as ApplyBlobHooks>::end_blob_hook( + &self.sequencer_registry, + sov_sequencer_registry::SequencerOutcome::Slashed { + sequencer: sequencer_da_address, + }, + working_set, + ) + } + } + } +} + +impl SlotHooks for Runtime { + type Context = C; + + fn begin_slot_hook( + &self, + _slot_header: &Da::BlockHeader, + _validity_condition: &Da::ValidityCondition, + _pre_state_root: &<::Storage as Storage>::Root, + _working_set: &mut sov_modules_api::WorkingSet, + ) { + } + + fn end_slot_hook(&self, _working_set: &mut sov_modules_api::WorkingSet) {} +} + +impl FinalizeHook for Runtime { + type Context = C; + + fn finalize_hook( + &self, + _root_hash: &<::Storage as Storage>::Root, + _accessory_working_set: &mut AccessoryWorkingSet, + ) { + } +} \ No newline at end of file diff --git a/protocol-units/data-availability/stf/src/lib.rs b/protocol-units/data-availability/stf/src/lib.rs index 886c8a58b..3e67a271b 100644 --- a/protocol-units/data-availability/stf/src/lib.rs +++ b/protocol-units/data-availability/stf/src/lib.rs @@ -1,6 +1,14 @@ -//! The rollup State Transition Function. - -//#[cfg(feature = "native")] +#[cfg(feature = "native")] pub mod genesis_config; -//mod hooks; -pub mod runtime; \ No newline at end of file +mod hooks; +pub mod runtime; +pub use runtime::*; +use sov_modules_stf_blueprint::StfBlueprint; +use sov_rollup_interface::da::DaVerifier; +use sov_stf_runner::verifier::StateTransitionVerifier; + +/// Alias for StateTransitionVerifier. +pub type StfVerifier = + StateTransitionVerifier::Spec, Vm, RT, K>, DA, Vm>; + +pub use sov_mock_da::MockDaSpec; \ No newline at end of file diff --git a/protocol-units/data-availability/stf/src/runtime.rs b/protocol-units/data-availability/stf/src/runtime.rs index 872c9a8c2..9f7f7d429 100644 --- a/protocol-units/data-availability/stf/src/runtime.rs +++ b/protocol-units/data-availability/stf/src/runtime.rs @@ -5,19 +5,18 @@ //! 2. Add the module to the `Runtime` below //! 3. Update `genesis.json` with any additional data required by your new module -//#[cfg(feature = "native")] +#[cfg(feature = "native")] pub use sov_accounts::{AccountsRpcImpl, AccountsRpcServer}; -//#[cfg(feature = "native")] +#[cfg(feature = "native")] pub use sov_bank::{BankRpcImpl, BankRpcServer}; -use sov_modules_api::macros::{DefaultRuntime, CliWallet}; -//#[cfg(feature = "native")] +use sov_modules_api::macros::DefaultRuntime; +#[cfg(feature = "native")] use sov_modules_api::Spec; use sov_modules_api::{Context, DaSpec, DispatchCall, Genesis, MessageCodec}; -//#[cfg(feature = "native")] +#[cfg(feature = "native")] pub use sov_sequencer_registry::{SequencerRegistryRpcImpl, SequencerRegistryRpcServer}; - -//#[cfg(feature = "native")] -use crate::genesis_config::{get_genesis_config, GenesisPaths}; +#[cfg(feature = "native")] +use crate::genesis_config::GenesisPaths; /// The runtime defines the logic of the rollup. /// @@ -49,44 +48,42 @@ use crate::genesis_config::{get_genesis_config, GenesisPaths}; /// `#[derive(MessageCodec)` adds deserialization capabilities to the `Runtime` (by implementing the `decode_call` method). /// `Runtime::decode_call` accepts a serialized call message and returns a type that implements the `DispatchCall` trait. /// The `DispatchCall` implementation (derived by a macro) forwards the message to the appropriate module and executes its `call` method. -#[derive( - CliWallet, - Genesis, - DispatchCall, - MessageCodec, - DefaultRuntime, - borsh::BorshDeserialize, - borsh::BorshSerialize, - serde::Serialize, - serde::Deserialize +#[cfg_attr( + feature = "native", + derive(sov_modules_api::macros::CliWallet), + sov_modules_api::macros::expose_rpc )] -#[sov_modules_api::macros::expose_rpc] +#[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] +#[serialization(borsh::BorshDeserialize, borsh::BorshSerialize)] +#[cfg_attr(feature = "serde", serialization(serde::Serialize, serde::Deserialize))] pub struct Runtime { - /// The `accounts` module is responsible for managing user accounts and their nonces. + /// The `accounts` module is responsible for managing user accounts and their nonces pub accounts: sov_accounts::Accounts, - /// The `bank` module is responsible for minting, transferring and burning tokens. + /// The bank module is responsible for minting, transferring, and burning tokens pub bank: sov_bank::Bank, - /// The sequencer reqistry module is responsible for authorizing users to sequencer rollup transactions. + /// The sequencer registry module is responsible for authorizing users to sequencer rollup transactions pub sequencer_registry: sov_sequencer_registry::SequencerRegistry, } -impl sov_modules_stf_blueprint::Runtime for Runtime +impl sov_modules_stf_blueprint::Runtime for Runtime where C: Context, Da: DaSpec, { type GenesisConfig = GenesisConfig; - //# [cfg(feature = "native")] + #[cfg(feature = "native")] + type GenesisPaths = GenesisPaths; + + #[cfg(feature = "native")] fn rpc_methods(storage: ::Storage) -> jsonrpsee::RpcModule<()> { get_rpc_methods::(storage.clone()) } - //# [cfg(feature = "native")] + #[cfg(feature = "native")] fn genesis_config( - genesis_paths: &Self::GenesisPaths, - ) -> Result { + genesis_paths: &Self::GenesisPaths, + ) -> Result { crate::genesis_config::get_genesis_config(genesis_paths) } -} - +} \ No newline at end of file From 49ef50fa3e430cc8c48b6699dcbd82d0492a2d2b Mon Sep 17 00:00:00 2001 From: Richard Melkonian Date: Mon, 4 Mar 2024 15:00:58 +0000 Subject: [PATCH 8/9] create mock rollup --- .../rollup/src/celestia_rollup.rs | 36 +++++- .../rollup/src/mock_rollup.rs | 115 +++++++++++++++++- 2 files changed, 145 insertions(+), 6 deletions(-) diff --git a/protocol-units/data-availability/rollup/src/celestia_rollup.rs b/protocol-units/data-availability/rollup/src/celestia_rollup.rs index e864cfbdb..c5175ba46 100644 --- a/protocol-units/data-availability/rollup/src/celestia_rollup.rs +++ b/protocol-units/data-availability/rollup/src/celestia_rollup.rs @@ -19,7 +19,7 @@ use sov_stf_runner::RollupConfig; use sov_stf_runner::RollupProverConfig; use stf::Runtime; -/// The namespace for the rollup on Celestia. +/// The namespace for the rollup on Celestia. const ROLLUP_NAMESPACE: Namespace = Namespace::const_v0(b"sov-celest"); /// The rollup stores the zk proofs in the namespace b"sov-test-p" on Celestia. @@ -30,7 +30,35 @@ pub struct CelestiaRollup {} /// This is the place, where all the rollup components come together and /// they can be easily swapped with alternative implementations as needed. -// #[async_trait] -// impl RollupBlueprint for CelestiaRollup { +#[async_trait] +impl RollupBlueprint for CelestiaRollup { + type DaSerive = CelesitaSerive; + type DaSpec = CelestiaSpec; + type DaConfig = CelestiaConfig; + type Vm = Risc0Host<'static>; -// } \ No newline at end of file + type ZkContext = ZkDefaultContext; + type NativeContext = DefaultContext; + + type StorageManager = ProverStoragerManager; + type ZkRuntime = Runtime; + + type NativeRuntime = Runtime; + + type NativeKernel = BasicKernel; + type ZkKernel = BasicKernel; + + type ProverService = ParallelProverService< + <::Storage as Storage>::Root, + <::Storage as Storage>::Witness, + Self::DaService, + Self::Vm, + StfBlueprint< + Self::ZkContext, + Self::DaSpec, + ::Guest, + Self::ZkRuntime, + Self::ZkKernel, + >, + >; +} diff --git a/protocol-units/data-availability/rollup/src/mock_rollup.rs b/protocol-units/data-availability/rollup/src/mock_rollup.rs index ec7376264..49062ac12 100644 --- a/protocol-units/data-availability/rollup/src/mock_rollup.rs +++ b/protocol-units/data-availability/rollup/src/mock_rollup.rs @@ -1,5 +1,5 @@ use async_trait::async_trait; -use sov_db::ledger_db::LedgerDB; +use sov_db::ledger_db::{self, LedgerDB}; use sov_mock_da::{MockDaConfig, MockDaService, MockDaSpec}; use sov_modules_api::default_context::{DefaultContext, ZkDefaultContext}; use sov_modules_api::Address; @@ -16,4 +16,115 @@ use sov_state::{DefaultStorageSpec, ZkStorage}; use sov_stf_runner::ParallelProverService; use sov_stf_runner::RollupConfig; use sov_stf_runner::RollupProverConfig; -//use stf_starter::Runtime; \ No newline at end of file +use stf::Runtime; + +pub struct MockRollup {} + +#[async_trait] +impl RollupBlueprint for MockRollup { + /// This component defines the Data Availability layer. + type DaService = MockDaService; + type DaSpec = MockDaSpec; + type DaConfig = MockDaConfig; + + /// The concrete ZkVm used in the rollup. + type Vm = Risc0Host<'static>; + /// Context for the Zero Knowledge environment. + type ZkContext = ZkDefaultContext; + /// Context for the ZNative environment. + type NativeContext = DefaultContext; + + /// Manager for the native storage lifecycle. + type StorageManager = ProverStorageManager; + + /// Runtime for the Zero Knowledge environment. + type ZkRuntime = Runtime; + /// Runtime for the Native environment. + type NativeRuntime = Runtime; + + /// Kernels. + type NativeKernel = BasicKernel; + type ZkKernel = BasicKernel; + + /// Prover service. + type ProverService = ParallelProverService< + <::Storage as Storage>::Root, + <::Storage as Storage>::Witness, + Self::DaService, + Self::Vm, + StfBlueprint< + Self::ZkContext, + Self::DaSpec, + ::Guest, + Self::ZkRuntime, + Self::ZkKernel, + >, + >; + + /// This function generates RPC methods for the rollup, allowing for extension with custom endpoints. + fn create_rpc_methods( + &self, + storage: &::Storage, + ledger_db: &LedgerDB, + da_service: &Self::DaService, + ) -> Result, anyhow::Error> { + //TODO set sequencer address + let sequencer = Address::new([0; 32]); + + #[allow(unused_mut)] + let mut rpc_methods = sov_modules_rollup_blueprint::register_rpc::< + Self::NativeRuntime, + Self::NativeContext, + Self::DaService, + >(storage, ledger_db, da_service, sequencer)?; + + #[cfg(feature = "experimental")] + crate::eth::register_ethereum::( + da_service.clone(), + storage.clone(), + &mut rpc_methods, + )?; + + Ok(rpc_methods) + } + + async fn create_da_service( + &self, + rollup_config: &RollupConfig, + ) -> Self::DaService { + MockDaService::new(rollup_config.da.sender_address) + } + + async fn create_prover_service( + &self, + prover_config: RollupProverConfig, + rollup_config: &RollupConfig, + _da_service: &Self::DaService, + ) -> Self::ProverService { + let vm = Risc0Host::new(risc0_starter::MOCK_DA_ELF); + let zk_stf = StfBlueprint::new(); + let zk_storage = ZkStorage::new(); + let da_verifier = Default::default(); + + ParallelProverService::new_with_default_workers( + vm, + zk_stf, + da_verifier, + prover_config, + zk_storage, + rollup_config.prover_service, + ) + } + + fn create_storage_manager( + &self, + rollup_config: &RollupConfig, + ) -> anyhow::Result { + let storage_config = StorageConfig { + path: rollup_config.storage.path.clone(), + }; + ProverStorageManager::new(storage_config) + } +} + +impl sov_modules_rollup_blueprint::WalletBlueprint for MockRollup {} From 638f4e92e4261258ca4feac2d065326b23e6c223 Mon Sep 17 00:00:00 2001 From: Richard Melkonian Date: Mon, 4 Mar 2024 17:40:49 +0000 Subject: [PATCH 9/9] dep updates --- Cargo.toml | 2 + .../provers/risc0/Cargo.toml | 16 +++++++ .../data-availability/provers/risc0/build.rs | 24 ++++++++++ .../provers/risc0/guest-celestia/Cargo.toml | 44 +++++++++++++++++ .../risc0/guest-celestia/src/bin/rollup.rs | 35 ++++++++++++++ .../provers/risc0/guest-mock/Cargo.toml | 47 +++++++++++++++++++ .../risc0/guest-mock/src/bin/mock_da.rs | 28 +++++++++++ .../provers/risc0/src/lib.rs | 1 + .../data-availability/rollup/Cargo.toml | 2 +- 9 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 protocol-units/data-availability/provers/risc0/Cargo.toml create mode 100644 protocol-units/data-availability/provers/risc0/build.rs create mode 100644 protocol-units/data-availability/provers/risc0/guest-celestia/Cargo.toml create mode 100644 protocol-units/data-availability/provers/risc0/guest-celestia/src/bin/rollup.rs create mode 100644 protocol-units/data-availability/provers/risc0/guest-mock/Cargo.toml create mode 100644 protocol-units/data-availability/provers/risc0/guest-mock/src/bin/mock_da.rs create mode 100644 protocol-units/data-availability/provers/risc0/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index e7a44bc62..b3f93fe82 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,6 +63,8 @@ sov-mock-da = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev 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] opt-level = 3 diff --git a/protocol-units/data-availability/provers/risc0/Cargo.toml b/protocol-units/data-availability/provers/risc0/Cargo.toml new file mode 100644 index 000000000..bf08cd1de --- /dev/null +++ b/protocol-units/data-availability/provers/risc0/Cargo.toml @@ -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 = [] \ No newline at end of file diff --git a/protocol-units/data-availability/provers/risc0/build.rs b/protocol-units/data-availability/provers/risc0/build.rs new file mode 100644 index 000000000..a71c2860c --- /dev/null +++ b/protocol-units/data-availability/provers/risc0/build.rs @@ -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() +} \ No newline at end of file diff --git a/protocol-units/data-availability/provers/risc0/guest-celestia/Cargo.toml b/protocol-units/data-availability/provers/risc0/guest-celestia/Cargo.toml new file mode 100644 index 000000000..ab72ffb76 --- /dev/null +++ b/protocol-units/data-availability/provers/risc0/guest-celestia/Cargo.toml @@ -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 \ No newline at end of file diff --git a/protocol-units/data-availability/provers/risc0/guest-celestia/src/bin/rollup.rs b/protocol-units/data-availability/provers/risc0/guest-celestia/src/bin/rollup.rs new file mode 100644 index 000000000..c354380bf --- /dev/null +++ b/protocol-units/data-availability/provers/risc0/guest-celestia/src/bin/rollup.rs @@ -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, 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"); +} \ No newline at end of file diff --git a/protocol-units/data-availability/provers/risc0/guest-mock/Cargo.toml b/protocol-units/data-availability/provers/risc0/guest-mock/Cargo.toml new file mode 100644 index 000000000..9ac19407e --- /dev/null +++ b/protocol-units/data-availability/provers/risc0/guest-mock/Cargo.toml @@ -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 \ No newline at end of file diff --git a/protocol-units/data-availability/provers/risc0/guest-mock/src/bin/mock_da.rs b/protocol-units/data-availability/provers/risc0/guest-mock/src/bin/mock_da.rs new file mode 100644 index 000000000..59446c3ca --- /dev/null +++ b/protocol-units/data-availability/provers/risc0/guest-mock/src/bin/mock_da.rs @@ -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> = StfBlueprint::new(); + let stf_verifier = StfVerifier::new(stf, MockDaVerifier {}); + + stf_verifier + .run_block(guest, storage) + .expect("Prover must be honest"); +} diff --git a/protocol-units/data-availability/provers/risc0/src/lib.rs b/protocol-units/data-availability/provers/risc0/src/lib.rs new file mode 100644 index 000000000..cd788e84c --- /dev/null +++ b/protocol-units/data-availability/provers/risc0/src/lib.rs @@ -0,0 +1 @@ +include!(concat!(env!("OUT_DIR"), "/methods.rs")); \ No newline at end of file diff --git a/protocol-units/data-availability/rollup/Cargo.toml b/protocol-units/data-availability/rollup/Cargo.toml index 6ad6a9352..b17bc8ea6 100644 --- a/protocol-units/data-availability/rollup/Cargo.toml +++ b/protocol-units/data-availability/rollup/Cargo.toml @@ -35,7 +35,7 @@ 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" } +risc0-starter = { path = "../provers/risc0" } stf = { path = "../stf", features = ["native"] }