From b446dc2d88c044b9f1b4951664dbb12585609736 Mon Sep 17 00:00:00 2001 From: Nick Gheorghita Date: Wed, 3 Apr 2024 15:40:07 -0400 Subject: [PATCH] fix: broken blob transaction ssz decoding (#1236) --- ethportal-api/src/types/execution/block_body.rs | 3 +++ ethportal-api/src/types/execution/transaction.rs | 2 +- portal-bridge/src/types/full_header.rs | 5 +++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ethportal-api/src/types/execution/block_body.rs b/ethportal-api/src/types/execution/block_body.rs index 302284831..92206c74f 100644 --- a/ethportal-api/src/types/execution/block_body.rs +++ b/ethportal-api/src/types/execution/block_body.rs @@ -339,6 +339,8 @@ impl Decodable for BlockBodyMerge { #[derive(Clone, Debug, PartialEq, Eq, Deserialize)] pub struct BlockBodyShanghai { pub txs: Vec, + // post-shanghai block bodies are expected to have empty uncles, but we skip that here + // and simply encode an empty list during the encoding/decoding process pub withdrawals: Vec, } @@ -395,6 +397,7 @@ impl ssz::Decode for BlockBodyShanghai { "Shanghai block body contains invalid transactions: {e:?}", )) })?; + // shanghai block bodies are expected to have empty uncles let uncles = rlp::decode_list::
(&uncles); if !uncles.is_empty() { return Err(ssz::DecodeError::BytesInvalid( diff --git a/ethportal-api/src/types/execution/transaction.rs b/ethportal-api/src/types/execution/transaction.rs index 80b1bf26d..b56c43f35 100644 --- a/ethportal-api/src/types/execution/transaction.rs +++ b/ethportal-api/src/types/execution/transaction.rs @@ -61,7 +61,7 @@ impl Decodable for Transaction { TransactionId::EIP1559 => Ok(Self::EIP1559(rlp::decode(&rlp.as_raw()[1..])?)), TransactionId::AccessList => Ok(Self::AccessList(rlp::decode(&rlp.as_raw()[1..])?)), TransactionId::Legacy => Ok(Self::Legacy(rlp::decode(rlp.as_raw())?)), - TransactionId::Blob => Ok(Self::Blob(rlp::decode(rlp.as_raw())?)), + TransactionId::Blob => Ok(Self::Blob(rlp::decode(&rlp.as_raw()[1..])?)), } } } diff --git a/portal-bridge/src/types/full_header.rs b/portal-bridge/src/types/full_header.rs index ce5ed9564..d2888c009 100644 --- a/portal-bridge/src/types/full_header.rs +++ b/portal-bridge/src/types/full_header.rs @@ -120,6 +120,7 @@ mod tests { BlockBody, BlockBodyLegacy, BlockBodyShanghai, }; use serde_json::Value; + use ssz::{Decode, Encode}; #[test] fn full_header_from_get_block_response() { @@ -179,6 +180,10 @@ mod tests { withdrawals: full_header.withdrawals.unwrap(), }); block_body.validate_against_header(&header).unwrap(); + // test ssz roundtrip + let ssz = block_body.as_ssz_bytes(); + let decoded_block_body = BlockBody::from_ssz_bytes(&ssz).unwrap(); + assert_eq!(block_body, decoded_block_body); } #[test_log::test]