diff --git a/crates/derive/src/lib.rs b/crates/derive/src/lib.rs index aea6a7c9e..0349da6ab 100644 --- a/crates/derive/src/lib.rs +++ b/crates/derive/src/lib.rs @@ -8,12 +8,15 @@ #![deny(unused_must_use, rust_2018_idioms)] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![no_std] -// Temp -#![allow(dead_code, unused, unreachable_pub)] extern crate alloc; -pub mod params; +mod params; +pub use params::{ + ChannelID, CHANNEL_ID_LENGTH, DERIVATION_VERSION_0, FRAME_OVERHEAD, MAX_CHANNEL_BANK_SIZE, + MAX_RLP_BYTES_PER_CHANNEL, MAX_SPAN_BATCH_BYTES, +}; + pub mod stages; pub mod traits; pub mod types; diff --git a/crates/derive/src/stages/channel_bank.rs b/crates/derive/src/stages/channel_bank.rs index f214efe1c..6293a6d14 100644 --- a/crates/derive/src/stages/channel_bank.rs +++ b/crates/derive/src/stages/channel_bank.rs @@ -1,6 +1,6 @@ //! This module contains the `ChannelBank` struct. -use super::{frame_queue::FrameQueue, l1_retrieval::L1Retrieval}; +use super::frame_queue::FrameQueue; use crate::{ params::{ChannelID, MAX_CHANNEL_BANK_SIZE}, traits::{ChainProvider, DataAvailabilityProvider, ResettableStage}, @@ -8,8 +8,9 @@ use crate::{ }; use alloc::{boxed::Box, collections::VecDeque}; use alloy_primitives::Bytes; -use anyhow::{anyhow, bail}; +use anyhow::anyhow; use async_trait::async_trait; +use core::fmt::Debug; use hashbrown::HashMap; /// [ChannelBank] is a stateful stage that does the following: @@ -23,10 +24,11 @@ use hashbrown::HashMap; /// Specifically, the channel bank is not allowed to become too large between successive calls /// to `IngestData`. This means that we can do an ingest and then do a read while becoming too large. /// [ChannelBank] buffers channel frames, and emits full channel data +#[derive(Debug)] pub struct ChannelBank where - DAP: DataAvailabilityProvider, - CP: ChainProvider, + DAP: DataAvailabilityProvider + Debug, + CP: ChainProvider + Debug, { /// The rollup configuration. cfg: RollupConfig, @@ -36,23 +38,20 @@ where channel_queue: VecDeque, /// The previous stage of the derivation pipeline. prev: FrameQueue, - /// Chain provider. - chain_provider: CP, } impl ChannelBank where - DAP: DataAvailabilityProvider, - CP: ChainProvider, + DAP: DataAvailabilityProvider + Debug, + CP: ChainProvider + Debug, { /// Create a new [ChannelBank] stage. - pub fn new(cfg: RollupConfig, prev: FrameQueue, chain_provider: CP) -> Self { + pub fn new(cfg: RollupConfig, prev: FrameQueue) -> Self { Self { cfg, channels: HashMap::new(), channel_queue: VecDeque::new(), prev, - chain_provider, } } @@ -162,7 +161,7 @@ where // Load the data into the channel bank let frame = self.prev.next_frame().await?; - self.ingest_frame(frame); + self.ingest_frame(frame)?; Err(StageError::NotEnoughData) } @@ -193,10 +192,10 @@ where #[async_trait] impl ResettableStage for ChannelBank where - DAP: DataAvailabilityProvider + Send, - CP: ChainProvider + Send, + DAP: DataAvailabilityProvider + Send + Debug, + CP: ChainProvider + Send + Debug, { - async fn reset(&mut self, base: BlockInfo, cfg: SystemConfig) -> StageResult<()> { + async fn reset(&mut self, _: BlockInfo, _: SystemConfig) -> StageResult<()> { self.channels.clear(); self.channel_queue = VecDeque::with_capacity(10); Err(StageError::Eof) diff --git a/crates/derive/src/stages/frame_queue.rs b/crates/derive/src/stages/frame_queue.rs index 5fbe138ff..f0900a91b 100644 --- a/crates/derive/src/stages/frame_queue.rs +++ b/crates/derive/src/stages/frame_queue.rs @@ -1,19 +1,22 @@ //! This module contains the [FrameQueue] stage of the derivation pipeline. +use core::fmt::Debug; + use super::l1_retrieval::L1Retrieval; use crate::{ traits::{ChainProvider, DataAvailabilityProvider, ResettableStage}, types::{BlockInfo, Frame, StageError, StageResult, SystemConfig}, }; use alloc::{boxed::Box, collections::VecDeque}; -use alloy_primitives::Bytes; -use anyhow::{anyhow, bail, Result}; +use anyhow::anyhow; use async_trait::async_trait; +/// The frame queue stage of the derivation pipeline. +#[derive(Debug)] pub struct FrameQueue where - DAP: DataAvailabilityProvider, - CP: ChainProvider, + DAP: DataAvailabilityProvider + Debug, + CP: ChainProvider + Debug, { /// The previous stage in the pipeline. pub prev: L1Retrieval, @@ -23,8 +26,8 @@ where impl FrameQueue where - DAP: DataAvailabilityProvider, - CP: ChainProvider, + DAP: DataAvailabilityProvider + Debug, + CP: ChainProvider + Debug, { /// Create a new frame queue stage. pub fn new(prev: L1Retrieval) -> Self { @@ -67,10 +70,10 @@ where #[async_trait] impl ResettableStage for FrameQueue where - DAP: DataAvailabilityProvider + Send, - CP: ChainProvider + Send, + DAP: DataAvailabilityProvider + Send + Debug, + CP: ChainProvider + Send + Debug, { - async fn reset(&mut self, base: BlockInfo, cfg: SystemConfig) -> StageResult<()> { + async fn reset(&mut self, _: BlockInfo, _: SystemConfig) -> StageResult<()> { self.queue = VecDeque::default(); Err(StageError::Eof) } diff --git a/crates/derive/src/stages/l1_retrieval.rs b/crates/derive/src/stages/l1_retrieval.rs index e73bcb053..d830043ac 100644 --- a/crates/derive/src/stages/l1_retrieval.rs +++ b/crates/derive/src/stages/l1_retrieval.rs @@ -5,7 +5,7 @@ use crate::{ traits::{ChainProvider, DataAvailabilityProvider, DataIter, ResettableStage}, types::{BlockInfo, StageError, StageResult, SystemConfig}, }; -use alloc::{boxed::Box, vec::Vec}; +use alloc::boxed::Box; use alloy_primitives::Bytes; use anyhow::anyhow; use async_trait::async_trait; diff --git a/crates/derive/src/stages/l1_traversal.rs b/crates/derive/src/stages/l1_traversal.rs index ff83591bc..253611050 100644 --- a/crates/derive/src/stages/l1_traversal.rs +++ b/crates/derive/src/stages/l1_traversal.rs @@ -5,7 +5,7 @@ use crate::{ types::{BlockInfo, RollupConfig, StageError, StageResult, SystemConfig}, }; use alloc::boxed::Box; -use anyhow::{anyhow, bail}; +use anyhow::anyhow; use async_trait::async_trait; /// The L1 traversal stage of the derivation pipeline. diff --git a/crates/derive/src/stages/mod.rs b/crates/derive/src/stages/mod.rs index e7b700db7..b1e079bbf 100644 --- a/crates/derive/src/stages/mod.rs +++ b/crates/derive/src/stages/mod.rs @@ -15,10 +15,16 @@ mod l1_traversal; pub use l1_traversal::L1Traversal; -mod batch_queue; +mod l1_retrieval; +pub use l1_retrieval::L1Retrieval; + +mod frame_queue; +pub use frame_queue::FrameQueue; + mod channel_bank; +pub use channel_bank::ChannelBank; + +mod batch_queue; mod channel_reader; mod engine_queue; -mod frame_queue; -mod l1_retrieval; mod payload_derivation; diff --git a/crates/derive/src/traits/data_sources.rs b/crates/derive/src/traits/data_sources.rs index 14f0ffe3e..69ccee18e 100644 --- a/crates/derive/src/traits/data_sources.rs +++ b/crates/derive/src/traits/data_sources.rs @@ -1,11 +1,11 @@ //! Contains traits that describe the functionality of various data sources used in the derivation pipeline's stages. -// use alloy_rpc_types::Block; use crate::types::{BlockInfo, Receipt, StageResult}; use alloc::{boxed::Box, vec::Vec}; use alloy_primitives::{Address, Bytes, B256}; use anyhow::Result; use async_trait::async_trait; +use core::fmt::Debug; /// Describes the functionality of a data source that can provide information from the blockchain. #[async_trait] @@ -22,7 +22,7 @@ pub trait ChainProvider { #[async_trait] pub trait DataAvailabilityProvider { /// A data iterator for the data source to return. - type DataIter>: DataIter + Send; + type DataIter>: DataIter + Send + Debug; /// Returns the data availability for the block with the given hash, or an error if the block does not exist in the /// data source. diff --git a/crates/derive/src/types/channel.rs b/crates/derive/src/types/channel.rs index bb8316b6b..b732e0b01 100644 --- a/crates/derive/src/types/channel.rs +++ b/crates/derive/src/types/channel.rs @@ -157,11 +157,10 @@ impl Channel { #[cfg(test)] mod test { + use std::println; + use super::Channel; - use crate::{ - params::ChannelID, - types::{BlockInfo, Frame}, - }; + use crate::types::{BlockInfo, Frame}; use alloc::{ string::{String, ToString}, vec, @@ -178,6 +177,8 @@ mod test { } fn run_frame_validity_test(test_case: FrameValidityTestCase) { + println!("Running test: {}", test_case.name); + let id = [0xFF; 16]; let block = BlockInfo::default(); let mut channel = Channel::new(id, block); diff --git a/crates/derive/src/types/eips/merge.rs b/crates/derive/src/types/eips/merge.rs index dac534b62..6dbc0c621 100644 --- a/crates/derive/src/types/eips/merge.rs +++ b/crates/derive/src/types/eips/merge.rs @@ -1,5 +1,7 @@ //! Constants related to the beacon chain consensus. +#![allow(unreachable_pub, unused)] + /// An EPOCH is a series of 32 slots. pub const EPOCH_SLOTS: u64 = 32; diff --git a/crates/derive/src/types/frame.rs b/crates/derive/src/types/frame.rs index 69428756e..d6ee9eed7 100644 --- a/crates/derive/src/types/frame.rs +++ b/crates/derive/src/types/frame.rs @@ -63,6 +63,11 @@ impl Frame { .try_into() .map_err(|e| anyhow!("Error: {e}"))?, ) as usize; + + if data_len > MAX_FRAME_LEN { + bail!("Frame data too large"); + } + let data = encoded[22..22 + data_len].to_vec(); let is_last = encoded[22 + data_len] != 0; Ok(( diff --git a/crates/derive/src/types/mod.rs b/crates/derive/src/types/mod.rs index 8a0229f89..3632c9df9 100644 --- a/crates/derive/src/types/mod.rs +++ b/crates/derive/src/types/mod.rs @@ -1,7 +1,7 @@ //! This module contains all of the types used within the derivation pipeline. mod system_config; -pub use system_config::{SystemAccounts, SystemConfig}; +pub use system_config::{SystemAccounts, SystemConfig, SystemConfigUpdateType}; mod rollup_config; pub use rollup_config::RollupConfig; diff --git a/crates/derive/src/types/network/mod.rs b/crates/derive/src/types/network/mod.rs index a36d88a13..b9762275d 100644 --- a/crates/derive/src/types/network/mod.rs +++ b/crates/derive/src/types/network/mod.rs @@ -1,5 +1,7 @@ //! `alloy-network` crate ported to `no_std`. +#![allow(unused, unreachable_pub)] + use crate::types::eips::eip2718::Eip2718Envelope; use alloc::vec::Vec; use alloy_primitives::B256; diff --git a/crates/derive/src/types/system_config.rs b/crates/derive/src/types/system_config.rs index dc5e79b0c..0775cc8cb 100644 --- a/crates/derive/src/types/system_config.rs +++ b/crates/derive/src/types/system_config.rs @@ -2,7 +2,7 @@ use super::{Receipt, RollupConfig}; use alloy_primitives::{address, b256, Address, Log, B256, U256}; -use alloy_sol_types::{sol, SolType, SolValue}; +use alloy_sol_types::{sol, SolType}; use anyhow::{anyhow, bail, Result}; /// `keccak256("ConfigUpdate(uint256,uint8,bytes)")` @@ -35,9 +35,13 @@ pub struct SystemConfig { #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[repr(u64)] pub enum SystemConfigUpdateType { + /// Batcher update type Batcher = 0, + /// Gas config update type GasConfig = 1, + /// Gas limit update type GasLimit = 2, + /// Unsafe block signer update type UnsafeBlockSigner = 3, } @@ -125,19 +129,19 @@ impl SystemConfig { } let pointer = ::abi_decode(&log_data[0..32], true) - .map_err(|e| anyhow!("Failed to decode batcher update log"))?; + .map_err(|_| anyhow!("Failed to decode batcher update log"))?; if pointer != 32 { bail!("Invalid config update log: invalid data pointer"); } let length = ::abi_decode(&log_data[32..64], true) - .map_err(|e| anyhow!("Failed to decode batcher update log"))?; + .map_err(|_| anyhow!("Failed to decode batcher update log"))?; if length != 32 { bail!("Invalid config update log: invalid data length"); } let batcher_address = ::abi_decode(&log.data.data.as_ref()[64..], true) - .map_err(|e| anyhow!("Failed to decode batcher update log"))?; + .map_err(|_| anyhow!("Failed to decode batcher update log"))?; self.batcher_addr = batcher_address; } SystemConfigUpdateType::GasConfig => { @@ -146,20 +150,20 @@ impl SystemConfig { } let pointer = ::abi_decode(&log_data[0..32], true) - .map_err(|e| anyhow!("Invalid config update log: invalid data pointer"))?; + .map_err(|_| anyhow!("Invalid config update log: invalid data pointer"))?; if pointer != 32 { bail!("Invalid config update log: invalid data pointer"); } let length = ::abi_decode(&log_data[32..64], true) - .map_err(|e| anyhow!("Invalid config update log: invalid data length"))?; + .map_err(|_| anyhow!("Invalid config update log: invalid data length"))?; if length != 64 { bail!("Invalid config update log: invalid data length"); } let overhead = ::abi_decode(&log_data[64..96], true) - .map_err(|e| anyhow!("Invalid config update log: invalid overhead"))?; + .map_err(|_| anyhow!("Invalid config update log: invalid overhead"))?; let scalar = ::abi_decode(&log_data[96..], true) - .map_err(|e| anyhow!("Invalid config update log: invalid scalar"))?; + .map_err(|_| anyhow!("Invalid config update log: invalid scalar"))?; if rollup_config.is_ecotone_active(l1_time) { if RollupConfig::check_ecotone_l1_system_config_scalar(scalar.to_be_bytes()) @@ -184,18 +188,18 @@ impl SystemConfig { } let pointer = ::abi_decode(&log_data[0..32], true) - .map_err(|e| anyhow!("Invalid config update log: invalid data pointer"))?; + .map_err(|_| anyhow!("Invalid config update log: invalid data pointer"))?; if pointer != 32 { bail!("Invalid config update log: invalid data pointer"); } let length = ::abi_decode(&log_data[32..64], true) - .map_err(|e| anyhow!("Invalid config update log: invalid data length"))?; + .map_err(|_| anyhow!("Invalid config update log: invalid data length"))?; if length != 32 { bail!("Invalid config update log: invalid data length"); } let gas_limit = ::abi_decode(&log_data[64..], true) - .map_err(|e| anyhow!("Invalid config update log: invalid gas limit"))?; + .map_err(|_| anyhow!("Invalid config update log: invalid gas limit"))?; self.gas_limit = gas_limit; } SystemConfigUpdateType::UnsafeBlockSigner => { @@ -235,7 +239,7 @@ mod test { use super::*; use alloc::vec; - use alloy_primitives::{hex, Bytes, LogData}; + use alloy_primitives::{hex, LogData}; extern crate std; diff --git a/crates/derive/src/types/transaction/deposit.rs b/crates/derive/src/types/transaction/deposit.rs index 184d15703..0003df168 100644 --- a/crates/derive/src/types/transaction/deposit.rs +++ b/crates/derive/src/types/transaction/deposit.rs @@ -113,11 +113,7 @@ impl TxDeposit { /// /// NOTE: Deposit transactions are not signed, so this function does not encode a signature, /// just the header and transaction rlp. - pub(crate) fn encode_with_signature( - &self, - signature: &Signature, - out: &mut dyn alloy_rlp::BufMut, - ) { + pub(crate) fn encode_with_signature(&self, _: &Signature, out: &mut dyn alloy_rlp::BufMut) { let payload_length = self.fields_len(); let header = Header { list: true, @@ -128,6 +124,7 @@ impl TxDeposit { } /// Output the length of the RLP signed transaction encoding. This encodes with a RLP header. + #[allow(unused)] pub(crate) fn payload_len(&self) -> usize { let payload_length = self.fields_len(); // 'tx type' + 'header length' + 'payload length' @@ -135,6 +132,7 @@ impl TxDeposit { length_of_length(len) + len } + #[allow(unused)] pub(crate) fn payload_len_without_header(&self) -> usize { let payload_length = self.fields_len(); // 'transaction type byte length' + 'header length' + 'payload length' @@ -256,7 +254,7 @@ impl Transaction for TxDeposit { None } - fn set_chain_id(&mut self, chain_id: ChainId) { + fn set_chain_id(&mut self, _: ChainId) { unreachable!("Deposit transactions do not have a chain id"); } @@ -264,7 +262,7 @@ impl Transaction for TxDeposit { 0 } - fn set_nonce(&mut self, nonce: u64) { + fn set_nonce(&mut self, _: u64) { unreachable!("Deposit transactions do not have a nonce"); }