Skip to content

Commit

Permalink
fix(interop): Check timestamp invariant against executing timestamp A…
Browse files Browse the repository at this point in the history
…ND horizon timestamp (#1024)
  • Loading branch information
clabby authored Feb 11, 2025
1 parent bc8822c commit cef9b87
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
28 changes: 14 additions & 14 deletions crates/interop/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,9 @@ where
let receipts = provider.receipts_by_hash(*chain_id, header.hash()).await?;
let executing_messages = extract_executing_messages(receipts.as_slice());

messages.extend(
executing_messages
.into_iter()
.map(|message| EnrichedExecutingMessage::new(message, *chain_id)),
);
messages.extend(executing_messages.into_iter().map(|message| {
EnrichedExecutingMessage::new(message, *chain_id, header.timestamp)
}));
}

info!(
Expand Down Expand Up @@ -167,9 +165,11 @@ where
// ChainID Invariant: The chain id of the initiating message MUST be in the dependency set
// This is enforced implicitly by the graph constructor and the provider.

let initiating_chain_id = message.inner.id.chainId.saturating_to();
let initiating_timestamp = message.inner.id.timestamp.saturating_to::<u64>();

// Attempt to fetch the rollup config for the initiating chain from the registry. If the
// rollup config is not found, fall back to the local rollup configs.
let initiating_chain_id = message.inner.id.chainId.saturating_to();
let rollup_config = ROLLUP_CONFIGS
.get(&initiating_chain_id)
.or_else(|| self.rollup_configs.get(&initiating_chain_id))
Expand All @@ -178,17 +178,17 @@ where
// Timestamp invariant: The timestamp at the time of inclusion of the initiating message
// MUST be less than or equal to the timestamp of the executing message as well as greater
// than or equal to the Interop Start Timestamp.
if message.inner.id.timestamp.saturating_to::<u64>() > self.horizon_timestamp {
if initiating_timestamp > self.horizon_timestamp ||
initiating_timestamp > message.executing_timestamp
{
return Err(MessageGraphError::MessageInFuture(
self.horizon_timestamp,
message.inner.id.timestamp.saturating_to(),
initiating_timestamp,
));
} else if message.inner.id.timestamp.saturating_to::<u64>() <
rollup_config.interop_time.unwrap_or_default()
{
} else if initiating_timestamp < rollup_config.interop_time.unwrap_or_default() {
return Err(MessageGraphError::InvalidMessageTimestamp(
rollup_config.interop_time.unwrap_or_default(),
message.inner.id.timestamp.saturating_to(),
initiating_timestamp,
));
}

Expand Down Expand Up @@ -239,9 +239,9 @@ where
}

// Validate that the timestamp of the block header containing the log is correct.
if remote_header.timestamp != message.inner.id.timestamp.saturating_to::<u64>() {
if remote_header.timestamp != initiating_timestamp {
return Err(MessageGraphError::InvalidMessageTimestamp(
message.inner.id.timestamp.saturating_to::<u64>(),
initiating_timestamp,
remote_header.timestamp,
));
}
Expand Down
10 changes: 8 additions & 2 deletions crates/interop/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,18 @@ pub struct EnrichedExecutingMessage {
pub inner: ExecutingMessage,
/// The chain ID of the chain that the message was executed on.
pub executing_chain_id: u64,
/// The timestamp of the block that the executing message was included in.
pub executing_timestamp: u64,
}

impl EnrichedExecutingMessage {
/// Create a new [EnrichedExecutingMessage] from an [ExecutingMessage] and a chain ID.
pub const fn new(inner: ExecutingMessage, executing_chain_id: u64) -> Self {
Self { inner, executing_chain_id }
pub const fn new(
inner: ExecutingMessage,
executing_chain_id: u64,
executing_timestamp: u64,
) -> Self {
Self { inner, executing_chain_id, executing_timestamp }
}
}

Expand Down

0 comments on commit cef9b87

Please sign in to comment.