diff --git a/Cargo.lock b/Cargo.lock index 44ec7bc43..1c780b9ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4198,6 +4198,7 @@ dependencies = [ "reqwest", "revm 13.0.0", "serde", + "serde_json", "tokio", "tracing", "tracing-subscriber", diff --git a/bin/client/Cargo.toml b/bin/client/Cargo.toml index 04ccf8ad6..0d8f004ef 100644 --- a/bin/client/Cargo.toml +++ b/bin/client/Cargo.toml @@ -22,6 +22,8 @@ spin.workspace = true async-trait.workspace = true tracing.workspace = true revm.workspace = true +serde = { version = "1.0.208", default-features = false, features = ["derive"] } +serde_json = { version = "1.0.125", default-features = false } # local kona-common = { path = "../../crates/common", version = "0.0.2" } @@ -35,10 +37,6 @@ kona-executor = { path = "../../crates/executor", version = "0.0.1" } # external tracing-subscriber = { version = "0.3.18", optional = true } -[dev-dependencies] -serde = { version = "1.0.197", features = ["derive"] } -serde_json = "1.0.117" - [features] tracing-subscriber = ["dep:tracing-subscriber"] diff --git a/bin/client/src/boot.rs b/bin/client/src/boot.rs index f1a2b35fb..2ec61ad0d 100644 --- a/bin/client/src/boot.rs +++ b/bin/client/src/boot.rs @@ -5,6 +5,7 @@ use alloy_primitives::{B256, U256}; use anyhow::{anyhow, Result}; use kona_preimage::{PreimageKey, PreimageOracleClient}; use kona_primitives::RollupConfig; +use tracing::warn; /// The local key ident for the L1 head hash. pub const L1_HEAD_KEY: U256 = U256::from_be_slice(&[1]); @@ -89,8 +90,21 @@ impl BootInfo { .try_into() .map_err(|_| anyhow!("Failed to convert L2 chain ID to u64"))?, ); - let rollup_config = RollupConfig::from_l2_chain_id(chain_id) - .ok_or_else(|| anyhow!("Failed to get rollup config for L2 Chain ID: {chain_id}"))?; + + // Attempt to load the rollup config from the chain ID. If there is no config for the chain, + // fall back to loading the config from the preimage oracle. + let rollup_config = if let Some(config) = RollupConfig::from_l2_chain_id(chain_id) { + config + } else { + warn!( + target: "boot-loader", + "No rollup config found for chain ID {}, falling back to preimage oracle. This is insecure in production without additional validation!", + chain_id + ); + let ser_cfg = oracle.get(PreimageKey::new_local(L2_ROLLUP_CONFIG_KEY.to())).await?; + serde_json::from_slice(&ser_cfg) + .map_err(|e| anyhow!("Failed to deserialize rollup config: {}", e))? + }; Ok(Self { l1_head, l2_output_root, l2_claim, l2_claim_block, chain_id, rollup_config }) } diff --git a/bin/host/Cargo.toml b/bin/host/Cargo.toml index 6230ba8d8..39533be15 100644 --- a/bin/host/Cargo.toml +++ b/bin/host/Cargo.toml @@ -35,7 +35,8 @@ reqwest = "0.12" tokio = { version = "1.37.0", features = ["full"] } futures = "0.3" clap = { version = "4.5.4", features = ["derive", "env"] } -serde = { version = "1.0.198", features = ["derive"] } +serde = { version = "1.0.208", features = ["derive"] } +serde_json = "1.0.125" tracing-subscriber = "0.3.18" command-fds = { version = "0.3", features = ["tokio"] } os_pipe = "1.2.1" diff --git a/bin/host/src/cli/mod.rs b/bin/host/src/cli/mod.rs index 84a4e4de3..62dccae54 100644 --- a/bin/host/src/cli/mod.rs +++ b/bin/host/src/cli/mod.rs @@ -5,7 +5,9 @@ use crate::kv::{ SplitKeyValueStore, }; use alloy_primitives::B256; +use anyhow::{anyhow, Result}; use clap::{ArgAction, Parser}; +use kona_derive::types::RollupConfig; use serde::Serialize; use std::{path::PathBuf, sync::Arc}; use tokio::sync::RwLock; @@ -59,6 +61,9 @@ pub struct HostCli { /// Run in pre-image server mode without executing any client program. Defaults to `false`. #[clap(long)] pub server: bool, + /// Path to rollup config + #[clap(long)] + pub rollup_config_path: Option, } impl HostCli { @@ -86,4 +91,21 @@ impl HostCli { kv_store } + + /// Reads the [RollupConfig] from the file system and returns it as a string. + pub fn read_rollup_config(&self) -> Result { + let path = self.rollup_config_path.as_ref().ok_or_else(|| { + anyhow::anyhow!( + "No rollup config path provided. Please provide a path to the rollup config." + ) + })?; + + // Read the serialized config from the file system. + let ser_config = std::fs::read_to_string(path) + .map_err(|e| anyhow!("Error reading RollupConfig file: {e}"))?; + + // Deserialize the config and return it. + serde_json::from_str(&ser_config) + .map_err(|e| anyhow!("Error deserializing RollupConfig: {e}")) + } } diff --git a/bin/host/src/kv/local.rs b/bin/host/src/kv/local.rs index 23dce446d..12bd92c64 100644 --- a/bin/host/src/kv/local.rs +++ b/bin/host/src/kv/local.rs @@ -31,7 +31,11 @@ impl KeyValueStore for LocalKeyValueStore { L2_CLAIM_KEY => Some(self.cfg.l2_claim.to_vec()), L2_CLAIM_BLOCK_NUMBER_KEY => Some(self.cfg.l2_block_number.to_be_bytes().to_vec()), L2_CHAIN_ID_KEY => Some(self.cfg.l2_chain_id.to_be_bytes().to_vec()), - L2_ROLLUP_CONFIG_KEY => unimplemented!("L2RollupConfig fetching in local store not implemented. Necessary for chain IDs without a known rollup config."), + L2_ROLLUP_CONFIG_KEY => { + let rollup_config = self.cfg.read_rollup_config().ok()?; + let serialized = serde_json::to_vec(&rollup_config).ok()?; + Some(serialized) + } _ => None, } }