diff --git a/Cargo.lock b/Cargo.lock index b701aeec4..ddb6efad4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4228,26 +4228,6 @@ dependencies = [ "tracing-subscriber", ] -[[package]] -name = "kona-plasma" -version = "0.0.1" -dependencies = [ - "alloy-consensus", - "alloy-primitives", - "alloy-provider", - "alloy-transport-http", - "anyhow", - "async-trait", - "kona-derive 0.0.2", - "kona-primitives 0.0.1", - "reqwest", - "serde", - "serde_json", - "tokio", - "tracing", - "tracing-subscriber", -] - [[package]] name = "kona-preimage" version = "0.0.2" diff --git a/crates/plasma/CHANGELOG.md b/crates/plasma/CHANGELOG.md deleted file mode 100644 index 3f1fefd5a..000000000 --- a/crates/plasma/CHANGELOG.md +++ /dev/null @@ -1,25 +0,0 @@ -# Changelog -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [Unreleased] - -## [0.0.1](https://github.com/ethereum-optimism/kona/releases/tag/kona-plasma-v0.0.1) - 2024-06-22 - -### Added -- *(kona-derive)* Towards Derivation ([#243](https://github.com/ethereum-optimism/kona/pull/243)) -- *(plasma)* Online Plasma Input Fetcher ([#167](https://github.com/ethereum-optimism/kona/pull/167)) -- *(ci)* Dependabot config ([#236](https://github.com/ethereum-optimism/kona/pull/236)) -- *(client)* `StatelessL2BlockExecutor` ([#210](https://github.com/ethereum-optimism/kona/pull/210)) -- *(preimage)* Async server components ([#183](https://github.com/ethereum-optimism/kona/pull/183)) -- *(derive)* Abstract Alt DA out of `kona-derive` ([#156](https://github.com/ethereum-optimism/kona/pull/156)) -- *(plasma)* Implements Plasma Support for kona derive ([#152](https://github.com/ethereum-optimism/kona/pull/152)) - -### Fixed -- *(plasma)* Plasma Data Source Cleanup ([#164](https://github.com/ethereum-optimism/kona/pull/164)) -- *(plasma)* reduce plasma source generic verbosity ([#165](https://github.com/ethereum-optimism/kona/pull/165)) - -### Other -- version dependencies ([#296](https://github.com/ethereum-optimism/kona/pull/296)) diff --git a/crates/plasma/Cargo.toml b/crates/plasma/Cargo.toml deleted file mode 100644 index 8aae4ce2f..000000000 --- a/crates/plasma/Cargo.toml +++ /dev/null @@ -1,52 +0,0 @@ -[package] -name = "kona-plasma" -description = "Plasma Data Availability Adapter" -version = "0.0.1" -edition.workspace = true -authors.workspace = true -license.workspace = true -repository.workspace = true -homepage.workspace = true - -[dependencies] -# Workspace -anyhow.workspace = true -tracing.workspace = true -alloy-consensus.workspace = true -alloy-primitives = { workspace = true, features = ["rlp"] } -async-trait.workspace = true - -# Local -kona-primitives = { path = "../primitives", version = "0.0.1" } -kona-derive = { path = "../derive", version = "0.0.2" } - -# `serde` feature dependencies -serde = { version = "1.0.203", default-features = false, features = ["derive"], optional = true } - -# `online` feature dependencies -alloy-transport-http = { version = "0.2", optional = true } -alloy-provider = { version = "0.2", default-features = false, optional = true } -reqwest = { version = "0.12", default-features = false, optional = true } - -[dev-dependencies] -kona-derive = { path = "../derive", features = ["test-utils"] } -serde_json = { version = "1.0.117", default-features = false } -tokio = { version = "1.38", features = ["full"] } -tracing-subscriber = "0.3.18" - -[features] -default = ["serde"] -serde = [ - "dep:serde", - "kona-primitives/serde", - "alloy-primitives/serde", - "alloy-consensus/serde", - "kona-derive/serde", -] -online = [ - "dep:alloy-provider", - "dep:alloy-transport-http", - "dep:reqwest", - "alloy-provider/reqwest", - "alloy-consensus/serde", -] diff --git a/crates/plasma/README.md b/crates/plasma/README.md deleted file mode 100644 index 4eadf2ea9..000000000 --- a/crates/plasma/README.md +++ /dev/null @@ -1,27 +0,0 @@ -# `kona-plasma` - -Plasma Data Availability Adapter for `kona-derive`. - -[plasma]: https://specs.optimism.io/experimental/plasma.html - -`kona-plasma` is an implementation of the [Plasma][plasma] OP Stack Specification in rust. - -## Usage - -Add `kona-plasma` to your `Cargo.toml`. - -```ignore -[dependencies] -kona-plasma = "0.0.1" - -# Serde is enabled by default and can be disabled by toggling default-features off -# kona-plasma = { version = "0.0.1", default-features = false } -``` - -## Features - -### Serde - -[`serde`] serialization and deserialization support for `kona-plasma` types. - -By default, the `serde` feature is enabled on `kona-plasma`. diff --git a/crates/plasma/src/lib.rs b/crates/plasma/src/lib.rs deleted file mode 100644 index 5c4e145e6..000000000 --- a/crates/plasma/src/lib.rs +++ /dev/null @@ -1,20 +0,0 @@ -#![doc = include_str!("../README.md")] -#![warn(missing_debug_implementations, missing_docs, unreachable_pub, rustdoc::all)] -#![deny(unused_must_use, rust_2018_idioms)] -#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -#![no_std] - -extern crate alloc; - -pub mod plasma; -pub mod source; -pub mod traits; -pub mod types; - -#[cfg(feature = "online")] -mod online; -#[cfg(feature = "online")] -pub use online::OnlinePlasmaInputFetcher; - -#[cfg(test)] -pub mod test_utils; diff --git a/crates/plasma/src/online.rs b/crates/plasma/src/online.rs deleted file mode 100644 index cf6da8748..000000000 --- a/crates/plasma/src/online.rs +++ /dev/null @@ -1,51 +0,0 @@ -//! Module contains an online implementation of the Plasma Input Fetcher. - -use crate::{ - traits::PlasmaInputFetcher, - types::{FinalizedHeadSignal, PlasmaError}, -}; -use alloc::boxed::Box; -use alloy_primitives::Bytes; -use async_trait::async_trait; -use kona_derive::online::AlloyChainProvider; -use kona_primitives::{BlockID, BlockInfo, SystemConfig}; - -/// An Online Plasma Input Fetcher. -#[derive(Debug, Clone)] -pub struct OnlinePlasmaInputFetcher {} - -#[async_trait] -impl PlasmaInputFetcher for OnlinePlasmaInputFetcher { - async fn get_input( - &mut self, - _fetcher: &AlloyChainProvider, - _commitment: Bytes, - _block: BlockID, - ) -> Option> { - unimplemented!() - } - - async fn advance_l1_origin( - &mut self, - _fetcher: &AlloyChainProvider, - _block: BlockID, - ) -> Option> { - unimplemented!() - } - - async fn reset( - &mut self, - _block_number: BlockInfo, - _cfg: SystemConfig, - ) -> Option> { - unimplemented!() - } - - async fn finalize(&mut self, _block_number: BlockInfo) -> Option> { - unimplemented!() - } - - fn on_finalized_head_signal(&mut self, _callback: FinalizedHeadSignal) { - unimplemented!() - } -} diff --git a/crates/plasma/src/plasma.rs b/crates/plasma/src/plasma.rs deleted file mode 100644 index b4cb00b97..000000000 --- a/crates/plasma/src/plasma.rs +++ /dev/null @@ -1,59 +0,0 @@ -//! Contains the [PlasmaDataSource], which is a concrete implementation of the -//! [DataAvailabilityProvider] trait for the Plasma source. Used as an adapter to the -//! [kona_derive] crate's derivation pipeline construction. - -use crate::{source::PlasmaSource, traits::PlasmaInputFetcher}; -use alloc::{boxed::Box, fmt::Debug}; -use alloy_primitives::Bytes; -use anyhow::Result; -use async_trait::async_trait; -use kona_derive::traits::{ChainProvider, DataAvailabilityProvider}; -use kona_primitives::BlockInfo; - -/// The plasma data source implements the [DataAvailabilityProvider] trait for the Plasma source. -#[derive(Debug, Clone, Copy)] -pub struct PlasmaDataSource -where - C: ChainProvider + Send + Clone, - F: PlasmaInputFetcher + Clone, - I: Iterator + Send + Clone, -{ - /// The chain provider. - pub chain_provider: C, - /// The plasma input fetcher. - pub plasma_input_fetcher: F, - /// The plasma iterator. - pub plasma_source: I, -} - -impl PlasmaDataSource -where - C: ChainProvider + Send + Clone + Debug, - F: PlasmaInputFetcher + Clone, - I: Iterator + Send + Clone, -{ - /// Creates a new [PlasmaDataSource] from the given providers. - pub fn new(chain_provider: C, plasma_input_fetcher: F, plasma_source: I) -> Self { - Self { chain_provider, plasma_input_fetcher, plasma_source } - } -} - -#[async_trait] -impl DataAvailabilityProvider for PlasmaDataSource -where - C: ChainProvider + Send + Clone + Debug + Sync, - F: PlasmaInputFetcher + Clone + Debug + Send + Sync, - I: Iterator + Send + Clone + Debug + Sync, -{ - type Item = Bytes; - type DataIter = PlasmaSource; - - async fn open_data(&self, block_ref: &BlockInfo) -> Result { - Ok(PlasmaSource::new( - self.chain_provider.clone(), - self.plasma_input_fetcher.clone(), - self.plasma_source.clone(), - block_ref.id(), - )) - } -} diff --git a/crates/plasma/src/source.rs b/crates/plasma/src/source.rs deleted file mode 100644 index 6eb433d7e..000000000 --- a/crates/plasma/src/source.rs +++ /dev/null @@ -1,287 +0,0 @@ -//! Plasma Data Source - -use crate::{ - traits::PlasmaInputFetcher, - types::{ - decode_keccak256, Keccak256Commitment, PlasmaError, MAX_INPUT_SIZE, TX_DATA_VERSION_1, - }, -}; -use alloc::boxed::Box; -use alloy_primitives::Bytes; -use anyhow::anyhow; -use async_trait::async_trait; -use kona_derive::{ - traits::{AsyncIterator, ChainProvider}, - types::{BlockID, ResetError, StageError, StageResult}, -}; - -/// A plasma data iterator. -#[derive(Debug, Clone)] -pub struct PlasmaSource -where - C: ChainProvider + Send, - F: PlasmaInputFetcher + Send, - I: Iterator, -{ - /// The chain provider to use for the plasma source. - pub chain_provider: C, - /// The plasma input fetcher. - pub input_fetcher: F, - /// A source data iterator. - pub source: I, - /// Keeps track of a pending commitment so we can keep trying to fetch the input. - pub commitment: Option, - /// The block id. - pub id: BlockID, -} - -impl PlasmaSource -where - C: ChainProvider + Send, - F: PlasmaInputFetcher + Send, - I: Iterator, -{ - /// Instantiates a new plasma data source. - pub fn new(chain_provider: C, input_fetcher: F, source: I, id: BlockID) -> Self { - Self { chain_provider, input_fetcher, source, id, commitment: None } - } -} - -#[async_trait] -impl AsyncIterator for PlasmaSource -where - C: ChainProvider + Send, - F: PlasmaInputFetcher + Send, - I: Iterator + Send, -{ - type Item = Bytes; - - async fn next(&mut self) -> StageResult { - // Process origin syncs the challenge contract events and updates the local challenge states - // before we can proceed to fetch the input data. This function can be called multiple times - // for the same origin and noop if the origin was already processed. It is also called if - // there is not commitment in the current origin. - match self.input_fetcher.advance_l1_origin(&self.chain_provider, self.id).await { - Some(Ok(_)) => { - tracing::debug!("plasma input fetcher - l1 origin advanced"); - } - Some(Err(PlasmaError::ReorgRequired)) => { - tracing::error!("new expired challenge"); - return StageResult::Err(StageError::Reset(ResetError::NewExpiredChallenge)); - } - Some(Err(e)) => { - tracing::error!("failed to advance plasma L1 origin: {:?}", e); - return StageResult::Err(StageError::Temporary(anyhow::anyhow!( - "failed to advance plasma L1 origin: {:?}", - e - ))); - } - None => { - tracing::warn!("l1 origin advance returned None"); - } - } - - // Set the commitment if it isn't available. - if self.commitment.is_none() { - // The l1 source returns the input commitment for the batch. - let data = match self.source.next().ok_or(PlasmaError::NotEnoughData) { - Ok(d) => d, - Err(e) => { - tracing::warn!("failed to pull next data from the plasma source iterator"); - return Err(StageError::Custom(anyhow!(e))); - } - }; - - // If the data is empty, - if data.is_empty() { - tracing::warn!("empty data from plasma source"); - return Err(StageError::Custom(anyhow!(PlasmaError::NotEnoughData))); - } - - // If the tx data type is not plasma, we forward it downstream to let the next - // steps validate and potentially parse it as L1 DA inputs. - if data[0] != TX_DATA_VERSION_1 { - tracing::info!("non-plasma tx data, forwarding downstream"); - return Ok(data); - } - - // Validate that the batcher inbox data is a commitment. - self.commitment = match decode_keccak256(&data[1..]) { - Ok(c) => Some(c), - Err(e) => { - tracing::warn!("invalid commitment: {}, err: {}", data, e); - return self.next().await; - } - }; - } - - // Use the commitment to fetch the input from the plasma DA provider. - let commitment = self.commitment.as_ref().expect("the commitment must be set"); - - // Fetch the input data from the plasma DA provider. - let data = match self - .input_fetcher - .get_input(&self.chain_provider, commitment.clone(), self.id) - .await - { - Some(Ok(data)) => data, - Some(Err(PlasmaError::ReorgRequired)) => { - // The plasma fetcher may call for a reorg if the pipeline is stalled and the plasma - // DA manager continued syncing origins detached from the pipeline - // origin. - tracing::warn!("challenge for a new previously derived commitment expired"); - return Err(StageError::Reset(ResetError::ReorgRequired)); - } - Some(Err(PlasmaError::ChallengeExpired)) => { - // This commitment was challenged and the challenge expired. - tracing::warn!("challenge expired, skipping batch"); - self.commitment = None; - // Skip the input. - return self.next().await; - } - Some(Err(PlasmaError::MissingPastWindow)) => { - tracing::warn!("missing past window, skipping batch"); - return Err(StageError::Critical(anyhow::anyhow!( - "data for commitment {:?} not available", - commitment - ))); - } - Some(Err(PlasmaError::ChallengePending)) => { - // Continue stepping without slowing down. - tracing::debug!("plasma challenge pending, proceeding"); - return Err(StageError::NotEnoughData); - } - Some(Err(e)) => { - // Return temporary error so we can keep retrying. - return Err(StageError::Temporary(anyhow::anyhow!( - "failed to fetch input data with comm {:?} from da service: {:?}", - commitment, - e - ))); - } - None => { - // Return temporary error so we can keep retrying. - return Err(StageError::Temporary(anyhow::anyhow!( - "failed to fetch input data with comm {:?} from da service", - commitment - ))); - } - }; - - // The data length is limited to a max size to ensure they can be challenged in the DA - // contract. - if data.len() > MAX_INPUT_SIZE { - tracing::warn!("input data (len {}) exceeds max size {MAX_INPUT_SIZE}", data.len()); - self.commitment = None; - return self.next().await; - } - - // Reset the commitment so we can fetch the next one from the source at the next iteration. - self.commitment = None; - - return Ok(data); - } -} - -#[cfg(test)] -mod tests { - use super::*; - use crate::test_utils::TestPlasmaInputFetcher; - use alloc::vec; - use kona_derive::{ - stages::test_utils::{CollectingLayer, TraceStorage}, - traits::test_utils::TestChainProvider, - }; - use tracing::Level; - use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; - - #[tokio::test] - async fn test_next_plasma_advance_origin_reorg_error() { - let chain_provider = TestChainProvider::default(); - let input_fetcher = TestPlasmaInputFetcher { - advances: vec![Err(PlasmaError::ReorgRequired)], - ..Default::default() - }; - let source = vec![Bytes::from("hello"), Bytes::from("world")].into_iter(); - let id = BlockID { number: 1, ..Default::default() }; - - let mut plasma_source = PlasmaSource::new(chain_provider, input_fetcher, source, id); - - let err = plasma_source.next().await.unwrap_err(); - assert_eq!(err, StageError::Reset(ResetError::NewExpiredChallenge)); - } - - #[tokio::test] - async fn test_next_plasma_advance_origin_other_error() { - let chain_provider = TestChainProvider::default(); - let input_fetcher = TestPlasmaInputFetcher { - advances: vec![Err(PlasmaError::NotEnoughData)], - ..Default::default() - }; - let source = vec![Bytes::from("hello"), Bytes::from("world")].into_iter(); - let id = BlockID { number: 1, ..Default::default() }; - - let mut plasma_source = PlasmaSource::new(chain_provider, input_fetcher, source, id); - - let err = plasma_source.next().await.unwrap_err(); - matches!(err, StageError::Temporary(_)); - } - - #[tokio::test] - async fn test_next_plasma_not_enough_source_data() { - let chain_provider = TestChainProvider::default(); - let input_fetcher = TestPlasmaInputFetcher { advances: vec![Ok(())], ..Default::default() }; - let source = vec![].into_iter(); - let id = BlockID { number: 1, ..Default::default() }; - - let mut plasma_source = PlasmaSource::new(chain_provider, input_fetcher, source, id); - - let err = plasma_source.next().await.unwrap_err(); - assert_eq!(err, StageError::Custom(anyhow!(PlasmaError::NotEnoughData))); - } - - #[tokio::test] - async fn test_next_plasma_empty_source_data() { - let trace_store: TraceStorage = Default::default(); - let layer = CollectingLayer::new(trace_store.clone()); - tracing_subscriber::Registry::default().with(layer).init(); - - let chain_provider = TestChainProvider::default(); - let input_fetcher = TestPlasmaInputFetcher { advances: vec![Ok(())], ..Default::default() }; - let source = vec![Bytes::from("")].into_iter(); - let id = BlockID { number: 1, ..Default::default() }; - - let mut plasma_source = PlasmaSource::new(chain_provider, input_fetcher, source, id); - - let err = plasma_source.next().await.unwrap_err(); - assert_eq!(err, StageError::Custom(anyhow!(PlasmaError::NotEnoughData))); - - let logs = trace_store.get_by_level(Level::WARN); - assert_eq!(logs.len(), 1); - assert!(logs[0].contains("empty data from plasma source")); - } - - #[tokio::test] - async fn test_next_plasma_non_plasma_tx_data_forwards() { - let trace_store: TraceStorage = Default::default(); - let layer = CollectingLayer::new(trace_store.clone()); - tracing_subscriber::Registry::default().with(layer).init(); - - let chain_provider = TestChainProvider::default(); - let input_fetcher = TestPlasmaInputFetcher { advances: vec![Ok(())], ..Default::default() }; - let first = Bytes::copy_from_slice(&[2u8]); - let source = vec![first.clone()].into_iter(); - let id = BlockID { number: 1, ..Default::default() }; - - let mut plasma_source = PlasmaSource::new(chain_provider, input_fetcher, source, id); - - let data = plasma_source.next().await.unwrap(); - assert_eq!(data, first); - - let logs = trace_store.get_by_level(Level::INFO); - assert_eq!(logs.len(), 1); - assert!(logs[0].contains("non-plasma tx data, forwarding downstream")); - } - - // TODO: more tests -} diff --git a/crates/plasma/src/test_utils.rs b/crates/plasma/src/test_utils.rs deleted file mode 100644 index 415129abe..000000000 --- a/crates/plasma/src/test_utils.rs +++ /dev/null @@ -1,56 +0,0 @@ -//! Test utilities for the `kona-plasma` crate. - -use crate::{ - traits::PlasmaInputFetcher, - types::{FinalizedHeadSignal, PlasmaError}, -}; -use alloc::{boxed::Box, vec::Vec}; -use alloy_primitives::Bytes; -use async_trait::async_trait; -use kona_derive::traits::test_utils::TestChainProvider; -use kona_primitives::{BlockID, BlockInfo, SystemConfig}; - -/// A mock plasma input fetcher for testing. -#[derive(Debug, Clone, Default)] -pub struct TestPlasmaInputFetcher { - /// Inputs to return. - pub inputs: Vec>, - /// Advance L1 origin results. - pub advances: Vec>, - /// Reset results. - pub resets: Vec>, -} - -#[async_trait] -impl PlasmaInputFetcher for TestPlasmaInputFetcher { - async fn get_input( - &mut self, - _fetcher: &TestChainProvider, - _commitment: Bytes, - _block: BlockID, - ) -> Option> { - self.inputs.pop() - } - - async fn advance_l1_origin( - &mut self, - _fetcher: &TestChainProvider, - _block: BlockID, - ) -> Option> { - self.advances.pop() - } - - async fn reset( - &mut self, - _block_number: BlockInfo, - _cfg: SystemConfig, - ) -> Option> { - self.resets.pop() - } - - async fn finalize(&mut self, _block_number: BlockInfo) -> Option> { - None - } - - fn on_finalized_head_signal(&mut self, _block_number: FinalizedHeadSignal) {} -} diff --git a/crates/plasma/src/traits.rs b/crates/plasma/src/traits.rs deleted file mode 100644 index 6529623cc..000000000 --- a/crates/plasma/src/traits.rs +++ /dev/null @@ -1,41 +0,0 @@ -//! This module contains traits for the plasma extension of the derivation pipeline. - -use crate::types::{FinalizedHeadSignal, PlasmaError}; -use alloc::boxed::Box; -use alloy_primitives::Bytes; -use async_trait::async_trait; -use kona_derive::traits::ChainProvider; -use kona_primitives::{BlockID, BlockInfo, SystemConfig}; - -/// A plasma input fetcher. -#[async_trait] -pub trait PlasmaInputFetcher { - /// Get the input for the given commitment at the given block number from the DA storage - /// service. - async fn get_input( - &mut self, - fetcher: &CP, - commitment: Bytes, - block: BlockID, - ) -> Option>; - - /// Advance the L1 origin to the given block number, syncing the DA challenge events. - async fn advance_l1_origin( - &mut self, - fetcher: &CP, - block: BlockID, - ) -> Option>; - - /// Reset the challenge origin in case of L1 reorg. - async fn reset( - &mut self, - block_number: BlockInfo, - cfg: SystemConfig, - ) -> Option>; - - /// Notify L1 finalized head so plasma finality is always behind L1. - async fn finalize(&mut self, block_number: BlockInfo) -> Option>; - - /// Set the engine finalization signal callback. - fn on_finalized_head_signal(&mut self, callback: FinalizedHeadSignal); -} diff --git a/crates/plasma/src/types.rs b/crates/plasma/src/types.rs deleted file mode 100644 index e158296ca..000000000 --- a/crates/plasma/src/types.rs +++ /dev/null @@ -1,67 +0,0 @@ -//! Types for the `kona-plasma` crate. - -use alloc::boxed::Box; -use alloy_primitives::Bytes; -use core::fmt::Display; -use kona_primitives::BlockInfo; - -/// A plasma error. -#[derive(Debug, Clone, Copy, Eq, PartialEq)] -pub enum PlasmaError { - /// A reorg is required. - ReorgRequired, - /// Not enough data. - NotEnoughData, - /// The commitment was challenge, but the challenge period expired. - ChallengeExpired, - /// Missing data past the challenge period. - MissingPastWindow, - /// A challenge is pending for the given commitment - ChallengePending, -} - -impl Display for PlasmaError { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - match self { - Self::ReorgRequired => write!(f, "reorg required"), - Self::NotEnoughData => write!(f, "not enough data"), - Self::ChallengeExpired => write!(f, "challenge expired"), - Self::MissingPastWindow => write!(f, "missing past window"), - Self::ChallengePending => write!(f, "challenge pending"), - } - } -} - -/// A callback method for the finalized head signal. -pub type FinalizedHeadSignal = Box; - -/// Max input size ensures the canonical chain cannot include input batches too large to -/// challenge in the Data Availability Challenge contract. Value in number of bytes. -/// This value can only be changed in a hard fork. -pub const MAX_INPUT_SIZE: usize = 130672; - -/// TxDataVersion1 is the version number for batcher transactions containing -/// plasma commitments. It should not collide with DerivationVersion which is still -/// used downstream when parsing the frames. -pub const TX_DATA_VERSION_1: u8 = 1; - -/// The default commitment type for the DA storage. -pub const KECCAK_256_COMMITMENT_TYPE: u8 = 0; - -/// The default commitment type. -pub type Keccak256Commitment = Bytes; - -/// DecodeKeccak256 validates and casts the commitment into a Keccak256Commitment. -pub fn decode_keccak256(commitment: &[u8]) -> Result { - if commitment.is_empty() { - return Err(PlasmaError::NotEnoughData); - } - if commitment[0] != KECCAK_256_COMMITMENT_TYPE { - return Err(PlasmaError::NotEnoughData); - } - let c = &commitment[1..]; - if c.len() != 32 { - return Err(PlasmaError::NotEnoughData); - } - Ok(Bytes::copy_from_slice(c)) -}