diff --git a/rust/kona/bin/host/src/interop/cfg.rs b/rust/kona/bin/host/src/interop/cfg.rs index 6338521c11446..a178fb774886c 100644 --- a/rust/kona/bin/host/src/interop/cfg.rs +++ b/rust/kona/bin/host/src/interop/cfg.rs @@ -22,7 +22,12 @@ use kona_providers_alloy::{OnlineBeaconClient, OnlineBlobProvider}; use kona_std_fpvm::{FileChannel, FileDescriptor}; use op_alloy_network::Optimism; use serde::Serialize; -use std::{collections::HashMap, path::PathBuf, str::FromStr, sync::Arc}; +use std::{ + collections::{BTreeMap, HashMap}, + path::PathBuf, + str::FromStr, + sync::Arc, +}; use tokio::task::{self, JoinHandle}; /// The interop host application. @@ -228,13 +233,14 @@ impl InteropHost { } /// Reads the [`RollupConfig`]s from the file system and returns a map of L2 chain ID -> - /// [`RollupConfig`]s. + /// [`RollupConfig`]s. Uses `BTreeMap` to ensure deterministic JSON serialization order when + /// these configs are served as preimages to the cannon VM. pub fn read_rollup_configs( &self, - ) -> Option, InteropHostError>> { + ) -> Option, InteropHostError>> { let rollup_config_paths = self.rollup_config_paths.as_ref()?; - Some(rollup_config_paths.iter().try_fold(HashMap::default(), |mut acc, path| { + Some(rollup_config_paths.iter().try_fold(BTreeMap::default(), |mut acc, path| { // Read the serialized config from the file system. let ser_config = std::fs::read_to_string(path)?; diff --git a/rust/kona/crates/protocol/interop/src/depset.rs b/rust/kona/crates/protocol/interop/src/depset.rs index 5b9b29e7efc06..eb99ec204d80a 100644 --- a/rust/kona/crates/protocol/interop/src/depset.rs +++ b/rust/kona/crates/protocol/interop/src/depset.rs @@ -1,6 +1,6 @@ use crate::MESSAGE_EXPIRY_WINDOW; +use alloc::collections::BTreeMap; use alloy_primitives::ChainId; -use kona_registry::HashMap; /// Configuration for a dependency of a chain #[derive(Debug, Clone, PartialEq, Eq)] @@ -15,7 +15,7 @@ pub struct ChainDependency {} #[allow(clippy::zero_sized_map_values)] pub struct DependencySet { /// Dependencies information per chain. - pub dependencies: HashMap, + pub dependencies: BTreeMap, /// Override message expiry window to use for this dependency set. pub override_message_expiry_window: Option, @@ -35,11 +35,11 @@ impl DependencySet { #[allow(clippy::zero_sized_map_values)] mod tests { use super::*; + use alloc::collections::BTreeMap; use alloy_primitives::ChainId; - use kona_registry::HashMap; const fn create_dependency_set( - dependencies: HashMap, + dependencies: BTreeMap, override_expiry: u64, ) -> DependencySet { DependencySet { dependencies, override_message_expiry_window: Some(override_expiry) } @@ -47,7 +47,7 @@ mod tests { #[test] fn test_get_message_expiry_window_default() { - let deps = HashMap::default(); + let deps = BTreeMap::default(); // override_message_expiry_window is 0, so default should be used let ds = create_dependency_set(deps, 0); assert_eq!( @@ -59,7 +59,7 @@ mod tests { #[test] fn test_get_message_expiry_window_override() { - let deps = HashMap::default(); + let deps = BTreeMap::default(); let override_value = 12345; let ds = create_dependency_set(deps, override_value); assert_eq!(