superchain_primitives/
genesis.rs

1//! Genesis types.
2
3use crate::BlockID;
4use crate::SystemConfig;
5
6/// Chain genesis information.
7#[derive(Debug, Clone, Default, Hash, Eq, PartialEq)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
10pub struct ChainGenesis {
11    /// L1 genesis block
12    pub l1: BlockID,
13    /// L2 genesis block
14    pub l2: BlockID,
15    /// Timestamp of the L2 genesis block
16    pub l2_time: u64,
17    /// Optional System configuration
18    pub system_config: Option<SystemConfig>,
19}
20
21#[cfg(test)]
22mod tests {
23    use super::*;
24    use alloy_primitives::{address, b256, uint};
25
26    fn ref_genesis() -> ChainGenesis {
27        ChainGenesis {
28            l1: BlockID {
29                hash: b256!("438335a20d98863a4c0c97999eb2481921ccd28553eac6f913af7c12aec04108"),
30                number: 17422590,
31            },
32            l2: BlockID {
33                hash: b256!("dbf6a80fef073de06add9b0d14026d6e5a86c85f6d102c36d3d8e9cf89c2afd3"),
34                number: 105235063,
35            },
36            l2_time: 1686068903,
37            system_config: Some(SystemConfig {
38                batcher_address: address!("6887246668a3b87F54DeB3b94Ba47a6f63F32985"),
39                overhead: uint!(0xbc_U256),
40                scalar: uint!(0xa6fe0_U256),
41                gas_limit: 30000000,
42                base_fee_scalar: None,
43                blob_base_fee_scalar: None,
44            }),
45        }
46    }
47
48    #[test]
49    fn test_genesis_serde() {
50        let genesis_str = r#"{
51            "l1": {
52              "hash": "0x438335a20d98863a4c0c97999eb2481921ccd28553eac6f913af7c12aec04108",
53              "number": 17422590
54            },
55            "l2": {
56              "hash": "0xdbf6a80fef073de06add9b0d14026d6e5a86c85f6d102c36d3d8e9cf89c2afd3",
57              "number": 105235063
58            },
59            "l2_time": 1686068903,
60            "system_config": {
61              "batcherAddr": "0x6887246668a3b87F54DeB3b94Ba47a6f63F32985",
62              "overhead": "0x00000000000000000000000000000000000000000000000000000000000000bc",
63              "scalar": "0x00000000000000000000000000000000000000000000000000000000000a6fe0",
64              "gasLimit": 30000000
65            }
66          }"#;
67        let genesis: ChainGenesis = serde_json::from_str(genesis_str).unwrap();
68        assert_eq!(genesis, ref_genesis());
69    }
70}