Skip to content

Commit ede1eaa

Browse files
committed
Fix extBlockTx rlp decode
This fixes a bug where transactions in a Block would not get filled in during rlp decode. The existing `TestBlockEncoding` unit test in core/types/block_test.go catches this.
1 parent 9e93167 commit ede1eaa

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

accounts/abi/bind/bind_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2098,7 +2098,12 @@ func TestGolangBindings(t *testing.T) {
20982098
t.Fatalf("failed to convert binding test to modules: %v\n%s", err, out)
20992099
}
21002100
pwd, _ := os.Getwd()
2101-
replacer := exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ethereum/[email protected]", "-replace", "github.com/ethereum/go-ethereum="+filepath.Join(pwd, "..", "..", "..")) // Repo root
2101+
//replacer := exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ethereum/[email protected]", "-replace", "github.com/ethereum/go-ethereum="+filepath.Join(pwd, "..", "..", "..")) // Repo root
2102+
// TODO(EIP-4844): Replace with above once go-kzg fork is upstreamed
2103+
replacer := exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ethereum/[email protected]",
2104+
"-replace", "github.com/ethereum/go-ethereum="+filepath.Join(pwd, "..", "..", ".."),
2105+
"-replace", "github.com/protolambda/go-kzg=github.com/inphi/[email protected]",
2106+
"-replace", "github.com/kilic/bls12-381=github.com/inphi/[email protected]") // Repo root
21022107
replacer.Dir = pkg
21032108
if out, err := replacer.CombinedOutput(); err != nil {
21042109
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out)

core/types/block.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -232,25 +232,26 @@ func (tx *minimalTx) EncodeRLP(w io.Writer) error {
232232
// a view over a regular transactions slice, to RLP decode/encode the transactions all the minimal way
233233
type extBlockTxs []*Transaction
234234

235-
func (txs extBlockTxs) DecodeRLP(s *rlp.Stream) error {
235+
func (txs *extBlockTxs) DecodeRLP(s *rlp.Stream) error {
236236
// we need generics to do this nicely...
237237
var out []*minimalTx
238-
for i, tx := range txs {
238+
for i, tx := range *txs {
239239
out[i] = (*minimalTx)(tx)
240240
}
241241
if err := s.Decode(&out); err != nil {
242242
return fmt.Errorf("failed to decode list of minimal txs: %v", err)
243243
}
244-
txs = make([]*Transaction, len(out))
244+
rawtxs := make([]*Transaction, len(out))
245245
for i, tx := range out {
246-
txs[i] = (*Transaction)(tx)
246+
rawtxs[i] = (*Transaction)(tx)
247247
}
248+
*txs = rawtxs
248249
return nil
249250
}
250251

251-
func (txs extBlockTxs) EncodeRLP(w io.Writer) error {
252-
out := make([]*minimalTx, len(txs))
253-
for i, tx := range txs {
252+
func (txs *extBlockTxs) EncodeRLP(w io.Writer) error {
253+
out := make([]*minimalTx, len(*txs))
254+
for i, tx := range *txs {
254255
out[i] = (*minimalTx)(tx)
255256
}
256257
return rlp.Encode(w, &out)
@@ -259,7 +260,7 @@ func (txs extBlockTxs) EncodeRLP(w io.Writer) error {
259260
// "external" block encoding. used for eth protocol, etc.
260261
type extblock struct {
261262
Header *Header
262-
Txs extBlockTxs
263+
Txs *extBlockTxs
263264
Uncles []*Header
264265
}
265266

@@ -331,17 +332,17 @@ func CopyHeader(h *Header) *Header {
331332

332333
// DecodeRLP decodes the Ethereum
333334
func (b *Block) DecodeRLP(s *rlp.Stream) error {
334-
var eb extblock
335+
eb := extblock{Txs: new(extBlockTxs)}
335336
_, size, _ := s.Kind()
336337
if err := s.Decode(&eb); err != nil {
337338
return err
338339
}
339-
for i, tx := range eb.Txs {
340+
for i, tx := range *eb.Txs {
340341
if tx.wrapData != nil {
341342
return fmt.Errorf("transactions in blocks must not contain wrap-data, tx %d is bad", i)
342343
}
343344
}
344-
b.header, b.uncles, b.transactions = eb.Header, eb.Uncles, []*Transaction(eb.Txs)
345+
b.header, b.uncles, b.transactions = eb.Header, eb.Uncles, []*Transaction(*eb.Txs)
345346
b.size.Store(common.StorageSize(rlp.ListSize(size)))
346347
return nil
347348
}
@@ -350,7 +351,7 @@ func (b *Block) DecodeRLP(s *rlp.Stream) error {
350351
func (b *Block) EncodeRLP(w io.Writer) error {
351352
return rlp.Encode(w, extblock{
352353
Header: b.header,
353-
Txs: (extBlockTxs)(b.transactions),
354+
Txs: (*extBlockTxs)(&b.transactions),
354355
Uncles: b.uncles,
355356
})
356357
}

les/catalyst/api_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func TestExecutePayloadV1(t *testing.T) {
135135
Timestamp: fakeBlock.Time(),
136136
ExtraData: fakeBlock.Extra(),
137137
BaseFeePerGas: fakeBlock.BaseFee(),
138-
Blobs: fakeBlock.ExcessBlobs(),
138+
ExcessBlobs: fakeBlock.ExcessBlobs(),
139139
BlockHash: fakeBlock.Hash(),
140140
Transactions: encodeTransactions(fakeBlock.Transactions()),
141141
})

0 commit comments

Comments
 (0)