Skip to content

Commit 9e1b247

Browse files
authored
fix: change Receipt rlp (#20074)
1 parent d71cd12 commit 9e1b247

File tree

2 files changed

+23
-105
lines changed

2 files changed

+23
-105
lines changed

crates/ethereum/primitives/src/receipt.rs

Lines changed: 3 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@ use alloy_consensus::{
55
Eip2718EncodableReceipt, Eip658Value, ReceiptEnvelope, ReceiptWithBloom, RlpDecodableReceipt,
66
RlpEncodableReceipt, TxReceipt, TxType, Typed2718,
77
};
8-
use alloy_eips::{
9-
eip2718::{Eip2718Error, Eip2718Result, Encodable2718, IsTyped2718},
10-
Decodable2718,
11-
};
8+
use alloy_eips::eip2718::{Eip2718Error, Encodable2718, IsTyped2718};
129
use alloy_primitives::{Bloom, Log, B256};
13-
use alloy_rlp::{BufMut, Decodable, Encodable, Header};
10+
use alloy_rlp::{BufMut, Decodable, Encodable, Header, RlpDecodable, RlpEncodable};
1411
use reth_primitives_traits::{proofs::ordered_trie_root_with_encoder, InMemorySize};
1512

1613
/// Helper trait alias with requirements for transaction type generic to be used within [`Receipt`].
@@ -50,7 +47,7 @@ pub type RpcReceipt<T = TxType> = EthereumReceipt<T, alloy_rpc_types_eth::Log>;
5047

5148
/// Typed ethereum transaction receipt.
5249
/// Receipt containing result of transaction execution.
53-
#[derive(Clone, Debug, PartialEq, Eq, Default)]
50+
#[derive(Clone, Debug, PartialEq, Eq, Default, RlpEncodable, RlpDecodable)]
5451
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5552
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
5653
#[cfg_attr(feature = "reth-codec", reth_codecs::add_arbitrary_tests(compact, rlp))]
@@ -141,44 +138,6 @@ impl<T: TxTy> Receipt<T> {
141138
pub fn calculate_receipt_root_no_memo(receipts: &[Self]) -> B256 {
142139
ordered_trie_root_with_encoder(receipts, |r, buf| r.with_bloom_ref().encode_2718(buf))
143140
}
144-
145-
/// Returns length of RLP-encoded receipt fields without the given [`Bloom`] without an RLP
146-
/// header
147-
pub fn rlp_encoded_fields_length_without_bloom(&self) -> usize {
148-
self.success.length() + self.cumulative_gas_used.length() + self.logs.length()
149-
}
150-
151-
/// RLP-encodes receipt fields without the given [`Bloom`] without an RLP header.
152-
pub fn rlp_encode_fields_without_bloom(&self, out: &mut dyn BufMut) {
153-
self.success.encode(out);
154-
self.cumulative_gas_used.encode(out);
155-
self.logs.encode(out);
156-
}
157-
158-
/// Returns RLP header for inner encoding.
159-
pub fn rlp_header_inner_without_bloom(&self) -> Header {
160-
Header { list: true, payload_length: self.rlp_encoded_fields_length_without_bloom() }
161-
}
162-
163-
/// RLP-decodes the receipt from the provided buffer. This does not expect a type byte or
164-
/// network header.
165-
pub fn rlp_decode_inner_without_bloom(buf: &mut &[u8], tx_type: T) -> alloy_rlp::Result<Self> {
166-
let header = Header::decode(buf)?;
167-
if !header.list {
168-
return Err(alloy_rlp::Error::UnexpectedString);
169-
}
170-
171-
let remaining = buf.len();
172-
let success = Decodable::decode(buf)?;
173-
let cumulative_gas_used = Decodable::decode(buf)?;
174-
let logs = Decodable::decode(buf)?;
175-
176-
if buf.len() + header.payload_length != remaining {
177-
return Err(alloy_rlp::Error::UnexpectedLength);
178-
}
179-
180-
Ok(Self { tx_type, success, cumulative_gas_used, logs })
181-
}
182141
}
183142

184143
impl<T: TxTy> Eip2718EncodableReceipt for Receipt<T> {
@@ -243,48 +202,6 @@ impl<T: TxTy> RlpDecodableReceipt for Receipt<T> {
243202
}
244203
}
245204

246-
impl<T: TxTy> Encodable2718 for Receipt<T> {
247-
fn encode_2718_len(&self) -> usize {
248-
(!self.tx_type.is_legacy() as usize) +
249-
self.rlp_header_inner_without_bloom().length_with_payload()
250-
}
251-
252-
// encode the header
253-
fn encode_2718(&self, out: &mut dyn BufMut) {
254-
if !self.tx_type.is_legacy() {
255-
out.put_u8(self.tx_type.ty());
256-
}
257-
self.rlp_header_inner_without_bloom().encode(out);
258-
self.rlp_encode_fields_without_bloom(out);
259-
}
260-
}
261-
262-
impl<T: TxTy> Decodable2718 for Receipt<T> {
263-
fn typed_decode(ty: u8, buf: &mut &[u8]) -> Eip2718Result<Self> {
264-
Ok(Self::rlp_decode_inner_without_bloom(buf, T::try_from(ty)?)?)
265-
}
266-
267-
fn fallback_decode(buf: &mut &[u8]) -> Eip2718Result<Self> {
268-
Ok(Self::rlp_decode_inner_without_bloom(buf, T::try_from(0)?)?)
269-
}
270-
}
271-
272-
impl<T: TxTy> Encodable for Receipt<T> {
273-
fn encode(&self, out: &mut dyn BufMut) {
274-
self.network_encode(out);
275-
}
276-
277-
fn length(&self) -> usize {
278-
self.network_len()
279-
}
280-
}
281-
282-
impl<T: TxTy> Decodable for Receipt<T> {
283-
fn decode(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
284-
Ok(Self::network_decode(buf)?)
285-
}
286-
}
287-
288205
impl<T, L> TxReceipt for EthereumReceipt<T, L>
289206
where
290207
T: TxTy,

crates/net/eth-wire-types/src/receipts.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,12 @@ impl<T: RlpDecodableReceipt> alloy_rlp::Decodable for Receipts<T> {
4949
/// Eth/69 receipt response type that removes bloom filters from the protocol.
5050
///
5151
/// This is effectively a subset of [`Receipts`].
52-
#[derive(Clone, Debug, PartialEq, Eq)]
52+
#[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper)]
5353
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5454
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
5555
#[add_arbitrary_tests(rlp)]
5656
pub struct Receipts69<T = Receipt>(pub Vec<Vec<T>>);
5757

58-
impl<T: RlpEncodableReceipt + alloy_rlp::Encodable> alloy_rlp::Encodable for Receipts69<T> {
59-
#[inline]
60-
fn encode(&self, out: &mut dyn alloy_rlp::BufMut) {
61-
self.0.encode(out)
62-
}
63-
#[inline]
64-
fn length(&self) -> usize {
65-
self.0.length()
66-
}
67-
}
68-
69-
impl<T: RlpDecodableReceipt + alloy_rlp::Decodable> alloy_rlp::Decodable for Receipts69<T> {
70-
#[inline]
71-
fn decode(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
72-
alloy_rlp::Decodable::decode(buf).map(Self)
73-
}
74-
}
75-
7658
impl<T: TxReceipt> Receipts69<T> {
7759
/// Encodes all receipts with the bloom filter.
7860
///
@@ -224,4 +206,23 @@ mod tests {
224206
}
225207
);
226208
}
209+
210+
#[test]
211+
fn decode_receipts_69() {
212+
let data = hex!("0xf9026605f90262f9025fc60201826590c0c7800183013cd9c0c702018301a2a5c0c7010183027a36c0c702018302e03ec0c7010183034646c0c702018303ac30c0c78001830483b8c0c702018304e9a2c0c780018305c17fc0c7020183062769c0c7800183068d71c0c702018306f35bc0c702018307cb77c0c701018308a382c0c7020183097ab6c0c78080830b0156c0c70101830b6740c0c70201830bcd48c0c70101830c32f6c0c70101830c98e0c0c70201830cfecac0c70201830d64b4c0c70280830dca9ec0c70101830e30a6c0c70201830f080dc0c70201830f6e15c0c78080830fd41dc0c702018310abbac0c701018310fdc2c0c7020183116370c0c780018311c95ac0c7010183122f44c0c701808312952ec0c7020183136c7dc0c70201831443c0c0c702018314a9c8c0c7020183150f94c0c7018083169634c0c7020183176d68c0c702808317d370c0c70201831838c4c0c701808319bf64c0c70201831a256cc0c78080831bac0cc0c70201831c11d8c0c70201831c77c2c0c78080831cdd34c0c70201831db57bc0c70101831e8d07c0c70101831ef2d3c0c70201831fcb37c0c70180832030e5c0c70201832096cfc0c701018320fcb9c0c70201832162c1c0c702018321c8abc0c7020183229ffac0c70201832305c6c0c7028083236bcec0c702808323d1d6c0c702018324a91cc0c7020183250f06c0c70201832574d2c0c7020183264c15c0c70201832723b6c0c70201832789a0c0c702018327ef8ac0c7020183285574c0c702018328bb40c0c702018329212ac0c7028083298714c0c70201832a5e4ec0c70201832ac438c0c70201832b9b72c0c70201832c017ac0");
213+
214+
let request = RequestPair::<Receipts69>::decode(&mut &data[..]).unwrap();
215+
assert_eq!(
216+
request.message.0[0][0],
217+
Receipt {
218+
tx_type: TxType::Eip1559,
219+
success: true,
220+
cumulative_gas_used: 26000,
221+
logs: vec![],
222+
}
223+
);
224+
225+
let encoded = alloy_rlp::encode(&request);
226+
assert_eq!(encoded, data);
227+
}
227228
}

0 commit comments

Comments
 (0)