Skip to content

Commit

Permalink
feat(workspace): kona-interop crate (#899)
Browse files Browse the repository at this point in the history
  • Loading branch information
clabby authored Jan 13, 2025
1 parent 7c49548 commit e7bfe4d
Show file tree
Hide file tree
Showing 13 changed files with 1,211 additions and 123 deletions.
270 changes: 147 additions & 123 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ members = [
"crates/driver",
"crates/executor",
"crates/mpt",
"crates/interop",
"crates/proof-sdk/*",
"bin/*"
]
Expand Down Expand Up @@ -91,6 +92,7 @@ alloy-node-bindings = { version = "0.9.2", default-features = false }
alloy-transport-http = { version = "0.9.2", default-features = false }
alloy-rpc-types-engine = { version = "0.9.2", default-features = false }
alloy-rpc-types-beacon = { version = "0.9.2", default-features = false }
alloy-sol-types = { version = "0.8.18", default-features = false }

# OP Alloy
op-alloy-genesis = { version = "0.9.2", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ see the [SDK section of the book](https://op-rs.github.io/kona/sdk/intro.html).
- [`executor`](./crates/executor): `no_std` stateless block executor for the [OP Stack][op-stack].
- [`derive`](./crates/derive): `no_std` compatible implementation of the [derivation pipeline][g-derivation-pipeline].
- [`driver`](./crates/driver): Stateful derivation pipeline driver.
- [`interop`](./crates/interop): Core functionality and primitives for the [Interop feature](https://specs.optimism.io/interop/overview.html) of the OP Stack.

**Proof SDK**

Expand Down
37 changes: 37 additions & 0 deletions crates/interop/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "kona-interop"
description = "Core functionality and primitives for the Interop feature of the OP Stack."
version = "0.1.0"
edition.workspace = true
authors.workspace = true
license.workspace = true
repository.workspace = true
homepage.workspace = true

[lints]
workspace = true

[dependencies]
# General
thiserror.workspace = true
async-trait.workspace = true
tracing.workspace = true

# Alloy
alloy-primitives = { workspace = true, features = ["rlp"] }
alloy-sol-types.workspace = true
alloy-consensus.workspace = true
alloy-rlp.workspace = true
op-alloy-consensus.workspace = true

# Arbitrary
arbitrary = { version = "1.4", features = ["derive"], optional = true }

[dev-dependencies]
tokio = { workspace = true, features = ["full"] }
alloy-primitives = { workspace = true, features = ["rlp", "arbitrary"] }
arbitrary = { version = "1.4", features = ["derive"] }
rand.workspace = true

[features]
arbitrary = ["dep:arbitrary", "alloy-primitives/arbitrary"]
8 changes: 8 additions & 0 deletions crates/interop/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# `kona-interop`

<a href="https://github.com/op-rs/kona/actions/workflows/rust_ci.yaml"><img src="https://github.com/op-rs/kona/actions/workflows/rust_ci.yaml/badge.svg?label=ci" alt="CI"></a>
<a href="https://crates.io/crates/kona-interop"><img src="https://img.shields.io/crates/v/kona-interop.svg?label=kona-interop&labelColor=2a2f35" alt="Kona MPT"></a>
<a href="https://github.com/op-rs/kona/blob/main/LICENSE.md"><img src="https://img.shields.io/badge/License-MIT-d1d1f6.svg?label=license&labelColor=2a2f35" alt="License"></a>
<a href="https://img.shields.io/codecov/c/github/op-rs/kona"><img src="https://img.shields.io/codecov/c/github/op-rs/kona" alt="Codecov"></a>

Core functionality and primitives for the [Interop feature](https://specs.optimism.io/interop/overview.html) of the OP Stack.
15 changes: 15 additions & 0 deletions crates/interop/src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! Constants for the OP Stack interop protocol.
use alloy_primitives::{address, Address};

/// The address of the L2 cross chain inbox predeploy proxy.
pub const CROSS_L2_INBOX_ADDRESS: Address = address!("4200000000000000000000000000000000000022");

/// The expiry window for relaying an initiating message (in seconds).
/// <https://specs.optimism.io/interop/messaging.html#message-expiry-invariant>
pub const MESSAGE_EXPIRY_WINDOW: u64 = 180 * 24 * 60 * 60;

/// The current version of the [SuperRoot] encoding format.
///
/// [SuperRoot]: crate::SuperRoot
pub const SUPER_ROOT_VERSION: u8 = 1;
71 changes: 71 additions & 0 deletions crates/interop/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//! Error types for the `kona-interop` crate.
use alloc::vec::Vec;
use alloy_primitives::{Address, B256};
use thiserror::Error;

/// An error type for the [MessageGraph] struct.
///
/// [MessageGraph]: crate::MessageGraph
#[derive(Debug, Clone, PartialEq, Eq, Error)]
pub enum MessageGraphError {
/// Dependency set is impossibly empty
#[error("Dependency set is impossibly empty")]
EmptyDependencySet,
/// Remote message not found
#[error("Remote message not found on chain ID {0} with message hash {1}")]
RemoteMessageNotFound(u64, B256),
/// Invalid message origin
#[error("Invalid message origin. Expected {0}, got {1}")]
InvalidMessageOrigin(Address, Address),
/// Invalid message payload hash
#[error("Invalid message hash. Expected {0}, got {1}")]
InvalidMessageHash(B256, B256),
/// Invalid message timestamp
#[error("Invalid message timestamp. Expected {0}, got {1}")]
InvalidMessageTimestamp(u64, u64),
/// Message is in the future
#[error("Message is in the future. Expected timestamp to be <= {0}, got {1}")]
MessageInFuture(u64, u64),
/// Invalid messages were found
#[error("Invalid messages found on chains: {0:?}")]
InvalidMessages(Vec<u64>),
/// Interop provider error
#[error("Interop provider: {0}")]
InteropProviderError(#[from] InteropProviderError),
}

/// A [Result] alias for the [MessageGraphError] type.
pub type MessageGraphResult<T> = core::result::Result<T, MessageGraphError>;

/// An error type for the [InteropProvider] trait.
///
/// [InteropProvider]: crate::InteropProvider
#[derive(Debug, Clone, PartialEq, Eq, Error)]
pub enum InteropProviderError {
/// Unknown Chain ID
#[error("Unknown Chain ID")]
UnknownChainId,
/// Not found
#[error("Not found")]
NotFound,
}

/// A [Result] alias for the [InteropProviderError] type.
pub type InteropProviderResult<T> = core::result::Result<T, InteropProviderError>;

/// An error type for the [SuperRoot] struct's serialization and deserialization.
///
/// [SuperRoot]: crate::SuperRoot
#[derive(Debug, Clone, PartialEq, Eq, Error)]
pub enum SuperRootError {
/// Invalid super root version byte
#[error("Invalid super root version byte")]
InvalidVersionByte,
/// Unexpected encoded super root length
#[error("Unexpected encoded super root length")]
UnexpectedLength,
}

/// A [Result] alias for the [SuperRootError] type.
pub type SuperRootResult<T> = core::result::Result<T, SuperRootError>;
Loading

0 comments on commit e7bfe4d

Please sign in to comment.