From 734abb26dcd9f1b52238c04d7dc632acd57fcc91 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Sat, 12 Apr 2025 11:30:50 +0800 Subject: [PATCH] Revert "core/types: fix wrong hash after EIP-1559 for EncodeIndex in PR #933 (#939)" This reverts commit 0cc4813e48f232ee1870d829ba19603dee481910. --- core/types/hashing_test.go | 2 +- core/types/receipt.go | 14 +++++++++++--- core/types/transaction.go | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/core/types/hashing_test.go b/core/types/hashing_test.go index 302c1f3bf3..22176a1601 100644 --- a/core/types/hashing_test.go +++ b/core/types/hashing_test.go @@ -43,7 +43,7 @@ func TestEIP2718DeriveSha(t *testing.T) { }{ { rlpData: "0xb8a701f8a486796f6c6f763380843b9aca008262d4948a8eafb1cf62bfbeb1741769dae1a9dd479961928080f838f7940000000000000000000000000000000000001337e1a0000000000000000000000000000000000000000000000000000000000000000080a0775101f92dcca278a56bfe4d613428624a1ebfc3cd9e0bcc1de80c41455b9021a06c9deac205afe7b124907d4ba54a9f46161498bd3990b90d175aac12c9a40ee9", - exp: "01 b8a701f8a486796f6c6f763380843b9aca008262d4948a8eafb1cf62bfbeb1741769dae1a9dd479961928080f838f7940000000000000000000000000000000000001337e1a0000000000000000000000000000000000000000000000000000000000000000080a0775101f92dcca278a56bfe4d613428624a1ebfc3cd9e0bcc1de80c41455b9021a06c9deac205afe7b124907d4ba54a9f46161498bd3990b90d175aac12c9a40ee9\n80 b8a701f8a486796f6c6f763380843b9aca008262d4948a8eafb1cf62bfbeb1741769dae1a9dd479961928080f838f7940000000000000000000000000000000000001337e1a0000000000000000000000000000000000000000000000000000000000000000080a0775101f92dcca278a56bfe4d613428624a1ebfc3cd9e0bcc1de80c41455b9021a06c9deac205afe7b124907d4ba54a9f46161498bd3990b90d175aac12c9a40ee9\n", + exp: "01 01f8a486796f6c6f763380843b9aca008262d4948a8eafb1cf62bfbeb1741769dae1a9dd479961928080f838f7940000000000000000000000000000000000001337e1a0000000000000000000000000000000000000000000000000000000000000000080a0775101f92dcca278a56bfe4d613428624a1ebfc3cd9e0bcc1de80c41455b9021a06c9deac205afe7b124907d4ba54a9f46161498bd3990b90d175aac12c9a40ee9\n80 01f8a486796f6c6f763380843b9aca008262d4948a8eafb1cf62bfbeb1741769dae1a9dd479961928080f838f7940000000000000000000000000000000000001337e1a0000000000000000000000000000000000000000000000000000000000000000080a0775101f92dcca278a56bfe4d613428624a1ebfc3cd9e0bcc1de80c41455b9021a06c9deac205afe7b124907d4ba54a9f46161498bd3990b90d175aac12c9a40ee9\n", }, } { d := &hashToHumanReadable{} diff --git a/core/types/receipt.go b/core/types/receipt.go index 3884a14897..4eb929fa5c 100644 --- a/core/types/receipt.go +++ b/core/types/receipt.go @@ -382,11 +382,19 @@ func (rs Receipts) Len() int { return len(rs) } // EncodeIndex encodes the i'th receipt to w. func (rs Receipts) EncodeIndex(i int, w *bytes.Buffer) { r := rs[i] + data := &receiptRLP{r.statusEncoding(), r.CumulativeGasUsed, r.Bloom, r.Logs} if r.Type == LegacyTxType { - data := &receiptRLP{r.statusEncoding(), r.CumulativeGasUsed, r.Bloom, r.Logs} rlp.Encode(w, data) - } else { - rlp.Encode(w, r) + return + } + w.WriteByte(r.Type) + switch r.Type { + case AccessListTxType, DynamicFeeTxType: + rlp.Encode(w, data) + default: + // For unsupported types, write nothing. Since this is for + // DeriveSha, the error will be caught matching the derived hash + // to the block. } } diff --git a/core/types/transaction.go b/core/types/transaction.go index dd5b505224..0a6daf07fa 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -640,7 +640,7 @@ func (s Transactions) EncodeIndex(i int, w *bytes.Buffer) { if tx.Type() == LegacyTxType { rlp.Encode(w, tx.inner) } else { - rlp.Encode(w, tx) + tx.encodeTyped(w) } }