From 0cc4813e48f232ee1870d829ba19603dee481910 Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Wed, 9 Apr 2025 00:05:21 +0800 Subject: [PATCH] core/types: fix wrong hash after EIP-1559 for EncodeIndex in PR #933 (#939) --- core/types/hashing_test.go | 2 +- core/types/receipt.go | 14 +++----------- core/types/transaction.go | 2 +- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/core/types/hashing_test.go b/core/types/hashing_test.go index 22176a1601..302c1f3bf3 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 01f8a486796f6c6f763380843b9aca008262d4948a8eafb1cf62bfbeb1741769dae1a9dd479961928080f838f7940000000000000000000000000000000000001337e1a0000000000000000000000000000000000000000000000000000000000000000080a0775101f92dcca278a56bfe4d613428624a1ebfc3cd9e0bcc1de80c41455b9021a06c9deac205afe7b124907d4ba54a9f46161498bd3990b90d175aac12c9a40ee9\n80 01f8a486796f6c6f763380843b9aca008262d4948a8eafb1cf62bfbeb1741769dae1a9dd479961928080f838f7940000000000000000000000000000000000001337e1a0000000000000000000000000000000000000000000000000000000000000000080a0775101f92dcca278a56bfe4d613428624a1ebfc3cd9e0bcc1de80c41455b9021a06c9deac205afe7b124907d4ba54a9f46161498bd3990b90d175aac12c9a40ee9\n", + exp: "01 b8a701f8a486796f6c6f763380843b9aca008262d4948a8eafb1cf62bfbeb1741769dae1a9dd479961928080f838f7940000000000000000000000000000000000001337e1a0000000000000000000000000000000000000000000000000000000000000000080a0775101f92dcca278a56bfe4d613428624a1ebfc3cd9e0bcc1de80c41455b9021a06c9deac205afe7b124907d4ba54a9f46161498bd3990b90d175aac12c9a40ee9\n80 b8a701f8a486796f6c6f763380843b9aca008262d4948a8eafb1cf62bfbeb1741769dae1a9dd479961928080f838f7940000000000000000000000000000000000001337e1a0000000000000000000000000000000000000000000000000000000000000000080a0775101f92dcca278a56bfe4d613428624a1ebfc3cd9e0bcc1de80c41455b9021a06c9deac205afe7b124907d4ba54a9f46161498bd3990b90d175aac12c9a40ee9\n", }, } { d := &hashToHumanReadable{} diff --git a/core/types/receipt.go b/core/types/receipt.go index 4eb929fa5c..3884a14897 100644 --- a/core/types/receipt.go +++ b/core/types/receipt.go @@ -382,19 +382,11 @@ 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) - 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. + } else { + rlp.Encode(w, r) } } diff --git a/core/types/transaction.go b/core/types/transaction.go index 0a6daf07fa..dd5b505224 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 { - tx.encodeTyped(w) + rlp.Encode(w, tx) } }