Skip to content

Commit

Permalink
fix: broken blob transaction ssz decoding (#1236)
Browse files Browse the repository at this point in the history
  • Loading branch information
njgheorghita authored Apr 3, 2024
1 parent 5e0658a commit b446dc2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ethportal-api/src/types/execution/block_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ impl Decodable for BlockBodyMerge {
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)]
pub struct BlockBodyShanghai {
pub txs: Vec<Transaction>,
// 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<Withdrawal>,
}

Expand Down Expand Up @@ -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::<Header>(&uncles);
if !uncles.is_empty() {
return Err(ssz::DecodeError::BytesInvalid(
Expand Down
2 changes: 1 addition & 1 deletion ethportal-api/src/types/execution/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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..])?)),
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions portal-bridge/src/types/full_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit b446dc2

Please sign in to comment.