From fdaa7015ef6c28fd824b8fc3ad73455dbdcf7eed Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Thu, 24 Oct 2024 22:23:28 +0200 Subject: [PATCH] all: remove empty items in requests commitment --- beacon/engine/types.go | 21 ++------------------- cmd/evm/internal/t8ntool/execution.go | 16 ++++++++++++---- core/chain_makers.go | 13 ++++++++++--- core/genesis.go | 4 +--- core/state_processor.go | 19 ++++++++++++++++--- core/types/hashes.go | 3 +++ miner/worker.go | 13 ++++++++++--- 7 files changed, 54 insertions(+), 35 deletions(-) diff --git a/beacon/engine/types.go b/beacon/engine/types.go index 9f41aa04ca..984090ef89 100644 --- a/beacon/engine/types.go +++ b/beacon/engine/types.go @@ -265,15 +265,7 @@ func ExecutableDataToBlockNoHash(data ExecutableData, versionedHashes []common.H var requestsHash *common.Hash if requests != nil { - // Put back request type byte. - typedRequests := make([][]byte, len(requests)) - for i, reqdata := range requests { - typedReqdata := make([]byte, len(reqdata)+1) - typedReqdata[0] = byte(i) - copy(typedReqdata[1:], reqdata) - typedRequests[i] = typedReqdata - } - h := types.CalcRequestsHash(typedRequests) + h := types.CalcRequestsHash(requests) requestsHash = &h } @@ -343,20 +335,11 @@ func BlockToExecutableData(block *types.Block, fees *big.Int, sidecars []*types. } } - // Remove type byte in requests. - var plainRequests [][]byte - if requests != nil { - plainRequests = make([][]byte, len(requests)) - for i, reqdata := range requests { - plainRequests[i] = reqdata[1:] - } - } - return &ExecutionPayloadEnvelope{ ExecutionPayload: data, BlockValue: fees, BlobsBundle: &bundle, - Requests: plainRequests, + Requests: requests, Override: false, } } diff --git a/cmd/evm/internal/t8ntool/execution.go b/cmd/evm/internal/t8ntool/execution.go index c0623a69bf..f4c0924c35 100644 --- a/cmd/evm/internal/t8ntool/execution.go +++ b/cmd/evm/internal/t8ntool/execution.go @@ -366,6 +366,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig, // Gather the execution-layer triggered requests. var requests [][]byte if chainConfig.IsPrague(vmContext.BlockNumber, vmContext.Time) { + requests = [][]byte{} // EIP-6110 deposits var allLogs []*types.Log for _, receipt := range receipts { @@ -375,12 +376,19 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig, if err != nil { return nil, nil, nil, NewError(ErrorEVM, fmt.Errorf("could not parse requests logs: %v", err)) } - requests = append(requests, depositRequests) - + if depositRequests != nil { + requests = append(requests, depositRequests) + } // EIP-7002 withdrawals - requests = append(requests, core.ProcessWithdrawalQueue(evm)) + withdrawalRequests := core.ProcessWithdrawalQueue(evm) + if withdrawalRequests != nil { + requests = append(requests, withdrawalRequests) + } // EIP-7251 consolidations - requests = append(requests, core.ProcessConsolidationQueue(evm)) + consolidationRequests := core.ProcessConsolidationQueue(evm) + if consolidationRequests != nil { + requests = append(requests, consolidationRequests) + } } // Commit block diff --git a/core/chain_makers.go b/core/chain_makers.go index e679a9e557..4700285987 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -349,6 +349,7 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse var requests [][]byte if config.IsPrague(b.header.Number, b.header.Time) { + requests = [][]byte{} // EIP-6110 deposits var blockLogs []*types.Log for _, r := range b.receipts { @@ -358,16 +359,22 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse if err != nil { panic(fmt.Sprintf("failed to parse deposit log: %v", err)) } - requests = append(requests, depositRequests) + if depositRequests != nil { + requests = append(requests, depositRequests) + } // create EVM for system calls blockContext := NewEVMBlockContext(b.header, cm, &b.header.Coinbase) evm := vm.NewEVM(blockContext, statedb, cm.config, vm.Config{}) // EIP-7002 withdrawals withdrawalRequests := ProcessWithdrawalQueue(evm) - requests = append(requests, withdrawalRequests) + if withdrawalRequests != nil { + requests = append(requests, withdrawalRequests) + } // EIP-7251 consolidations consolidationRequests := ProcessConsolidationQueue(evm) - requests = append(requests, consolidationRequests) + if consolidationRequests != nil { + requests = append(requests, consolidationRequests) + } } if requests != nil { reqHash := types.CalcRequestsHash(requests) diff --git a/core/genesis.go b/core/genesis.go index eff92084eb..85ef049ba6 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -472,9 +472,7 @@ func (g *Genesis) toBlockWithRoot(root common.Hash) *types.Block { } } if conf.IsPrague(num, g.Timestamp) { - emptyRequests := [][]byte{{0x00}, {0x01}, {0x02}} - rhash := types.CalcRequestsHash(emptyRequests) - head.RequestsHash = &rhash + head.RequestsHash = &types.EmptyRequestsHash } } return types.NewBlock(head, &types.Body{Withdrawals: withdrawals}, nil, trie.NewStackTrie(nil)) diff --git a/core/state_processor.go b/core/state_processor.go index 1703377111..fe1a09e010 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -106,18 +106,25 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg // Read requests if Prague is enabled. var requests [][]byte if p.config.IsPrague(block.Number(), block.Time()) { + requests = [][]byte{} // EIP-6110 deposits depositRequests, err := ParseDepositLogs(allLogs, p.config) if err != nil { return nil, err } - requests = append(requests, depositRequests) + if depositRequests != nil { + requests = append(requests, depositRequests) + } // EIP-7002 withdrawals withdrawalRequests := ProcessWithdrawalQueue(evm) - requests = append(requests, withdrawalRequests) + if withdrawalRequests != nil { + requests = append(requests, withdrawalRequests) + } // EIP-7251 consolidations consolidationRequests := ProcessConsolidationQueue(evm) - requests = append(requests, consolidationRequests) + if consolidationRequests != nil { + requests = append(requests, consolidationRequests) + } } // Finalize the block, applying any consensus engine specific extras (e.g. block rewards) @@ -302,6 +309,9 @@ func processRequestsSystemCall(evm *vm.EVM, requestType byte, addr common.Addres evm.StateDB.AddAddressToAccessList(addr) ret, _, _ := evm.Call(vm.AccountRef(msg.From), *msg.To, msg.Data, 30_000_000, common.U2560) evm.StateDB.Finalise(true) + if len(ret) == 0 { + return nil + } // Create withdrawals requestsData with prefix 0x01 requestsData := make([]byte, len(ret)+1) @@ -323,5 +333,8 @@ func ParseDepositLogs(logs []*types.Log, config *params.ChainConfig) ([]byte, er deposits = append(deposits, request...) } } + if len(deposits) == 1 { + deposits = nil + } return deposits, nil } diff --git a/core/types/hashes.go b/core/types/hashes.go index 43e9130fd1..55506d63d0 100644 --- a/core/types/hashes.go +++ b/core/types/hashes.go @@ -41,6 +41,9 @@ var ( // EmptyWithdrawalsHash is the known hash of the empty withdrawal set. EmptyWithdrawalsHash = common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421") + // EmptyRequestsHash is the known hash of an empty request set, sha256(""). + EmptyRequestsHash = common.HexToHash("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855") + // EmptyVerkleHash is the known hash of an empty verkle trie. EmptyVerkleHash = common.Hash{} ) diff --git a/miner/worker.go b/miner/worker.go index aeb6cfcdc2..cd1496417e 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -121,18 +121,25 @@ func (miner *Miner) generateWork(params *generateParams, witness bool) *newPaylo // Collect consensus-layer requests if Prague is enabled. var requests [][]byte if miner.chainConfig.IsPrague(work.header.Number, work.header.Time) { + requests = [][]byte{} // EIP-6110 deposits depositRequests, err := core.ParseDepositLogs(allLogs, miner.chainConfig) if err != nil { return &newPayloadResult{err: err} } - requests = append(requests, depositRequests) + if depositRequests != nil { + requests = append(requests, depositRequests) + } // EIP-7002 withdrawals withdrawalRequests := core.ProcessWithdrawalQueue(work.evm) - requests = append(requests, withdrawalRequests) + if withdrawalRequests != nil { + requests = append(requests, withdrawalRequests) + } // EIP-7251 consolidations consolidationRequests := core.ProcessConsolidationQueue(work.evm) - requests = append(requests, consolidationRequests) + if consolidationRequests != nil { + requests = append(requests, consolidationRequests) + } } if requests != nil { reqHash := types.CalcRequestsHash(requests)