Skip to content

Commit ee0a2da

Browse files
authored
Update Empty requests list behaviour for Pectra-5 (#12985)
The updated EIP-7685 says requests with empty `request_data` should be dropped from `executionRequests` field in the API and ignored for hash calculation. See ethereum/EIPs#8989, ethereum/execution-apis#599 Issue board: #12401
1 parent 916e9ae commit ee0a2da

File tree

11 files changed

+76
-63
lines changed

11 files changed

+76
-63
lines changed

consensus/merge/merge.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func (s *Merge) Finalize(config *chain.Config, header *types.Header, state *stat
187187

188188
var rs types.FlatRequests
189189
if config.IsPrague(header.Time) {
190-
rs = make(types.FlatRequests, len(types.KnownRequestTypes))
190+
rs = make(types.FlatRequests, 0)
191191
allLogs := make(types.Logs, 0)
192192
for _, rec := range receipts {
193193
allLogs = append(allLogs, rec.Logs...)
@@ -196,11 +196,17 @@ func (s *Merge) Finalize(config *chain.Config, header *types.Header, state *stat
196196
if err != nil {
197197
return nil, nil, nil, fmt.Errorf("error: could not parse requests logs: %v", err)
198198
}
199-
rs[0] = *depositReqs
199+
if depositReqs != nil {
200+
rs = append(rs, *depositReqs)
201+
}
200202
withdrawalReq := misc.DequeueWithdrawalRequests7002(syscall)
201-
rs[1] = *withdrawalReq
203+
if withdrawalReq != nil {
204+
rs = append(rs, *withdrawalReq)
205+
}
202206
consolidations := misc.DequeueConsolidationRequests7251(syscall)
203-
rs[2] = *consolidations
207+
if consolidations != nil {
208+
rs = append(rs, *consolidations)
209+
}
204210
if header.RequestsHash != nil {
205211
rh := rs.Hash()
206212
if *header.RequestsHash != *rh {
@@ -219,15 +225,15 @@ func (s *Merge) FinalizeAndAssemble(config *chain.Config, header *types.Header,
219225
return s.eth1Engine.FinalizeAndAssemble(config, header, state, txs, uncles, receipts, withdrawals, chain, syscall, call, logger)
220226
}
221227
header.RequestsHash = nil
222-
outTxs, outReceipts, rs, err := s.Finalize(config, header, state, txs, uncles, receipts, withdrawals, chain, syscall, logger)
228+
outTxs, outReceipts, outRequests, err := s.Finalize(config, header, state, txs, uncles, receipts, withdrawals, chain, syscall, logger)
223229

224230
if err != nil {
225231
return nil, nil, nil, nil, err
226232
}
227233
if config.IsPrague(header.Time) {
228-
header.RequestsHash = rs.Hash()
234+
header.RequestsHash = outRequests.Hash()
229235
}
230-
return types.NewBlockForAsembling(header, outTxs, uncles, outReceipts, withdrawals), outTxs, outReceipts, rs, nil
236+
return types.NewBlockForAsembling(header, outTxs, uncles, outReceipts, withdrawals), outTxs, outReceipts, outRequests, nil
231237
}
232238

233239
func (s *Merge) SealHash(header *types.Header) (hash libcommon.Hash) {

consensus/misc/eip6110.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,8 @@ func ParseDepositLogs(logs []*types.Log, depositContractAddress libcommon.Addres
8585
reqData = append(reqData, d...)
8686
}
8787
}
88-
return &types.FlatRequest{Type: types.DepositRequestType, RequestData: reqData}, nil
88+
if len(reqData) > 0 {
89+
return &types.FlatRequest{Type: types.DepositRequestType, RequestData: reqData}, nil
90+
}
91+
return nil, nil
8992
}

consensus/misc/eip7002.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ func DequeueWithdrawalRequests7002(syscall consensus.SystemCall) *types.FlatRequ
2929
log.Warn("Err with syscall to WithdrawalRequestAddress", "err", err)
3030
return nil
3131
}
32-
if res == nil {
33-
res = make([]byte, 0)
32+
if res != nil {
33+
// Just append the contract output
34+
return &types.FlatRequest{Type: types.WithdrawalRequestType, RequestData: res}
3435
}
35-
// Just append the contract outputs
36-
return &types.FlatRequest{Type: types.WithdrawalRequestType, RequestData: res}
36+
return nil
3737
}

consensus/misc/eip7251.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ func DequeueConsolidationRequests7251(syscall consensus.SystemCall) *types.FlatR
2929
log.Warn("Err with syscall to ConsolidationRequestAddress", "err", err)
3030
return nil
3131
}
32-
if res == nil {
33-
res = make([]byte, 0)
32+
if res != nil {
33+
// Just append the contract output as the request data
34+
return &types.FlatRequest{Type: types.ConsolidationRequestType, RequestData: res}
3435
}
35-
// Just append the contract outputs as the encoded request data
36-
return &types.FlatRequest{Type: types.ConsolidationRequestType, RequestData: res}
36+
return nil
3737
}

core/blockchain.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ func FinalizeBlockExecution(
337337
if isMining {
338338
newBlock, newTxs, newReceipt, retRequests, err = engine.FinalizeAndAssemble(cc, header, ibs, txs, uncles, receipts, withdrawals, chainReader, syscall, nil, logger)
339339
} else {
340-
// var rss types.Requests
341340
newTxs, newReceipt, retRequests, err = engine.Finalize(cc, header, ibs, txs, uncles, receipts, withdrawals, chainReader, syscall, logger)
342341
}
343342
if err != nil {

core/types/block.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import (
4040

4141
var (
4242
EmptyRootHash = libcommon.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
43-
EmptyRequestsHash = libcommon.HexToHash("6036c41849da9c076ed79654d434017387a88fb833c2856b32e18218b3341c5f")
43+
EmptyRequestsHash = libcommon.HexToHash("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855") // sha256.Sum256([]byte(""))
4444
EmptyUncleHash = rlpHash([]*Header(nil))
4545

4646
ExtraVanityLength = 32 // Fixed number of extra-data prefix bytes reserved for signer vanity

core/types/eip7685_requests.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ func (f *FlatRequest) copy() *FlatRequest {
5252
type FlatRequests []FlatRequest
5353

5454
func (r FlatRequests) Hash() *libcommon.Hash {
55-
if r == nil || len(r) < len(KnownRequestTypes) {
55+
if r == nil {
5656
return nil
5757
}
5858
sha := sha256.New()
59-
for i, t := range KnownRequestTypes {
60-
hi := sha256.Sum256(append([]byte{t}, r[i].RequestData...))
59+
for i, t := range r {
60+
hi := sha256.Sum256(append([]byte{t.Type}, r[i].RequestData...))
6161
sha.Write(hi[:])
6262
}
6363
h := libcommon.BytesToHash(sha.Sum(nil))

core/types/requests_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2025 The Erigon Authors
2+
// This file is part of Erigon.
3+
//
4+
// Erigon is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Lesser General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Erigon is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Lesser General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Lesser General Public License
15+
// along with Erigon. If not, see <http://www.gnu.org/licenses/>.
16+
17+
package types
18+
19+
import (
20+
"testing"
21+
)
22+
23+
func TestEmptyRequestsHashCalculation(t *testing.T) {
24+
reqs := make(FlatRequests, 0)
25+
h := reqs.Hash()
26+
testH := EmptyRequestsHash
27+
if *h != testH {
28+
t.Errorf("Requests Hash calculation error for empty hash, expected: %v, got: %v", testH, h)
29+
}
30+
}

turbo/builder/block_builder.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package builder
1818

1919
import (
20-
"fmt"
2120
"sync"
2221
"sync/atomic"
2322
"time"
@@ -50,11 +49,7 @@ func NewBlockBuilder(build BlockBuilderFunc, param *core.BlockBuilderParameters)
5049
log.Warn("Failed to build a block", "err", err)
5150
} else {
5251
block := result.Block
53-
reqLenStr := "nil"
54-
if len(result.Requests) == 3 {
55-
reqLenStr = fmt.Sprint("Deposit Requests", len(result.Requests[0].RequestData), "Withdrawal Requests", len(result.Requests[1].RequestData), "Consolidation Requests", len(result.Requests[2].RequestData))
56-
}
57-
log.Info("Built block", "hash", block.Hash(), "height", block.NumberU64(), "txs", len(block.Transactions()), "executionRequests", len(result.Requests), "Requests", reqLenStr, "gas used %", 100*float64(block.GasUsed())/float64(block.GasLimit()), "time", time.Since(t))
52+
log.Info("Built block", "hash", block.Hash(), "height", block.NumberU64(), "txs", len(block.Transactions()), "executionRequests", len(result.Requests), "gas used %", 100*float64(block.GasUsed())/float64(block.GasLimit()), "time", time.Since(t))
5853
}
5954

6055
builder.syncCond.L.Lock()

turbo/engineapi/engine_server.go

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,6 @@ func (s *EngineServer) checkRequestsPresence(version clparams.StateVersion, exec
147147
if executionRequests != nil {
148148
return &rpc.InvalidParamsError{Message: "requests in EngineAPI not supported before Prague"}
149149
}
150-
} else {
151-
if executionRequests == nil {
152-
return &rpc.InvalidParamsError{Message: "missing requests list"}
153-
}
154-
if len(executionRequests) != len(types.KnownRequestTypes) {
155-
return &rpc.InvalidParamsError{Message: "invalid requests lists"}
156-
}
157150
}
158151
return nil
159152
}
@@ -215,12 +208,12 @@ func (s *EngineServer) newPayload(ctx context.Context, req *engine_types.Executi
215208
return nil, err
216209
}
217210
if version >= clparams.ElectraVersion {
218-
requests = make(types.FlatRequests, len(types.KnownRequestTypes))
219-
for i, r := range types.KnownRequestTypes {
220-
if len(executionRequests) == i {
221-
executionRequests = append(executionRequests, []byte{})
211+
requests = make(types.FlatRequests, 0)
212+
for i, r := range executionRequests {
213+
if len(r) <= 1 {
214+
return nil, &rpc.InvalidParamsError{Message: fmt.Sprintf("Invalid Request at index %d", i)}
222215
}
223-
requests[i] = types.FlatRequest{Type: r, RequestData: executionRequests[i]}
216+
requests = append(requests, types.FlatRequest{Type: r[0], RequestData: r})
224217
}
225218
rh := requests.Hash()
226219
header.RequestsHash = rh
@@ -499,16 +492,9 @@ func (s *EngineServer) getPayload(ctx context.Context, payloadId uint64, version
499492
data := resp.Data
500493
var executionRequests []hexutility.Bytes
501494
if version >= clparams.ElectraVersion {
502-
executionRequests = make([]hexutility.Bytes, len(types.KnownRequestTypes))
503-
if len(data.Requests.Requests) != 3 {
504-
s.logger.Warn("Error in getPayload - data.Requests.Requests len not 3")
505-
}
506-
for i := 0; i < len(types.KnownRequestTypes); i++ {
507-
if len(data.Requests.Requests) < i+1 || data.Requests.Requests[i] == nil {
508-
executionRequests[i] = make(hexutility.Bytes, 0)
509-
} else {
510-
executionRequests[i] = data.Requests.Requests[i]
511-
}
495+
executionRequests = make([]hexutility.Bytes, 0)
496+
for _, r := range data.Requests.Requests {
497+
executionRequests = append(executionRequests, r)
512498
}
513499
}
514500

0 commit comments

Comments
 (0)