diff --git a/crates/evm/src/block/receipt.rs b/crates/evm/src/block/receipt.rs index c2bf1d3..590b564 100644 --- a/crates/evm/src/block/receipt.rs +++ b/crates/evm/src/block/receipt.rs @@ -46,7 +46,7 @@ impl ReceiptBuilder for MorphReceiptBuilder { MorphTxType::Eip1559 => MorphReceipt::Eip1559(MorphTransactionReceipt::new(inner)), MorphTxType::Eip7702 => MorphReceipt::Eip7702(MorphTransactionReceipt::new(inner)), MorphTxType::L1Msg => MorphReceipt::L1Msg(inner), - MorphTxType::AltFee => MorphReceipt::AltFee(MorphTransactionReceipt::new(inner)), + MorphTxType::Morph => MorphReceipt::Morph(MorphTransactionReceipt::new(inner)), } } } diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index 39c8421..d40f384 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -8,13 +8,13 @@ //! Morph L2 extends Ethereum's transaction types with: //! //! - [`TxL1Msg`]: L1 message transactions (type `0x7E`) - deposits from L1 -//! - [`TxAltFee`]: Alternative fee transactions (type `0x7F`) - pay gas with ERC20 tokens +//! - [`TxMorph`]: Morph transactions (type `0x7F`) - pay gas with ERC20 tokens //! - [`MorphTxEnvelope`]: Transaction envelope containing all supported transaction types //! //! # Receipt Types //! //! - [`MorphReceipt`]: Receipt enum for all transaction types -//! - [`MorphTransactionReceipt`]: Extended receipt with L1 fee and AltFee fields +//! - [`MorphTransactionReceipt`]: Extended receipt with L1 fee and Morph transaction fields //! //! # Block Types //! @@ -61,7 +61,7 @@ pub use receipt::{MorphReceipt, MorphReceiptWithBloom, MorphTransactionReceipt}; // Re-export transaction types pub use transaction::{ - ALT_FEE_TX_TYPE_ID, L1_TX_TYPE_ID, MorphTxEnvelope, MorphTxType, TxAltFee, TxAltFeeExt, TxL1Msg, + L1_TX_TYPE_ID, MORPH_TX_TYPE_ID, MorphTxEnvelope, MorphTxType, TxL1Msg, TxMorph, TxMorphExt, }; /// A [`NodePrimitives`] implementation for Morph. diff --git a/crates/primitives/src/receipt/mod.rs b/crates/primitives/src/receipt/mod.rs index 06e6d11..bad6ebf 100644 --- a/crates/primitives/src/receipt/mod.rs +++ b/crates/primitives/src/receipt/mod.rs @@ -1,7 +1,7 @@ //! Morph receipt types. //! //! This module provides: -//! - [`MorphTransactionReceipt`]: Receipt with L1 fee and AltFee fields +//! - [`MorphTransactionReceipt`]: Receipt with L1 fee and Morph transaction fields //! - [`MorphReceipt`]: Typed receipt enum for different transaction types #[allow(clippy::module_inception)] @@ -22,7 +22,7 @@ use reth_primitives_traits::InMemorySize; /// /// This enum wraps different receipt types based on the transaction type. /// For L1 messages, it uses a standard receipt without L1 fee. -/// For other transactions, it uses [`MorphTransactionReceipt`] with L1 fee and optional AltFee fields. +/// For other transactions, it uses [`MorphTransactionReceipt`] with L1 fee and optional Morph transaction fields. #[derive(Clone, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum MorphReceipt { @@ -36,8 +36,8 @@ pub enum MorphReceipt { Eip7702(MorphTransactionReceipt), /// L1 message receipt (no L1 fee since it's pre-paid on L1) L1Msg(Receipt), - /// AltFee receipt - AltFee(MorphTransactionReceipt), + /// Morph transaction receipt + Morph(MorphTransactionReceipt), } impl Default for MorphReceipt { @@ -55,7 +55,7 @@ impl MorphReceipt { Self::Eip1559(_) => MorphTxType::Eip1559, Self::Eip7702(_) => MorphTxType::Eip7702, Self::L1Msg(_) => MorphTxType::L1Msg, - Self::AltFee(_) => MorphTxType::AltFee, + Self::Morph(_) => MorphTxType::Morph, } } @@ -66,7 +66,7 @@ impl MorphReceipt { | Self::Eip2930(receipt) | Self::Eip1559(receipt) | Self::Eip7702(receipt) - | Self::AltFee(receipt) => &receipt.inner, + | Self::Morph(receipt) => &receipt.inner, Self::L1Msg(receipt) => receipt, } } @@ -78,7 +78,7 @@ impl MorphReceipt { | Self::Eip2930(r) | Self::Eip1559(r) | Self::Eip7702(r) - | Self::AltFee(r) => r.l1_fee, + | Self::Morph(r) => r.l1_fee, Self::L1Msg(_) => None, } } @@ -95,7 +95,7 @@ impl MorphReceipt { | Self::Eip2930(r) | Self::Eip1559(r) | Self::Eip7702(r) - | Self::AltFee(r) => r.rlp_encoded_fields_length_with_bloom(bloom), + | Self::Morph(r) => r.rlp_encoded_fields_length_with_bloom(bloom), Self::L1Msg(r) => r.rlp_encoded_fields_length_with_bloom(bloom), } } @@ -107,7 +107,7 @@ impl MorphReceipt { | Self::Eip2930(r) | Self::Eip1559(r) | Self::Eip7702(r) - | Self::AltFee(r) => r.rlp_encode_fields_with_bloom(bloom, out), + | Self::Morph(r) => r.rlp_encode_fields_with_bloom(bloom, out), Self::L1Msg(r) => r.rlp_encode_fields_with_bloom(bloom, out), } } @@ -140,7 +140,7 @@ impl MorphReceipt { | Self::Eip2930(r) | Self::Eip1559(r) | Self::Eip7702(r) - | Self::AltFee(r) => { + | Self::Morph(r) => { r.inner.status.length() + r.inner.cumulative_gas_used.length() + r.inner.logs.length() @@ -159,7 +159,7 @@ impl MorphReceipt { | Self::Eip2930(r) | Self::Eip1559(r) | Self::Eip7702(r) - | Self::AltFee(r) => { + | Self::Morph(r) => { r.inner.status.encode(out); r.inner.cumulative_gas_used.encode(out); r.inner.logs.encode(out); @@ -206,7 +206,7 @@ impl MorphReceipt { MorphTxType::Eip1559 => Ok(Self::Eip1559(MorphTransactionReceipt::new(inner))), MorphTxType::Eip7702 => Ok(Self::Eip7702(MorphTransactionReceipt::new(inner))), MorphTxType::L1Msg => Ok(Self::L1Msg(inner)), - MorphTxType::AltFee => Ok(Self::AltFee(MorphTransactionReceipt::new(inner))), + MorphTxType::Morph => Ok(Self::Morph(MorphTransactionReceipt::new(inner))), } } @@ -228,7 +228,7 @@ impl MorphReceipt { MorphTxType::Eip1559 => Self::Eip1559(MorphTransactionReceipt::new(inner)), MorphTxType::Eip7702 => Self::Eip7702(MorphTransactionReceipt::new(inner)), MorphTxType::L1Msg => Self::L1Msg(inner), - MorphTxType::AltFee => Self::AltFee(MorphTransactionReceipt::new(inner)), + MorphTxType::Morph => Self::Morph(MorphTransactionReceipt::new(inner)), }; Ok(ReceiptWithBloom { @@ -476,7 +476,7 @@ mod compact { | MorphReceipt::Eip2930(r) | MorphReceipt::Eip1559(r) | MorphReceipt::Eip7702(r) - | MorphReceipt::AltFee(r) => ( + | MorphReceipt::Morph(r) => ( r.l1_fee, r.fee_token_id.map(u64::from), r.fee_rate, @@ -540,7 +540,7 @@ mod compact { MorphTxType::Eip1559 => Self::Eip1559(morph_receipt), MorphTxType::Eip7702 => Self::Eip7702(morph_receipt), MorphTxType::L1Msg => unreachable!("L1Msg handled above"), - MorphTxType::AltFee => Self::AltFee(morph_receipt), + MorphTxType::Morph => Self::Morph(morph_receipt), } } } @@ -615,15 +615,15 @@ mod tests { }) } - /// Creates an AltFee receipt for testing. - fn create_alt_fee_receipt() -> MorphReceipt { + /// Creates a Morph transaction receipt for testing. + fn create_morph_receipt() -> MorphReceipt { let inner = Receipt { status: false.into(), cumulative_gas_used: 50000, logs: vec![], }; - MorphReceipt::AltFee(MorphTransactionReceipt::with_alt_fee( + MorphReceipt::Morph(MorphTransactionReceipt::with_morph_tx( inner, U256::from(2000), // l1_fee 1, // fee_token_id @@ -641,8 +641,8 @@ mod tests { let l1_msg = MorphReceipt::L1Msg(Receipt::default()); assert_eq!(l1_msg.tx_type(), MorphTxType::L1Msg); - let alt_fee = MorphReceipt::AltFee(MorphTransactionReceipt::default()); - assert_eq!(alt_fee.tx_type(), MorphTxType::AltFee); + let morph = MorphReceipt::Morph(MorphTransactionReceipt::default()); + assert_eq!(morph.tx_type(), MorphTxType::Morph); } #[test] @@ -762,23 +762,23 @@ mod tests { assert!(decoded.is_l1_message()); } - /// Tests that EIP-2718 encoding and decoding roundtrips correctly for AltFee receipt. + /// Tests that EIP-2718 encoding and decoding roundtrips correctly for Morph receipt. #[test] - fn test_alt_fee_receipt_encode_2718_roundtrip() { - let original = create_alt_fee_receipt(); + fn test_morph_receipt_encode_2718_roundtrip() { + let original = create_morph_receipt(); // Encode let mut encoded = Vec::new(); original.encode_2718(&mut encoded); // Verify type byte - assert_eq!(encoded[0], MorphTxType::AltFee as u8); + assert_eq!(encoded[0], MorphTxType::Morph as u8); // Decode let decoded = MorphReceipt::decode_2718(&mut encoded.as_slice()).unwrap(); // Verify fields - assert_eq!(decoded.tx_type(), MorphTxType::AltFee); + assert_eq!(decoded.tx_type(), MorphTxType::Morph); assert_eq!(decoded.status(), original.status()); assert_eq!( decoded.cumulative_gas_used(), @@ -887,7 +887,7 @@ mod tests { (MorphTxType::Legacy, create_legacy_receipt()), (MorphTxType::Eip1559, create_test_receipt()), (MorphTxType::L1Msg, create_l1_msg_receipt()), - (MorphTxType::AltFee, create_alt_fee_receipt()), + (MorphTxType::Morph, create_morph_receipt()), ]; for (expected_type, original) in receipts { diff --git a/crates/primitives/src/receipt/receipt.rs b/crates/primitives/src/receipt/receipt.rs index 9495877..fd5751e 100644 --- a/crates/primitives/src/receipt/receipt.rs +++ b/crates/primitives/src/receipt/receipt.rs @@ -2,20 +2,20 @@ //! //! This module defines the Morph-specific receipt types that include: //! - L1 data fee for rollup transactions -//! - AltFee fields for alternative fee token transactions +//! - Morph transaction fields for alternative fee token transactions use alloy_consensus::{Eip658Value, Receipt, ReceiptWithBloom, TxReceipt}; use alloy_primitives::{Bloom, Log, U256}; use alloy_rlp::{BufMut, Decodable, Encodable, Header}; -/// Morph transaction receipt with L1 fee and AltFee fields. +/// Morph transaction receipt with L1 fee and Morph transaction fields. /// /// This receipt extends the standard Ethereum receipt with: /// - `l1_fee`: The L1 data fee charged for posting transaction data to L1 -/// - `fee_token_id`: The ERC20 token ID used for fee payment (AltFee) +/// - `fee_token_id`: The ERC20 token ID used for fee payment (TxMorph) /// - `fee_rate`: The exchange rate for the fee token /// - `token_scale`: The scale factor for the token -/// - `fee_limit`: The fee limit for AltFee transactions +/// - `fee_limit`: The fee limit for TxMorph #[derive(Clone, Debug, Default, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] @@ -32,8 +32,8 @@ pub struct MorphTransactionReceipt { )] pub l1_fee: Option, - /// The ERC20 token ID used for fee payment (AltFee feature). - /// Only present for AltFee transactions. + /// The ERC20 token ID used for fee payment (TxMorph feature). + /// Only present for TxMorph. #[cfg_attr( feature = "serde", serde(default, skip_serializing_if = "Option::is_none") @@ -41,7 +41,7 @@ pub struct MorphTransactionReceipt { pub fee_token_id: Option, /// The exchange rate for the fee token. - /// Only present for AltFee transactions. + /// Only present for TxMorph. #[cfg_attr( feature = "serde", serde(default, skip_serializing_if = "Option::is_none") @@ -49,15 +49,15 @@ pub struct MorphTransactionReceipt { pub fee_rate: Option, /// The scale factor for the token. - /// Only present for AltFee transactions. + /// Only present for TxMorph. #[cfg_attr( feature = "serde", serde(default, skip_serializing_if = "Option::is_none") )] pub token_scale: Option, - /// The fee limit for the AltFee transaction. - /// Only present for AltFee transactions. + /// The fee limit for the TxMorph. + /// Only present for TxMorph. #[cfg_attr( feature = "serde", serde(default, skip_serializing_if = "Option::is_none") @@ -90,8 +90,8 @@ impl MorphTransactionReceipt { } } - /// Creates a new receipt with AltFee fields. - pub const fn with_alt_fee( + /// Creates a new receipt with TxMorph fields. + pub const fn with_morph_tx( inner: Receipt, l1_fee: U256, fee_token_id: u16, @@ -109,8 +109,8 @@ impl MorphTransactionReceipt { } } - /// Returns true if this receipt is for an AltFee transaction. - pub const fn is_alt_fee(&self) -> bool { + /// Returns true if this receipt is for a TxMorph. + pub const fn is_morph_tx(&self) -> bool { self.fee_token_id.is_some() } @@ -136,7 +136,7 @@ impl MorphTransactionReceipt { impl MorphTransactionReceipt { /// Returns length of RLP-encoded receipt fields with the given [`Bloom`] without an RLP header. /// - /// Note: L1 fee and AltFee fields are NOT included in the RLP encoding for consensus, + /// Note: L1 fee and TxMorph fields are NOT included in the RLP encoding for consensus, /// matching go-ethereum's behavior. pub fn rlp_encoded_fields_length_with_bloom(&self, bloom: &Bloom) -> usize { self.inner.rlp_encoded_fields_length_with_bloom(bloom) @@ -144,7 +144,7 @@ impl MorphTransactionReceipt { /// RLP-encodes receipt fields with the given [`Bloom`] without an RLP header. /// - /// Note: L1 fee and AltFee fields are NOT included in the RLP encoding for consensus, + /// Note: L1 fee and TxMorph fields are NOT included in the RLP encoding for consensus, /// matching go-ethereum's behavior. pub fn rlp_encode_fields_with_bloom(&self, bloom: &Bloom, out: &mut dyn BufMut) { self.inner.rlp_encode_fields_with_bloom(bloom, out); @@ -251,7 +251,7 @@ mod tests { assert_eq!(receipt.cumulative_gas_used(), 21000); assert!(receipt.l1_fee.is_none()); assert!(receipt.fee_token_id.is_none()); - assert!(!receipt.is_alt_fee()); + assert!(!receipt.is_morph_tx()); } #[test] @@ -266,11 +266,11 @@ mod tests { assert_eq!(receipt.l1_fee, Some(l1_fee)); assert_eq!(receipt.l1_fee_or_zero(), l1_fee); - assert!(!receipt.is_alt_fee()); + assert!(!receipt.is_morph_tx()); } #[test] - fn test_morph_receipt_with_alt_fee() { + fn test_morph_receipt_with_morph_tx() { let inner: Receipt = Receipt { status: true.into(), cumulative_gas_used: 21000, @@ -282,7 +282,7 @@ mod tests { let token_scale = U256::from(18); let fee_limit = U256::from(5000000); - let receipt = MorphTransactionReceipt::with_alt_fee( + let receipt = MorphTransactionReceipt::with_morph_tx( inner, l1_fee, fee_token_id, @@ -291,7 +291,7 @@ mod tests { fee_limit, ); - assert!(receipt.is_alt_fee()); + assert!(receipt.is_morph_tx()); assert_eq!(receipt.fee_token_id, Some(fee_token_id)); assert_eq!(receipt.fee_rate, Some(fee_rate)); assert_eq!(receipt.token_scale, Some(token_scale)); diff --git a/crates/primitives/src/transaction/envelope.rs b/crates/primitives/src/transaction/envelope.rs index 23c6587..efcec41 100644 --- a/crates/primitives/src/transaction/envelope.rs +++ b/crates/primitives/src/transaction/envelope.rs @@ -5,7 +5,7 @@ use alloy_eips::eip2718::Encodable2718; use alloy_primitives::{B256, Bytes}; use alloy_rlp::BytesMut; -use crate::{TxAltFee, TxL1Msg}; +use crate::{TxL1Msg, TxMorph}; #[derive(Debug, Clone, TransactionEnvelope)] #[envelope(tx_type_name = MorphTxType)] @@ -30,9 +30,9 @@ pub enum MorphTxEnvelope { #[envelope(ty = 0x7e)] L1Msg(Sealed), - /// Alt Fee Transaction + /// Morph Transaction #[envelope(ty = 0x7f)] - AltFee(Signed), + Morph(Signed), } impl MorphTxEnvelope { @@ -44,7 +44,7 @@ impl MorphTxEnvelope { Self::Eip1559(_) => MorphTxType::Eip1559, Self::Eip7702(_) => MorphTxType::Eip7702, Self::L1Msg(_) => MorphTxType::L1Msg, - Self::AltFee(_) => MorphTxType::AltFee, + Self::Morph(_) => MorphTxType::Morph, } } @@ -68,7 +68,7 @@ impl MorphTxEnvelope { | Self::Eip2930(_) | Self::Eip1559(_) | Self::Eip7702(_) - | Self::AltFee(_) => None, + | Self::Morph(_) => None, Self::L1Msg(tx) => Some(tx.queue_index), } } @@ -83,7 +83,7 @@ impl MorphTxEnvelope { Self::Eip1559(tx) => tx.encode_2718(&mut bytes), Self::Eip7702(tx) => tx.encode_2718(&mut bytes), Self::L1Msg(tx) => tx.encode_2718(&mut bytes), - Self::AltFee(tx) => tx.encode_2718(&mut bytes), + Self::Morph(tx) => tx.encode_2718(&mut bytes), } Bytes(bytes.freeze()) } @@ -97,7 +97,7 @@ impl reth_primitives_traits::InMemorySize for MorphTxEnvelope { Self::Eip1559(tx) => tx.size(), Self::Eip7702(tx) => tx.size(), Self::L1Msg(tx) => tx.size(), - Self::AltFee(tx) => tx.size(), + Self::Morph(tx) => tx.size(), } } } @@ -130,7 +130,7 @@ impl alloy_consensus::transaction::TxHashRef for MorphTxEnvelope { Self::Eip1559(tx) => tx.hash(), Self::Eip7702(tx) => tx.hash(), Self::L1Msg(tx) => tx.hash_ref(), - Self::AltFee(tx) => tx.hash(), + Self::Morph(tx) => tx.hash(), } } } @@ -152,7 +152,7 @@ impl alloy_consensus::transaction::SignerRecoverable for MorphTxEnvelope { } // L1 messages have no signature - the sender is stored in the transaction itself Self::L1Msg(tx) => Ok(tx.sender), - Self::AltFee(tx) => alloy_consensus::transaction::SignerRecoverable::recover_signer(tx), + Self::Morph(tx) => alloy_consensus::transaction::SignerRecoverable::recover_signer(tx), } } @@ -174,7 +174,7 @@ impl alloy_consensus::transaction::SignerRecoverable for MorphTxEnvelope { } // L1 messages have no signature - the sender is stored in the transaction itself Self::L1Msg(tx) => Ok(tx.sender), - Self::AltFee(tx) => { + Self::Morph(tx) => { alloy_consensus::transaction::SignerRecoverable::recover_signer_unchecked(tx) } } @@ -185,10 +185,10 @@ impl reth_primitives_traits::SignedTransaction for MorphTxEnvelope {} #[cfg(feature = "reth-codec")] mod codec { - use crate::ALT_FEE_TX_TYPE_ID; use crate::L1_TX_TYPE_ID; - use crate::TxAltFee; + use crate::MORPH_TX_TYPE_ID; use crate::TxL1Msg; + use crate::TxMorph; use super::*; use alloy_eips::eip2718::EIP7702_TX_TYPE_ID; @@ -243,10 +243,10 @@ mod codec { let tx = Sealed::new(tx); (Self::L1Msg(tx), buf) } - MorphTxType::AltFee => { - let (tx, buf) = TxAltFee::from_compact(buf, buf.len()); + MorphTxType::Morph => { + let (tx, buf) = TxMorph::from_compact(buf, buf.len()); let tx = Signed::new_unhashed(tx, signature); - (Self::AltFee(tx), buf) + (Self::Morph(tx), buf) } } } @@ -260,7 +260,7 @@ mod codec { Self::Eip1559(tx) => tx.tx().to_compact(buf), Self::Eip7702(tx) => tx.tx().to_compact(buf), Self::L1Msg(tx) => tx.to_compact(buf), - Self::AltFee(tx) => tx.tx().to_compact(buf), + Self::Morph(tx) => tx.tx().to_compact(buf), }; } } @@ -280,7 +280,7 @@ mod codec { Self::Eip1559(tx) => tx.signature(), Self::Eip7702(tx) => tx.signature(), Self::L1Msg(_) => &L1_MSG_SIGNATURE, - Self::AltFee(tx) => tx.signature(), + Self::Morph(tx) => tx.signature(), } } @@ -306,8 +306,8 @@ mod codec { buf.put_u8(L1_TX_TYPE_ID); COMPACT_EXTENDED_IDENTIFIER_FLAG } - Self::AltFee => { - buf.put_u8(ALT_FEE_TX_TYPE_ID); + Self::Morph => { + buf.put_u8(MORPH_TX_TYPE_ID); COMPACT_EXTENDED_IDENTIFIER_FLAG } } @@ -328,7 +328,7 @@ mod codec { match extended_identifier { EIP7702_TX_TYPE_ID => Self::Eip7702, crate::transaction::L1_TX_TYPE_ID => Self::L1Msg, - crate::transaction::ALT_FEE_TX_TYPE_ID => Self::AltFee, + crate::transaction::MORPH_TX_TYPE_ID => Self::Morph, _ => panic!("Unsupported TxType identifier: {extended_identifier}"), } } diff --git a/crates/primitives/src/transaction/mod.rs b/crates/primitives/src/transaction/mod.rs index 99951df..edd18f2 100644 --- a/crates/primitives/src/transaction/mod.rs +++ b/crates/primitives/src/transaction/mod.rs @@ -1,9 +1,9 @@ //! Morph transaction types. -pub mod alt_fee; pub mod envelope; pub mod l1_transaction; +pub mod morph_transaction; -pub use alt_fee::{ALT_FEE_TX_TYPE_ID, TxAltFee, TxAltFeeExt}; pub use envelope::{MorphTxEnvelope, MorphTxType}; pub use l1_transaction::{L1_TX_TYPE_ID, TxL1Msg}; +pub use morph_transaction::{MORPH_TX_TYPE_ID, TxMorph, TxMorphExt}; diff --git a/crates/primitives/src/transaction/alt_fee.rs b/crates/primitives/src/transaction/morph_transaction.rs similarity index 89% rename from crates/primitives/src/transaction/alt_fee.rs rename to crates/primitives/src/transaction/morph_transaction.rs index 88c7eff..227c861 100644 --- a/crates/primitives/src/transaction/alt_fee.rs +++ b/crates/primitives/src/transaction/morph_transaction.rs @@ -1,6 +1,6 @@ -//! Altfee Transaction type for Morph L2. +//! Morph Transaction type for Morph L2. //! -//! This module defines the TxAltFee type which represents transactions that +//! This module defines the TxMorph type which represents transactions that //! use ERC20 tokens for gas payment instead of native ETH. //! //! Reference: @@ -16,10 +16,10 @@ use alloy_primitives::{B256, Bytes, ChainId, Signature, TxKind, U256, keccak256} use alloy_rlp::{BufMut, Decodable, Encodable, Header}; use core::mem; -/// Altfee Transaction type ID (0x7F). -pub const ALT_FEE_TX_TYPE_ID: u8 = 0x7F; +/// Morph Transaction type ID (0x7F). +pub const MORPH_TX_TYPE_ID: u8 = 0x7F; -/// Altfee Transaction for Morph L2. +/// Morph Transaction for Morph L2. /// /// This transaction type allows users to pay gas fees using ERC20 tokens /// instead of native ETH. It extends EIP-1559 style transactions with @@ -29,7 +29,7 @@ pub const ALT_FEE_TX_TYPE_ID: u8 = 0x7F; #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] -pub struct TxAltFee { +pub struct TxMorph { /// EIP-155: Simple replay attack protection. #[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))] pub chain_id: ChainId, @@ -92,11 +92,11 @@ pub struct TxAltFee { pub fee_token_id: u16, } -impl TxAltFee { +impl TxMorph { /// Get the transaction type. #[doc(alias = "transaction_type")] pub const fn tx_type() -> u8 { - ALT_FEE_TX_TYPE_ID + MORPH_TX_TYPE_ID } /// Returns the effective gas price for the given `base_fee`. @@ -213,13 +213,13 @@ impl TxAltFee { } } -impl Typed2718 for TxAltFee { +impl Typed2718 for TxMorph { fn ty(&self) -> u8 { - ALT_FEE_TX_TYPE_ID + MORPH_TX_TYPE_ID } } -impl Transaction for TxAltFee { +impl Transaction for TxMorph { fn chain_id(&self) -> Option { Some(self.chain_id) } @@ -289,7 +289,7 @@ impl Transaction for TxAltFee { } } -impl RlpEcdsaEncodableTx for TxAltFee { +impl RlpEcdsaEncodableTx for TxMorph { fn rlp_encoded_fields_length(&self) -> usize { self.fields_len() } @@ -299,7 +299,7 @@ impl RlpEcdsaEncodableTx for TxAltFee { } } -impl RlpEcdsaDecodableTx for TxAltFee { +impl RlpEcdsaDecodableTx for TxMorph { const DEFAULT_TX_TYPE: u8 = { Self::tx_type() }; /// Decodes the inner [TxEip1559] fields from RLP bytes. @@ -308,7 +308,7 @@ impl RlpEcdsaDecodableTx for TxAltFee { } } -impl SignableTransaction for TxAltFee { +impl SignableTransaction for TxMorph { fn set_chain_id(&mut self, chain_id: ChainId) { self.chain_id = chain_id; } @@ -323,7 +323,7 @@ impl SignableTransaction for TxAltFee { } } -impl Encodable for TxAltFee { +impl Encodable for TxMorph { fn encode(&self, out: &mut dyn BufMut) { self.rlp_encode(out); } @@ -333,7 +333,7 @@ impl Encodable for TxAltFee { } } -impl Decodable for TxAltFee { +impl Decodable for TxMorph { fn decode(buf: &mut &[u8]) -> alloy_rlp::Result { let header = Header::decode(buf)?; if !header.list { @@ -349,9 +349,9 @@ impl Decodable for TxAltFee { } } -impl Encodable2718 for TxAltFee { +impl Encodable2718 for TxMorph { fn type_flag(&self) -> Option { - Some(ALT_FEE_TX_TYPE_ID) + Some(MORPH_TX_TYPE_ID) } fn encode_2718_len(&self) -> usize { @@ -365,7 +365,7 @@ impl Encodable2718 for TxAltFee { } fn encode_2718(&self, out: &mut dyn BufMut) { - ALT_FEE_TX_TYPE_ID.encode(out); + MORPH_TX_TYPE_ID.encode(out); let header = Header { list: true, payload_length: self.fields_len(), @@ -375,14 +375,14 @@ impl Encodable2718 for TxAltFee { } } -impl reth_primitives_traits::InMemorySize for TxAltFee { +impl reth_primitives_traits::InMemorySize for TxMorph { fn size(&self) -> usize { Self::size(self) } } #[cfg(feature = "reth-codec")] -impl reth_codecs::Compact for TxAltFee { +impl reth_codecs::Compact for TxMorph { fn to_compact(&self, buf: &mut B) -> usize where B: BufMut + AsMut<[u8]>, @@ -434,8 +434,8 @@ impl reth_codecs::Compact for TxAltFee { } } -/// Extension trait for [`TxAltFee`] to access token fee fields. -pub trait TxAltFeeExt { +/// Extension trait for [`TxMorph`] to access token fee fields. +pub trait TxMorphExt { /// Returns the token ID used for fee payment. fn fee_token_id(&self) -> u16; @@ -448,7 +448,7 @@ pub trait TxAltFeeExt { } } -impl TxAltFeeExt for TxAltFee { +impl TxMorphExt for TxMorph { fn fee_token_id(&self) -> u16 { self.fee_token_id } @@ -464,8 +464,8 @@ mod tests { use alloy_primitives::address; #[test] - fn test_tx_alt_fee_default() { - let tx = TxAltFee::default(); + fn test_morph_transaction_default() { + let tx = TxMorph::default(); assert_eq!(tx.chain_id, 0); assert_eq!(tx.nonce, 0); assert_eq!(tx.gas_limit, 0); @@ -477,21 +477,21 @@ mod tests { } #[test] - fn test_tx_alt_fee_tx_type() { - assert_eq!(TxAltFee::tx_type(), ALT_FEE_TX_TYPE_ID); - assert_eq!(TxAltFee::tx_type(), 0x7F); + fn test_morph_transaction_tx_type() { + assert_eq!(TxMorph::tx_type(), MORPH_TX_TYPE_ID); + assert_eq!(TxMorph::tx_type(), 0x7F); } #[test] - fn test_tx_alt_fee_validate() { - let valid_tx = TxAltFee { + fn test_morph_transaction_validate() { + let valid_tx = TxMorph { max_fee_per_gas: 100, max_priority_fee_per_gas: 50, ..Default::default() }; assert!(valid_tx.validate().is_ok()); - let invalid_tx = TxAltFee { + let invalid_tx = TxMorph { max_fee_per_gas: 50, max_priority_fee_per_gas: 100, ..Default::default() @@ -500,8 +500,8 @@ mod tests { } #[test] - fn test_tx_alt_fee_effective_gas_price() { - let tx = TxAltFee { + fn test_morph_transaction_effective_gas_price() { + let tx = TxMorph { max_fee_per_gas: 100, max_priority_fee_per_gas: 20, ..Default::default() @@ -518,8 +518,8 @@ mod tests { } #[test] - fn test_tx_alt_fee_trait_methods() { - let tx = TxAltFee { + fn test_morph_transaction_trait_methods() { + let tx = TxMorph { chain_id: 1, nonce: 42, gas_limit: 21_000, @@ -550,26 +550,26 @@ mod tests { ); assert_eq!(Transaction::value(&tx), U256::from(100u64)); assert_eq!(Transaction::input(&tx), &Bytes::from(vec![1, 2, 3, 4])); - assert_eq!(Typed2718::ty(&tx), ALT_FEE_TX_TYPE_ID); + assert_eq!(Typed2718::ty(&tx), MORPH_TX_TYPE_ID); assert!(tx.access_list().is_some()); assert!(tx.blob_versioned_hashes().is_none()); assert!(tx.authorization_list().is_none()); - // Test TxAltFeeExt trait methods + // Test TxMorphExt trait methods assert_eq!(tx.fee_token_id(), 1); assert_eq!(tx.fee_limit(), U256::from(1000u64)); assert!(tx.uses_token_fee()); } #[test] - fn test_tx_alt_fee_is_create() { - let create_tx = TxAltFee { + fn test_morph_transaction_is_create() { + let create_tx = TxMorph { to: TxKind::Create, ..Default::default() }; assert!(create_tx.is_create()); - let call_tx = TxAltFee { + let call_tx = TxMorph { to: TxKind::Call(address!("0000000000000000000000000000000000000001")), ..Default::default() }; @@ -577,8 +577,8 @@ mod tests { } #[test] - fn test_tx_alt_fee_rlp_roundtrip() { - let tx = TxAltFee { + fn test_morph_transaction_rlp_roundtrip() { + let tx = TxMorph { chain_id: 1, nonce: 42, gas_limit: 21_000, @@ -597,7 +597,7 @@ mod tests { tx.encode(&mut buf); // Decode - let decoded = TxAltFee::decode(&mut buf.as_slice()).expect("Should decode"); + let decoded = TxMorph::decode(&mut buf.as_slice()).expect("Should decode"); assert_eq!(tx.chain_id, decoded.chain_id); assert_eq!(tx.nonce, decoded.nonce); @@ -615,8 +615,8 @@ mod tests { } #[test] - fn test_tx_alt_fee_create() { - let tx = TxAltFee { + fn test_morph_transaction_create() { + let tx = TxMorph { chain_id: 1, nonce: 0, gas_limit: 100_000, @@ -635,14 +635,14 @@ mod tests { tx.encode(&mut buf); // Decode - let decoded = TxAltFee::decode(&mut buf.as_slice()).expect("Should decode"); + let decoded = TxMorph::decode(&mut buf.as_slice()).expect("Should decode"); assert_eq!(decoded.to, TxKind::Create); } #[test] - fn test_tx_alt_fee_encode_2718() { - let tx = TxAltFee { + fn test_morph_transaction_encode_2718() { + let tx = TxMorph { chain_id: 1, nonce: 1, gas_limit: 21_000, @@ -660,18 +660,18 @@ mod tests { tx.encode_2718(&mut buf); // First byte should be the type ID - assert_eq!(buf[0], ALT_FEE_TX_TYPE_ID); + assert_eq!(buf[0], MORPH_TX_TYPE_ID); // Verify type_flag - assert_eq!(tx.type_flag(), Some(ALT_FEE_TX_TYPE_ID)); + assert_eq!(tx.type_flag(), Some(MORPH_TX_TYPE_ID)); // Verify length consistency assert_eq!(buf.len(), tx.encode_2718_len()); } #[test] - fn test_tx_alt_fee_decode_rejects_malformed_rlp() { - let tx = TxAltFee { + fn test_morph_transaction_decode_rejects_malformed_rlp() { + let tx = TxMorph { chain_id: 1, nonce: 42, gas_limit: 21_000, @@ -693,7 +693,7 @@ mod tests { let original_len = buf.len(); buf.truncate(original_len - 5); - let result = TxAltFee::decode(&mut buf.as_slice()); + let result = TxMorph::decode(&mut buf.as_slice()); assert!( result.is_err(), "Decoding should fail when data is truncated" @@ -701,8 +701,8 @@ mod tests { } #[test] - fn test_tx_alt_fee_size() { - let tx = TxAltFee { + fn test_morph_transaction_size() { + let tx = TxMorph { chain_id: 1, nonce: 0, gas_limit: 21_000, @@ -721,8 +721,8 @@ mod tests { } #[test] - fn test_tx_alt_fee_fields_len() { - let tx = TxAltFee { + fn test_morph_transaction_fields_len() { + let tx = TxMorph { chain_id: 1, nonce: 1, gas_limit: 21_000, @@ -745,8 +745,8 @@ mod tests { } #[test] - fn test_tx_alt_fee_encode_fields() { - let tx = TxAltFee { + fn test_morph_transaction_encode_fields() { + let tx = TxMorph { chain_id: 1, nonce: 1, gas_limit: 21_000, @@ -769,14 +769,14 @@ mod tests { } #[test] - fn test_tx_alt_fee_uses_token_fee() { - let tx_with_token = TxAltFee { + fn test_morph_transaction_uses_token_fee() { + let tx_with_token = TxMorph { fee_token_id: 1, ..Default::default() }; assert!(tx_with_token.uses_token_fee()); - let tx_without_token = TxAltFee { + let tx_without_token = TxMorph { fee_token_id: 0, ..Default::default() }; @@ -784,8 +784,8 @@ mod tests { } #[test] - fn test_tx_alt_fee_signature_hash() { - let tx = TxAltFee { + fn test_morph_transaction_signature_hash() { + let tx = TxMorph { chain_id: 1, nonce: 1, gas_limit: 21_000, diff --git a/crates/revm/src/handler.rs b/crates/revm/src/handler.rs index 955d21e..3fc54ac 100644 --- a/crates/revm/src/handler.rs +++ b/crates/revm/src/handler.rs @@ -112,8 +112,8 @@ where return Ok(()); } - // Check if transaction is AltFeeTx (tx_type 0x7F) which uses token fee - if evm.ctx_ref().tx().is_alt_fee_tx() { + // Check if transaction is MorphTransaction (tx_type 0x7F) which uses token fee + if evm.ctx_ref().tx().is_morph_tx() { // Get fee_token_id directly from MorphTxEnv let token_id = evm.ctx_ref().tx().fee_token_id.unwrap_or_default(); return self.validate_and_deduct_token_fee(evm, token_id); @@ -135,8 +135,8 @@ where return Ok(()); } - // Check if transaction is AltFeeTx (tx_type 0x7F) which uses token fee - if tx.is_alt_fee_tx() { + // Check if transaction is MorphTransaction (tx_type 0x7F) which uses token fee + if tx.is_morph_tx() { // Get fee_token_id directly from MorphTxEnv let token_id = tx.fee_token_id.unwrap_or_default(); return self.reimburse_caller_token_fee(evm, exec_result.gas(), token_id); @@ -159,8 +159,8 @@ where return Ok(()); } // L1 message transactions skip all reward. - // AltFeeTx rewards are already applied when gasFee is deducted. - if tx.is_l1_msg() || tx.is_alt_fee_tx() { + // MorphTransaction rewards are already applied when gasFee is deducted. + if tx.is_l1_msg() || tx.is_morph_tx() { return Ok(()); } diff --git a/crates/revm/src/lib.rs b/crates/revm/src/lib.rs index 94635b0..222dcdb 100644 --- a/crates/revm/src/lib.rs +++ b/crates/revm/src/lib.rs @@ -8,7 +8,7 @@ //! - [`MorphEvm`]: The main EVM type with Morph-specific handler //! - [`handler::MorphEvmHandler`]: Custom handler implementing fee deduction and reimbursement //! - [`L1BlockInfo`]: L1 gas price oracle data for L1 data fee calculation -//! - [`TokenFeeInfo`]: Token registry data for AltFee transaction support +//! - [`TokenFeeInfo`]: Token registry data for Morph transaction fee support //! //! # Fee Handling //! @@ -16,7 +16,7 @@ //! //! 1. **L2 Execution Fee**: Standard gas fee for EVM execution //! 2. **L1 Data Fee**: Fee for posting transaction data to L1 (calculated from L1 gas price) -//! 3. **AltFee Token Fee**: Optional ERC20 token payment instead of ETH +//! 3. **Morph Token Fee**: Optional ERC20 token payment instead of ETH //! //! # L1 Messages //! diff --git a/crates/revm/src/tx.rs b/crates/revm/src/tx.rs index 5c49fc2..d0e32bb 100644 --- a/crates/revm/src/tx.rs +++ b/crates/revm/src/tx.rs @@ -8,7 +8,7 @@ use alloy_eips::eip2930::AccessList; use alloy_eips::eip7702::RecoveredAuthority; use alloy_primitives::{Address, B256, Bytes, TxKind, U256}; use alloy_rlp::Decodable; -use morph_primitives::{ALT_FEE_TX_TYPE_ID, L1_TX_TYPE_ID, MorphTxEnvelope, TxAltFee}; +use morph_primitives::{L1_TX_TYPE_ID, MORPH_TX_TYPE_ID, MorphTxEnvelope, TxMorph}; use reth_evm::{FromRecoveredTx, FromTxWithEncoded, ToTxEnv, TransactionEnv}; use revm::context::{Transaction, TxEnv}; use revm::context_interface::transaction::{ @@ -23,7 +23,7 @@ use alloy_consensus::transaction::Either; /// /// This wraps the standard [`TxEnv`] and adds Morph-specific fields for: /// - L1 message detection (tx_type 0x7E) -/// - Morph transaction with token-based gas payment (tx_type 0x7F) +/// - TxMorph with token-based gas payment (tx_type 0x7F) /// - RLP encoded transaction bytes for L1 data fee calculation #[derive(Clone, Debug, Default, PartialEq, Eq)] pub struct MorphTxEnv { @@ -34,7 +34,7 @@ pub struct MorphTxEnv { pub rlp_bytes: Option, /// Maximum amount of tokens the sender is willing to pay as fee. pub fee_limit: Option, - /// Token ID for fee payment (only for AltFeeTx type 0x7F). + /// Token ID for fee payment (only for TxMorph type 0x7F). /// 0 means ETH payment, > 0 means ERC20 token payment. pub fee_token_id: Option, } @@ -73,7 +73,7 @@ impl MorphTxEnv { /// This method: /// - Converts the transaction to `TxEnv` /// - Extracts the RLP-encoded transaction bytes for L1 data fee calculation - /// - Extracts fee_token_id for AltFeeTx (type 0x7F) + /// - Extracts fee_token_id for TxMorph (type 0x7F) pub fn from_recovered_tx(tx: &MorphTxEnvelope, signer: Address) -> Self { // Encode the transaction to RLP bytes for L1 data fee calculation let rlp_bytes = tx.encoded_2718(); @@ -86,8 +86,8 @@ impl MorphTxEnv { fn from_tx_with_rlp_bytes(tx: &MorphTxEnvelope, signer: Address, rlp_bytes: Bytes) -> Self { let tx_type: u8 = tx.tx_type().into(); - // Extract fee_token_id for AltFeeTx (type 0x7F) - let fee_token_info = if tx_type == ALT_FEE_TX_TYPE_ID { + // Extract fee_token_id for TxMorph (type 0x7F) + let fee_token_info = if tx_type == MORPH_TX_TYPE_ID { ( Some(extract_fee_token_id_from_rlp(&rlp_bytes)), Some(extract_fee_limit_from_rlp(&rlp_bytes)), @@ -142,7 +142,7 @@ impl MorphTxEnv { } } -/// Extract fee_token_id from RLP-encoded AltFeeTx bytes. +/// Extract fee_token_id from RLP-encoded TxMorph bytes. /// /// The bytes should be EIP-2718 encoded (type byte + RLP payload). /// Returns 0 if decoding fails. @@ -151,14 +151,14 @@ fn extract_fee_token_id_from_rlp(rlp_bytes: &Bytes) -> u16 { return 0; } - // Skip the type byte (0x7F) and decode the AltFeeTx + // Skip the type byte (0x7F) and decode the TxMorph let payload = &rlp_bytes[1..]; - TxAltFee::decode(&mut &payload[..]) + TxMorph::decode(&mut &payload[..]) .map(|tx| tx.fee_token_id) .unwrap_or(0) } -/// Extract fee_limit from RLP-encoded AltFeeTx bytes. +/// Extract fee_limit from RLP-encoded TxMorph bytes. /// /// The bytes should be EIP-2718 encoded (type byte + RLP payload). /// Returns 0 if decoding fails. @@ -167,9 +167,9 @@ fn extract_fee_limit_from_rlp(rlp_bytes: &Bytes) -> U256 { return U256::default(); } - // Skip the type byte (0x7F) and decode the AltFeeTx + // Skip the type byte (0x7F) and decode the TxMorph let payload = &rlp_bytes[1..]; - TxAltFee::decode(&mut &payload[..]) + TxMorph::decode(&mut &payload[..]) .map(|tx| tx.fee_limit) .unwrap_or_default() } @@ -353,9 +353,9 @@ pub trait MorphTxExt { /// Returns whether this transaction is an L1 message transaction (type 0x7E). fn is_l1_msg(&self) -> bool; - /// Returns whether this transaction is a Morph transaction (type 0x7F). - /// Morph transactions support ERC20 token-based gas payment. - fn is_alt_fee_tx(&self) -> bool; + /// Returns whether this transaction is a TxMorph (type 0x7F). + /// TxMorph supports ERC20 token-based gas payment. + fn is_morph_tx(&self) -> bool; } impl MorphTxExt for MorphTxEnv { @@ -365,8 +365,8 @@ impl MorphTxExt for MorphTxEnv { } #[inline] - fn is_alt_fee_tx(&self) -> bool { - self.inner.tx_type == ALT_FEE_TX_TYPE_ID + fn is_morph_tx(&self) -> bool { + self.inner.tx_type == MORPH_TX_TYPE_ID } } @@ -377,8 +377,8 @@ impl MorphTxExt for TxEnv { } #[inline] - fn is_alt_fee_tx(&self) -> bool { - self.tx_type == ALT_FEE_TX_TYPE_ID + fn is_morph_tx(&self) -> bool { + self.tx_type == MORPH_TX_TYPE_ID } } @@ -391,7 +391,7 @@ mod tests { let mut tx = MorphTxEnv::default(); tx.inner.tx_type = L1_TX_TYPE_ID; assert!(tx.is_l1_msg()); - assert!(!tx.is_alt_fee_tx()); + assert!(!tx.is_morph_tx()); let regular_tx = MorphTxEnv::default(); assert!(!regular_tx.is_l1_msg()); @@ -400,21 +400,21 @@ mod tests { #[test] fn test_morph_tx_detection() { let mut tx = MorphTxEnv::default(); - tx.inner.tx_type = ALT_FEE_TX_TYPE_ID; - assert!(tx.is_alt_fee_tx()); + tx.inner.tx_type = MORPH_TX_TYPE_ID; + assert!(tx.is_morph_tx()); assert!(!tx.is_l1_msg()); } #[test] fn test_txenv_morph_tx_detection() { let tx = TxEnv { - tx_type: ALT_FEE_TX_TYPE_ID, + tx_type: MORPH_TX_TYPE_ID, ..Default::default() }; - assert!(tx.is_alt_fee_tx()); + assert!(tx.is_morph_tx()); let regular_tx = TxEnv::default(); - assert!(!regular_tx.is_alt_fee_tx()); + assert!(!regular_tx.is_morph_tx()); } #[test]