diff --git a/Cargo.lock b/Cargo.lock index 616d65cfd..908c46013 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1687,6 +1687,7 @@ dependencies = [ "kona-derive", "kona-mpt", "kona-preimage", + "kona-primitives", "lru", "op-alloy-consensus", "revm", diff --git a/bin/host/src/cli/mod.rs b/bin/host/src/cli/mod.rs index 4ef072dd5..8e51bc310 100644 --- a/bin/host/src/cli/mod.rs +++ b/bin/host/src/cli/mod.rs @@ -52,6 +52,9 @@ pub struct HostCli { /// Number of the L2 block that the claim is from. #[clap(long)] pub l2_block_number: u64, + /// The L2 chain ID. + #[clap(long)] + pub l2_chain_id: u64, //// Path to the genesis file. #[clap(long)] pub l2_genesis_path: PathBuf, diff --git a/bin/host/src/kv/local.rs b/bin/host/src/kv/local.rs index de64cfa74..e66583df4 100644 --- a/bin/host/src/kv/local.rs +++ b/bin/host/src/kv/local.rs @@ -4,8 +4,8 @@ use super::KeyValueStore; use crate::cli::HostCli; use alloy_primitives::B256; use kona_client::{ - L1_HEAD_KEY, L2_CHAIN_CONFIG_KEY, L2_CHAIN_ID_KEY, L2_CLAIM_BLOCK_NUMBER_KEY, L2_CLAIM_KEY, - L2_OUTPUT_ROOT_KEY, L2_ROLLUP_CONFIG_KEY, + L1_HEAD_KEY, L2_CHAIN_ID_KEY, L2_CLAIM_BLOCK_NUMBER_KEY, L2_CLAIM_KEY, L2_OUTPUT_ROOT_KEY, + L2_ROLLUP_CONFIG_KEY, }; use kona_preimage::PreimageKey; @@ -29,9 +29,8 @@ impl KeyValueStore for LocalKeyValueStore { L2_OUTPUT_ROOT_KEY => Some(self.cfg.l2_output_root.to_vec()), 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 => todo!(), - L2_CHAIN_CONFIG_KEY => todo!(), - L2_ROLLUP_CONFIG_KEY => todo!(), + 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."), _ => None, } } diff --git a/bin/programs/client/Cargo.toml b/bin/programs/client/Cargo.toml index db7cc9b05..0f93ac4c7 100644 --- a/bin/programs/client/Cargo.toml +++ b/bin/programs/client/Cargo.toml @@ -25,6 +25,7 @@ async-trait.workspace = true kona-common = { path = "../../../crates/common", version = "0.0.1" } kona-common-proc = { path = "../../../crates/common-proc", version = "0.0.1" } kona-preimage = { path = "../../../crates/preimage", version = "0.0.1" } +kona-primitives = { path = "../../../crates/primitives", version = "0.0.1" } kona-mpt = { path = "../../../crates/mpt", version = "0.0.1" } kona-derive = { path = "../../../crates/derive", version = "0.0.1" } diff --git a/bin/programs/client/justfile b/bin/programs/client/justfile index fb54f5d69..cbd49030a 100644 --- a/bin/programs/client/justfile +++ b/bin/programs/client/justfile @@ -17,6 +17,7 @@ run-client-native l1_rpc l1_beacon_rpc l2_rpc verbosity: L2_OUTPUT_ROOT=$(cast 2b 0) L2_CLAIM=$(cast 2b 0) L2_BLOCK_NUMBER=0 + L2_CHAIN_ID=10 L1_NODE_ADDRESS="{{l1_rpc}}" L1_BEACON_ADDRESS="{{l1_beacon_rpc}}" @@ -36,6 +37,7 @@ run-client-native l1_rpc l1_beacon_rpc l2_rpc verbosity: --l2-claim $L2_CLAIM \ --l2-output-root $L2_OUTPUT_ROOT \ --l2-block-number $L2_BLOCK_NUMBER \ + --l2-chain-id $L2_CHAIN_ID \ --l1-node-address $L1_NODE_ADDRESS \ --l1-beacon-address $L1_BEACON_ADDRESS \ --l2-node-address $L2_NODE_ADDRESS \ diff --git a/bin/programs/client/src/boot.rs b/bin/programs/client/src/boot.rs index 32dd0cb8d..da7fef421 100644 --- a/bin/programs/client/src/boot.rs +++ b/bin/programs/client/src/boot.rs @@ -4,6 +4,7 @@ use alloy_primitives::{B256, U256}; use anyhow::{anyhow, Result}; use kona_preimage::{PreimageKey, PreimageOracleClient}; +use kona_primitives::{RollupConfig, OP_MAINNET_CONFIG}; /// The local key ident for the L1 head hash. pub const L1_HEAD_KEY: U256 = U256::from_be_slice(&[1]); @@ -20,11 +21,8 @@ pub const L2_CLAIM_BLOCK_NUMBER_KEY: U256 = U256::from_be_slice(&[4]); /// The local key ident for the L2 chain ID. pub const L2_CHAIN_ID_KEY: U256 = U256::from_be_slice(&[5]); -/// The local key ident for the L2 chain config. -pub const L2_CHAIN_CONFIG_KEY: U256 = U256::from_be_slice(&[6]); - /// The local key ident for the L2 rollup config. -pub const L2_ROLLUP_CONFIG_KEY: U256 = U256::from_be_slice(&[7]); +pub const L2_ROLLUP_CONFIG_KEY: U256 = U256::from_be_slice(&[6]); /// The boot information for the client program. /// @@ -49,6 +47,8 @@ pub struct BootInfo { pub l2_claim_block: u64, /// The L2 chain ID. pub chain_id: u64, + /// The rollup config for the L2 chain. + pub rollup_config: RollupConfig, } impl BootInfo { @@ -89,7 +89,16 @@ impl BootInfo { .try_into() .map_err(|_| anyhow!("Failed to convert L2 chain ID to u64"))?, ); + let rollup_config = rollup_config_from_chain_id(chain_id)?; + + Ok(Self { l1_head, l2_output_root, l2_claim, l2_claim_block, chain_id, rollup_config }) + } +} - Ok(Self { l1_head, l2_output_root, l2_claim, l2_claim_block, chain_id }) +/// Returns the rollup config for the given chain ID. +fn rollup_config_from_chain_id(chain_id: u64) -> Result { + match chain_id { + 10 => Ok(OP_MAINNET_CONFIG), + _ => anyhow::bail!("Unsupported chain ID: {}", chain_id), } } diff --git a/bin/programs/client/src/lib.rs b/bin/programs/client/src/lib.rs index 3110a0d79..e4ef5a6e0 100644 --- a/bin/programs/client/src/lib.rs +++ b/bin/programs/client/src/lib.rs @@ -13,6 +13,6 @@ pub use comms::{CachingOracle, HINT_WRITER, ORACLE_READER}; mod boot; pub use boot::{ - BootInfo, L1_HEAD_KEY, L2_CHAIN_CONFIG_KEY, L2_CHAIN_ID_KEY, L2_CLAIM_BLOCK_NUMBER_KEY, - L2_CLAIM_KEY, L2_OUTPUT_ROOT_KEY, L2_ROLLUP_CONFIG_KEY, + BootInfo, L1_HEAD_KEY, L2_CHAIN_ID_KEY, L2_CLAIM_BLOCK_NUMBER_KEY, L2_CLAIM_KEY, + L2_OUTPUT_ROOT_KEY, L2_ROLLUP_CONFIG_KEY, };