From 7a158f78b4523f58b83060400418958de634b63e Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Wed, 27 Nov 2024 22:55:38 +0400 Subject: [PATCH] fix: pass slice to RlpReceipt::rlp_decode_fields --- crates/consensus/src/receipt/mod.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/consensus/src/receipt/mod.rs b/crates/consensus/src/receipt/mod.rs index 3eed2a0d70e..fc1103f11ef 100644 --- a/crates/consensus/src/receipt/mod.rs +++ b/crates/consensus/src/receipt/mod.rs @@ -1,5 +1,5 @@ use alloy_primitives::Bloom; -use alloy_rlp::{BufMut, Header}; +use alloy_rlp::{Buf, BufMut, Header}; use core::fmt; mod envelope; @@ -100,18 +100,20 @@ pub trait RlpReceipt: Sized { if !header.list { return Err(alloy_rlp::Error::UnexpectedString); } - let remaining = buf.len(); - if header.payload_length > remaining { + if header.payload_length > buf.len() { return Err(alloy_rlp::Error::InputTooShort); } - let this = Self::rlp_decode_fields_with_bloom(buf)?; + let mut fields_buf = &buf[..header.payload_length]; + let this = Self::rlp_decode_fields_with_bloom(&mut fields_buf)?; - if buf.len() + header.payload_length != remaining { + if !fields_buf.is_empty() { return Err(alloy_rlp::Error::UnexpectedLength); } + buf.advance(header.payload_length); + Ok(this) } }