Skip to content

Commit 90800ee

Browse files
fjlsebastianst
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 008993f commit 90800ee

20 files changed

+69
-86
lines changed

beacon/engine/types.go

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -299,15 +299,7 @@ func ExecutableDataToBlockNoHash(data ExecutableData, versionedHashes []common.H
299299

300300
var requestsHash *common.Hash
301301
if requests != nil {
302-
// Put back request type byte.
303-
typedRequests := make([][]byte, len(requests))
304-
for i, reqdata := range requests {
305-
typedReqdata := make([]byte, len(reqdata)+1)
306-
typedReqdata[0] = byte(i)
307-
copy(typedReqdata[1:], reqdata)
308-
typedRequests[i] = typedReqdata
309-
}
310-
h := types.CalcRequestsHash(typedRequests)
302+
h := types.CalcRequestsHash(requests)
311303
requestsHash = &h
312304
}
313305

@@ -378,20 +370,15 @@ func BlockToExecutableData(block *types.Block, fees *big.Int, sidecars []*types.
378370
bundle.Proofs = append(bundle.Proofs, hexutil.Bytes(sidecar.Proofs[j][:]))
379371
}
380372
}
381-
// Remove type byte in requests.
382-
var plainRequests [][]byte
383-
if requests != nil {
384-
plainRequests = make([][]byte, len(requests))
385-
for i, reqdata := range requests {
386-
plainRequests[i] = reqdata[1:]
387-
}
388-
}
373+
389374
return &ExecutionPayloadEnvelope{
390-
ExecutionPayload: data,
391-
BlockValue: fees,
392-
BlobsBundle: &bundle,
393-
Requests: plainRequests,
394-
Override: false,
375+
ExecutionPayload: data,
376+
BlockValue: fees,
377+
BlobsBundle: &bundle,
378+
Requests: requests,
379+
Override: false,
380+
381+
// OP-Stack addition
395382
ParentBeaconBlockRoot: block.BeaconRoot(),
396383
}
397384
}

cmd/evm/internal/t8ntool/execution.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -366,21 +366,19 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
366366
// Gather the execution-layer triggered requests.
367367
var requests [][]byte
368368
if chainConfig.IsPrague(vmContext.BlockNumber, vmContext.Time) {
369-
// EIP-6110 deposits
369+
requests = [][]byte{}
370+
// EIP-6110
370371
var allLogs []*types.Log
371372
for _, receipt := range receipts {
372373
allLogs = append(allLogs, receipt.Logs...)
373374
}
374-
depositRequests, err := core.ParseDepositLogs(allLogs, chainConfig)
375-
if err != nil {
375+
if err := core.ParseDepositLogs(&requests, allLogs, chainConfig); err != nil {
376376
return nil, nil, nil, NewError(ErrorEVM, fmt.Errorf("could not parse requests logs: %v", err))
377377
}
378-
requests = append(requests, depositRequests)
379-
380-
// EIP-7002 withdrawals
381-
requests = append(requests, core.ProcessWithdrawalQueue(evm))
382-
// EIP-7251 consolidations
383-
requests = append(requests, core.ProcessConsolidationQueue(evm))
378+
// EIP-7002
379+
core.ProcessWithdrawalQueue(&requests, evm)
380+
// EIP-7251
381+
core.ProcessConsolidationQueue(&requests, evm)
384382
}
385383

386384
// Commit block

core/chain_makers.go

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

355355
var requests [][]byte
356356
if config.IsPrague(b.header.Number, b.header.Time) {
357+
requests = [][]byte{}
357358
// EIP-6110 deposits
358359
var blockLogs []*types.Log
359360
for _, r := range b.receipts {
360361
blockLogs = append(blockLogs, r.Logs...)
361362
}
362-
depositRequests, err := ParseDepositLogs(blockLogs, config)
363-
if err != nil {
363+
if err := ParseDepositLogs(&requests, blockLogs, config); err != nil {
364364
panic(fmt.Sprintf("failed to parse deposit log: %v", err))
365365
}
366-
requests = append(requests, depositRequests)
367366
// create EVM for system calls
368367
blockContext := NewEVMBlockContext(b.header, cm, &b.header.Coinbase, b.cm.config, b.statedb)
369368
evm := vm.NewEVM(blockContext, statedb, cm.config, vm.Config{})
370-
// EIP-7002 withdrawals
371-
withdrawalRequests := ProcessWithdrawalQueue(evm)
372-
requests = append(requests, withdrawalRequests)
373-
// EIP-7251 consolidations
374-
consolidationRequests := ProcessConsolidationQueue(evm)
375-
requests = append(requests, consolidationRequests)
369+
// EIP-7002
370+
ProcessWithdrawalQueue(&requests, evm)
371+
// EIP-7251
372+
ProcessConsolidationQueue(&requests, evm)
376373
}
377374
if requests != nil {
378375
reqHash := types.CalcRequestsHash(requests)

core/genesis.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,7 @@ func (g *Genesis) toBlockWithRoot(stateRoot, storageRootMessagePasser common.Has
592592
}
593593
}
594594
if conf.IsPrague(num, g.Timestamp) {
595-
emptyRequests := [][]byte{{0x00}, {0x01}, {0x02}}
596-
rhash := types.CalcRequestsHash(emptyRequests)
597-
head.RequestsHash = &rhash
595+
head.RequestsHash = &types.EmptyRequestsHash
598596
}
599597
// If Isthmus is active at genesis, set the WithdrawalRoot to the storage root of the L2ToL1MessagePasser contract.
600598
if g.Config.IsOptimismIsthmus(g.Timestamp) {

core/state_processor.go

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,15 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
106106
// Read requests if Prague is enabled.
107107
var requests [][]byte
108108
if p.config.IsPrague(block.Number(), block.Time()) {
109-
// EIP-6110 deposits
110-
depositRequests, err := ParseDepositLogs(allLogs, p.config)
111-
if err != nil {
109+
requests = [][]byte{}
110+
// EIP-6110
111+
if err := ParseDepositLogs(&requests, allLogs, p.config); err != nil {
112112
return nil, err
113113
}
114-
requests = append(requests, depositRequests)
115-
// EIP-7002 withdrawals
116-
withdrawalRequests := ProcessWithdrawalQueue(evm)
117-
requests = append(requests, withdrawalRequests)
118-
// EIP-7251 consolidations
119-
consolidationRequests := ProcessConsolidationQueue(evm)
120-
requests = append(requests, consolidationRequests)
114+
// EIP-7002
115+
ProcessWithdrawalQueue(&requests, evm)
116+
// EIP-7251
117+
ProcessConsolidationQueue(&requests, evm)
121118
}
122119

123120
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
@@ -298,17 +295,17 @@ func ProcessParentBlockHash(prevHash common.Hash, evm *vm.EVM) {
298295

299296
// ProcessWithdrawalQueue calls the EIP-7002 withdrawal queue contract.
300297
// It returns the opaque request data returned by the contract.
301-
func ProcessWithdrawalQueue(evm *vm.EVM) []byte {
302-
return processRequestsSystemCall(evm, 0x01, params.WithdrawalQueueAddress)
298+
func ProcessWithdrawalQueue(requests *[][]byte, evm *vm.EVM) {
299+
processRequestsSystemCall(requests, evm, 0x01, params.WithdrawalQueueAddress)
303300
}
304301

305302
// ProcessConsolidationQueue calls the EIP-7251 consolidation queue contract.
306303
// It returns the opaque request data returned by the contract.
307-
func ProcessConsolidationQueue(evm *vm.EVM) []byte {
308-
return processRequestsSystemCall(evm, 0x02, params.ConsolidationQueueAddress)
304+
func ProcessConsolidationQueue(requests *[][]byte, evm *vm.EVM) {
305+
processRequestsSystemCall(requests, evm, 0x02, params.ConsolidationQueueAddress)
309306
}
310307

311-
func processRequestsSystemCall(evm *vm.EVM, requestType byte, addr common.Address) []byte {
308+
func processRequestsSystemCall(requests *[][]byte, evm *vm.EVM, requestType byte, addr common.Address) {
312309
if tracer := evm.Config.Tracer; tracer != nil {
313310
if tracer.OnSystemCallStart != nil {
314311
tracer.OnSystemCallStart()
@@ -329,26 +326,32 @@ func processRequestsSystemCall(evm *vm.EVM, requestType byte, addr common.Addres
329326
evm.StateDB.AddAddressToAccessList(addr)
330327
ret, _, _ := evm.Call(vm.AccountRef(msg.From), *msg.To, msg.Data, 30_000_000, common.U2560)
331328
evm.StateDB.Finalise(true)
329+
if len(ret) == 0 {
330+
return // skip empty output
331+
}
332332

333-
// Create withdrawals requestsData with prefix 0x01
333+
// Append prefixed requestsData to the requests list.
334334
requestsData := make([]byte, len(ret)+1)
335335
requestsData[0] = requestType
336336
copy(requestsData[1:], ret)
337-
return requestsData
337+
*requests = append(*requests, requestsData)
338338
}
339339

340340
// ParseDepositLogs extracts the EIP-6110 deposit values from logs emitted by
341341
// BeaconDepositContract.
342-
func ParseDepositLogs(logs []*types.Log, config *params.ChainConfig) ([]byte, error) {
342+
func ParseDepositLogs(requests *[][]byte, logs []*types.Log, config *params.ChainConfig) error {
343343
deposits := make([]byte, 1) // note: first byte is 0x00 (== deposit request type)
344344
for _, log := range logs {
345345
if log.Address == config.DepositContractAddress {
346346
request, err := types.DepositLogToRequest(log.Data)
347347
if err != nil {
348-
return nil, fmt.Errorf("unable to parse deposit data: %v", err)
348+
return fmt.Errorf("unable to parse deposit data: %v", err)
349349
}
350350
deposits = append(deposits, request...)
351351
}
352352
}
353-
return deposits, nil
353+
if len(deposits) > 1 {
354+
*requests = append(*requests, deposits)
355+
}
356+
return nil
354357
}

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)