kona_interop/
errors.rs

1//! Error types for the `kona-interop` crate.
2
3use crate::InteropProvider;
4use alloy_primitives::{Address, B256};
5use core::fmt::Debug;
6use kona_registry::HashMap;
7use thiserror::Error;
8
9/// An error type for the [MessageGraph] struct.
10///
11/// [MessageGraph]: crate::MessageGraph
12#[derive(Debug, Clone, PartialEq, Eq, Error)]
13pub enum MessageGraphError<E: Debug> {
14    /// Dependency set is impossibly empty
15    #[error("Dependency set is impossibly empty")]
16    EmptyDependencySet,
17    /// Missing a [RollupConfig] for a chain ID
18    ///
19    /// [RollupConfig]: kona_genesis::RollupConfig
20    #[error("Missing a RollupConfig for chain ID {0}")]
21    MissingRollupConfig(u64),
22    /// Interop provider error
23    #[error("Interop provider: {0}")]
24    InteropProviderError(#[from] E),
25    /// Remote message not found
26    #[error("Remote message not found on chain ID {chain_id} with message hash {message_hash}")]
27    RemoteMessageNotFound {
28        /// The remote chain ID
29        chain_id: u64,
30        /// The message hash
31        message_hash: B256,
32    },
33    /// Invalid message origin
34    #[error("Invalid message origin. Expected {expected}, got {actual}")]
35    InvalidMessageOrigin {
36        /// The expected message origin
37        expected: Address,
38        /// The actual message origin
39        actual: Address,
40    },
41    /// Invalid message payload hash
42    #[error("Invalid message hash. Expected {expected}, got {actual}")]
43    InvalidMessageHash {
44        /// The expected message hash
45        expected: B256,
46        /// The actual message hash
47        actual: B256,
48    },
49    /// Invalid message timestamp
50    #[error("Invalid message timestamp. Expected {expected}, got {actual}")]
51    InvalidMessageTimestamp {
52        /// The expected timestamp
53        expected: u64,
54        /// The actual timestamp
55        actual: u64,
56    },
57    /// Interop has not been activated for at least one block on the initiating message's chain.
58    #[error(
59        "Interop has not been active for at least one block on initiating message's chain. Activation time: {activation_time}, initiating message time: {initiating_message_time}"
60    )]
61    InitiatedTooEarly {
62        /// The timestamp of the interop activation
63        activation_time: u64,
64        /// The timestamp of the initiating message
65        initiating_message_time: u64,
66    },
67    /// Message is in the future
68    #[error("Message is in the future. Expected timestamp to be <= {max}, got {actual}")]
69    MessageInFuture {
70        /// The expected max timestamp
71        max: u64,
72        /// The actual timestamp
73        actual: u64,
74    },
75    /// Message has exceeded the expiry window.
76    #[error(
77        "Message has exceeded the expiry window. Initiating Timestamp: {initiating_timestamp}, Executing Timestamp: {executing_timestamp}"
78    )]
79    MessageExpired {
80        /// The timestamp of the initiating message
81        initiating_timestamp: u64,
82        /// The timestamp of the executing message
83        executing_timestamp: u64,
84    },
85    /// Invalid messages were found
86    #[error("Invalid messages found on chains: {0:?}")]
87    InvalidMessages(HashMap<u64, MessageGraphError<E>>),
88}
89
90/// A [Result] alias for the [MessageGraphError] type.
91#[allow(type_alias_bounds)]
92pub type MessageGraphResult<T, P: InteropProvider> =
93    core::result::Result<T, MessageGraphError<P::Error>>;
94
95/// An error type for the [SuperRoot] struct's serialization and deserialization.
96///
97/// [SuperRoot]: crate::SuperRoot
98#[derive(Debug, Clone, Error)]
99pub enum SuperRootError {
100    /// Invalid super root version byte
101    #[error("Invalid super root version byte")]
102    InvalidVersionByte,
103    /// Unexpected encoded super root length
104    #[error("Unexpected encoded super root length")]
105    UnexpectedLength,
106    /// Slice conversion error
107    #[error("Slice conversion error: {0}")]
108    SliceConversionError(#[from] core::array::TryFromSliceError),
109}
110
111/// A [Result] alias for the [SuperRootError] type.
112pub type SuperRootResult<T> = core::result::Result<T, SuperRootError>;
113
114/// Errors that can occur during interop validation.
115#[derive(Debug, Error, PartialEq, Eq)]
116pub enum InteropValidationError {
117    /// Interop is not enabled on one or both chains at the required timestamp.
118    #[error("interop not enabled")]
119    InteropNotEnabled,
120
121    /// Executing timestamp is earlier than the initiating timestamp.
122    #[error(
123        "executing timestamp is earlier than initiating timestamp, executing: {executing}, initiating: {initiating}"
124    )]
125    InvalidTimestampInvariant {
126        /// Executing timestamp of the message
127        executing: u64,
128        /// Initiating timestamp of the message
129        initiating: u64,
130    },
131
132    /// Timestamp is outside the allowed interop expiry window.
133    #[error("timestamp outside allowed interop window, timestamp: {0}")]
134    InvalidInteropTimestamp(u64),
135}