Skip to content

Commit 3138869

Browse files
fjlqianhh
authored andcommitted
all: exclude empty outputs in requests commitment (#30670)
Implements changes from these spec PRs: - ethereum/EIPs#8989 - ethereum/execution-apis#599
1 parent 6bdac04 commit 3138869

20 files changed

+62
-86
lines changed

beacon/engine/types.go

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,7 @@ func ExecutableDataToBlockNoHash(data ExecutableData, versionedHashes []common.H
265265

266266
var requestsHash *common.Hash
267267
if requests != nil {
268-
// Put back request type byte.
269-
typedRequests := make([][]byte, len(requests))
270-
for i, reqdata := range requests {
271-
typedReqdata := make([]byte, len(reqdata)+1)
272-
typedReqdata[0] = byte(i)
273-
copy(typedReqdata[1:], reqdata)
274-
typedRequests[i] = typedReqdata
275-
}
276-
h := types.CalcRequestsHash(typedRequests)
268+
h := types.CalcRequestsHash(requests)
277269
requestsHash = &h
278270
}
279271

@@ -343,20 +335,11 @@ func BlockToExecutableData(block *types.Block, fees *big.Int, sidecars []*types.
343335
}
344336
}
345337

346-
// Remove type byte in requests.
347-
var plainRequests [][]byte
348-
if requests != nil {
349-
plainRequests = make([][]byte, len(requests))
350-
for i, reqdata := range requests {
351-
plainRequests[i] = reqdata[1:]
352-
}
353-
}
354-
355338
return &ExecutionPayloadEnvelope{
356339
ExecutionPayload: data,
357340
BlockValue: fees,
358341
BlobsBundle: &bundle,
359-
Requests: plainRequests,
342+
Requests: requests,
360343
Override: false,
361344
}
362345
}

cmd/evm/internal/t8ntool/execution.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -375,21 +375,19 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
375375
// Gather the execution-layer triggered requests.
376376
var requests [][]byte
377377
if chainConfig.IsPrague(vmContext.BlockNumber, vmContext.Time) {
378-
// EIP-6110 deposits
378+
requests = [][]byte{}
379+
// EIP-6110
379380
var allLogs []*types.Log
380381
for _, receipt := range receipts {
381382
allLogs = append(allLogs, receipt.Logs...)
382383
}
383-
depositRequests, err := core.ParseDepositLogs(allLogs, chainConfig)
384-
if err != nil {
384+
if err := core.ParseDepositLogs(&requests, allLogs, chainConfig); err != nil {
385385
return nil, nil, nil, NewError(ErrorEVM, fmt.Errorf("could not parse requests logs: %v", err))
386386
}
387-
requests = append(requests, depositRequests)
388-
389-
// EIP-7002 withdrawals
390-
requests = append(requests, core.ProcessWithdrawalQueue(evm))
391-
// EIP-7251 consolidations
392-
requests = append(requests, core.ProcessConsolidationQueue(evm))
387+
// EIP-7002
388+
core.ProcessWithdrawalQueue(&requests, evm)
389+
// EIP-7251
390+
core.ProcessConsolidationQueue(&requests, evm)
393391
}
394392

395393
// Commit block

core/chain_makers.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -349,25 +349,22 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
349349

350350
var requests [][]byte
351351
if config.IsPrague(b.header.Number, b.header.Time) {
352+
requests = [][]byte{}
352353
// EIP-6110 deposits
353354
var blockLogs []*types.Log
354355
for _, r := range b.receipts {
355356
blockLogs = append(blockLogs, r.Logs...)
356357
}
357-
depositRequests, err := ParseDepositLogs(blockLogs, config)
358-
if err != nil {
358+
if err := ParseDepositLogs(&requests, blockLogs, config); err != nil {
359359
panic(fmt.Sprintf("failed to parse deposit log: %v", err))
360360
}
361-
requests = append(requests, depositRequests)
362361
// create EVM for system calls
363362
blockContext := NewEVMBlockContext(b.header, cm, &b.header.Coinbase)
364363
evm := vm.NewEVM(blockContext, statedb, cm.config, vm.Config{})
365-
// EIP-7002 withdrawals
366-
withdrawalRequests := ProcessWithdrawalQueue(evm)
367-
requests = append(requests, withdrawalRequests)
368-
// EIP-7251 consolidations
369-
consolidationRequests := ProcessConsolidationQueue(evm)
370-
requests = append(requests, consolidationRequests)
364+
// EIP-7002
365+
ProcessWithdrawalQueue(&requests, evm)
366+
// EIP-7251
367+
ProcessConsolidationQueue(&requests, evm)
371368
}
372369
if requests != nil {
373370
reqHash := types.CalcRequestsHash(requests)

core/genesis.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,7 @@ func (g *Genesis) toBlockWithRoot(root common.Hash) *types.Block {
503503
}
504504
}
505505
if conf.IsPrague(num, g.Timestamp) {
506-
emptyRequests := [][]byte{{0x00}, {0x01}, {0x02}}
507-
rhash := types.CalcRequestsHash(emptyRequests)
508-
head.RequestsHash = &rhash
506+
head.RequestsHash = &types.EmptyRequestsHash
509507
}
510508
}
511509
return types.NewBlock(head, &types.Body{Withdrawals: withdrawals}, nil, trie.NewStackTrie(nil))

core/state_processor.go

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,15 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
124124
// Read requests if Prague is enabled.
125125
var requests [][]byte
126126
if p.config.IsPrague(block.Number(), block.Time()) {
127-
// EIP-6110 deposits
128-
depositRequests, err := ParseDepositLogs(allLogs, p.config)
129-
if err != nil {
127+
requests = [][]byte{}
128+
// EIP-6110
129+
if err := ParseDepositLogs(&requests, allLogs, p.config); err != nil {
130130
return nil, err
131131
}
132-
requests = append(requests, depositRequests)
133-
// EIP-7002 withdrawals
134-
withdrawalRequests := ProcessWithdrawalQueue(evm)
135-
requests = append(requests, withdrawalRequests)
136-
// EIP-7251 consolidations
137-
consolidationRequests := ProcessConsolidationQueue(evm)
138-
requests = append(requests, consolidationRequests)
132+
// EIP-7002
133+
ProcessWithdrawalQueue(&requests, evm)
134+
// EIP-7251
135+
ProcessConsolidationQueue(&requests, evm)
139136
}
140137

141138
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
@@ -289,17 +286,17 @@ func ProcessParentBlockHash(prevHash common.Hash, evm *vm.EVM) {
289286

290287
// ProcessWithdrawalQueue calls the EIP-7002 withdrawal queue contract.
291288
// It returns the opaque request data returned by the contract.
292-
func ProcessWithdrawalQueue(evm *vm.EVM) []byte {
293-
return processRequestsSystemCall(evm, 0x01, params.WithdrawalQueueAddress)
289+
func ProcessWithdrawalQueue(requests *[][]byte, evm *vm.EVM) {
290+
processRequestsSystemCall(requests, evm, 0x01, params.WithdrawalQueueAddress)
294291
}
295292

296293
// ProcessConsolidationQueue calls the EIP-7251 consolidation queue contract.
297294
// It returns the opaque request data returned by the contract.
298-
func ProcessConsolidationQueue(evm *vm.EVM) []byte {
299-
return processRequestsSystemCall(evm, 0x02, params.ConsolidationQueueAddress)
295+
func ProcessConsolidationQueue(requests *[][]byte, evm *vm.EVM) {
296+
processRequestsSystemCall(requests, evm, 0x02, params.ConsolidationQueueAddress)
300297
}
301298

302-
func processRequestsSystemCall(evm *vm.EVM, requestType byte, addr common.Address) []byte {
299+
func processRequestsSystemCall(requests *[][]byte, evm *vm.EVM, requestType byte, addr common.Address) {
303300
if tracer := evm.Config.Tracer; tracer != nil {
304301
if tracer.OnSystemCallStart != nil {
305302
tracer.OnSystemCallStart()
@@ -320,28 +317,34 @@ func processRequestsSystemCall(evm *vm.EVM, requestType byte, addr common.Addres
320317
evm.StateDB.AddAddressToAccessList(addr)
321318
ret, _, _ := evm.Call(vm.AccountRef(msg.From), *msg.To, msg.Data, 30_000_000, common.U2560)
322319
evm.StateDB.Finalise(true)
320+
if len(ret) == 0 {
321+
return // skip empty output
322+
}
323323

324-
// Create withdrawals requestsData with prefix 0x01
324+
// Append prefixed requestsData to the requests list.
325325
requestsData := make([]byte, len(ret)+1)
326326
requestsData[0] = requestType
327327
copy(requestsData[1:], ret)
328-
return requestsData
328+
*requests = append(*requests, requestsData)
329329
}
330330

331331
// ParseDepositLogs extracts the EIP-6110 deposit values from logs emitted by
332332
// BeaconDepositContract.
333-
func ParseDepositLogs(logs []*types.Log, config *params.ChainConfig) ([]byte, error) {
333+
func ParseDepositLogs(requests *[][]byte, logs []*types.Log, config *params.ChainConfig) error {
334334
deposits := make([]byte, 1) // note: first byte is 0x00 (== deposit request type)
335335
for _, log := range logs {
336336
if log.Address == config.DepositContractAddress {
337337
request, err := types.DepositLogToRequest(log.Data)
338338
if err != nil {
339-
return nil, fmt.Errorf("unable to parse deposit data: %v", err)
339+
return fmt.Errorf("unable to parse deposit data: %v", err)
340340
}
341341
deposits = append(deposits, request...)
342342
}
343343
}
344-
return deposits, nil
344+
if len(deposits) > 1 {
345+
*requests = append(*requests, deposits)
346+
}
347+
return nil
345348
}
346349

347350
// ProcessOnPersist applies a system call to the governance contract.

core/types/hashes.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ var (
4141
// EmptyWithdrawalsHash is the known hash of the empty withdrawal set.
4242
EmptyWithdrawalsHash = common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
4343

44+
// EmptyRequestsHash is the known hash of an empty request set, sha256("").
45+
EmptyRequestsHash = common.HexToHash("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
46+
4447
// EmptyVerkleHash is the known hash of an empty verkle trie.
4548
EmptyVerkleHash = common.Hash{}
4649
)

eth/tracers/internal/tracetest/supply_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TestSupplyOmittedFields(t *testing.T) {
8686

8787
expected := supplyInfo{
8888
Number: 0,
89-
Hash: common.HexToHash("0xc02ee8ee5b54a40e43f0fa827d431e1bd4f217e941790dda10b2521d1925a20b"),
89+
Hash: common.HexToHash("0x3055fc27d6b4a08eb07033a0d1ee755a4b2988086f28a6189eac1b507525eeb1"),
9090
ParentHash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
9191
}
9292
actual := out[expected.Number]

internal/ethapi/testdata/eth_getBlockReceipts-block-with-blob-tx.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
"blobGasPrice": "0x1",
44
"blobGasUsed": "0x20000",
5-
"blockHash": "0x11e6318d77a45c01f89f76b56d36c6936c5250f4e2bd238cb7b09df73cf0cb7d",
5+
"blockHash": "0x17124e31fb075a301b1d7d4135683b0a09fe4e6d453c54e2e734d5ee00744a49",
66
"blockNumber": "0x6",
77
"contractAddress": null,
88
"cumulativeGasUsed": "0x5208",

internal/ethapi/testdata/eth_getBlockReceipts-block-with-contract-create-tx.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"blockHash": "0x5526cd89bc188f20fd5e9bb50d8054dc5a51a81a74ed07eacf36a4a8b10de4b1",
3+
"blockHash": "0xb3e447c77374fd285964cba692e96b1673a88a959726826b5b6e2dca15472b0a",
44
"blockNumber": "0x2",
55
"contractAddress": "0xae9bea628c4ce503dcfd7e305cab4e29e7476592",
66
"cumulativeGasUsed": "0xcf50",

internal/ethapi/testdata/eth_getBlockReceipts-block-with-dynamic-fee-tx.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"blockHash": "0x3e946aa9e252873af511b257d9d89a1bcafa54ce7c6a6442f8407ecdf81e288d",
3+
"blockHash": "0x102e50de30318ee99a03a09db74387e79cad3165bf6840cc84249806a2a302f3",
44
"blockNumber": "0x4",
55
"contractAddress": null,
66
"cumulativeGasUsed": "0x538d",

0 commit comments

Comments
 (0)