From 4646398c5bd267b95f13fafc2800ff43c487879a Mon Sep 17 00:00:00 2001 From: nicolas <48695862+merklefruit@users.noreply.github.com> Date: Mon, 27 May 2024 00:16:14 +0200 Subject: [PATCH] fix(primitives): use decode_2718() to gracefully handle the tx type --- Cargo.lock | 1 + crates/primitives/Cargo.toml | 1 + crates/primitives/src/payload.rs | 8 +++++--- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e8844e00..983282c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1664,6 +1664,7 @@ name = "kona-primitives" version = "0.0.1" dependencies = [ "alloy-consensus 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=e3f2f07)", + "alloy-eips 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=cb95183)", "alloy-primitives", "alloy-rlp", "alloy-sol-types", diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index 52a07c7b..b194e822 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -16,6 +16,7 @@ alloy-primitives = { workspace = true, features = ["rlp"] } # Alloy Types alloy-sol-types = { version = "0.7.1", default-features = false } +alloy-eips = { git = "https://github.com/alloy-rs/alloy", rev = "cb95183", default-features = false } op-alloy-consensus = { git = "https://github.com/clabby/op-alloy", branch = "refcell/consensus-port", default-features = false } # `serde` feature dependencies diff --git a/crates/primitives/src/payload.rs b/crates/primitives/src/payload.rs index bf730db4..e15dce07 100644 --- a/crates/primitives/src/payload.rs +++ b/crates/primitives/src/payload.rs @@ -1,6 +1,7 @@ //! Contains the execution payload type. use alloc::vec::Vec; +use alloy_eips::eip2718::Decodable2718; use alloy_primitives::{Address, Bloom, Bytes, B256, U256}; use anyhow::Result; use op_alloy_consensus::{OpTxEnvelope, OpTxType}; @@ -17,7 +18,7 @@ use super::{ Block, BlockInfo, L1BlockInfoBedrock, L1BlockInfoEcotone, L1BlockInfoTx, L2BlockInfo, OpBlock, RollupConfig, SystemConfig, Withdrawal, }; -use alloy_rlp::{Decodable, Encodable}; +use alloy_rlp::Encodable; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -139,7 +140,8 @@ impl L2ExecutionPayloadEnvelope { if ty != OpTxType::Deposit as u8 { anyhow::bail!("First payload transaction has unexpected type: {:?}", ty); } - let tx = OpTxEnvelope::decode(&mut execution_payload.transactions[0][1..].as_ref()) + + let tx = OpTxEnvelope::decode_2718(&mut execution_payload.transactions[0].as_ref()) .map_err(|e| anyhow::anyhow!(e))?; let OpTxEnvelope::Deposit(tx) = tx else { @@ -183,7 +185,7 @@ impl L2ExecutionPayloadEnvelope { if ty != OpTxType::Deposit as u8 { anyhow::bail!("First payload transaction has unexpected type: {:?}", ty); } - let tx = OpTxEnvelope::decode(&mut execution_payload.transactions[0][1..].as_ref()) + let tx = OpTxEnvelope::decode_2718(&mut execution_payload.transactions[0].as_ref()) .map_err(|e| anyhow::anyhow!(e))?; let OpTxEnvelope::Deposit(tx) = tx else {