From 177baacf95e9ad559db8685d387d123a83077fda Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Wed, 9 Oct 2024 14:51:39 +0200 Subject: [PATCH] core: perform EIP-7002, EIP-7251 system calls --- core/state_processor.go | 53 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/core/state_processor.go b/core/state_processor.go index c4e2bcf1e5..fe0304e81d 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -102,11 +102,18 @@ 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()) { + // EIP-6110 deposits depositRequests, err := ParseDepositLogs(allLogs, p.config) if err != nil { return nil, err } requests = append(requests, depositRequests) + // EIP-7002 withdrawals + withdrawalRequests := ProcessWithdrawalQueue(vmenv, statedb) + requests = append(requests, withdrawalRequests) + // EIP-7251 consolidations + consolidationRequests := ProcessConsolidationQueue(vmenv, statedb) + requests = append(requests, consolidationRequests) } // Finalize the block, applying any consensus engine specific extras (e.g. block rewards) @@ -219,9 +226,6 @@ func ProcessBeaconBlockRoot(beaconRoot common.Hash, vmenv *vm.EVM, statedb *stat defer tracer.OnSystemCallEnd() } } - - // If EIP-4788 is enabled, we need to invoke the beaconroot storage contract with - // the new root msg := &Message{ From: params.SystemAddress, GasLimit: 30_000_000, @@ -248,7 +252,6 @@ func ProcessParentBlockHash(prevHash common.Hash, vmenv *vm.EVM, statedb *state. defer tracer.OnSystemCallEnd() } } - msg := &Message{ From: params.SystemAddress, GasLimit: 30_000_000, @@ -264,6 +267,48 @@ func ProcessParentBlockHash(prevHash common.Hash, vmenv *vm.EVM, statedb *state. statedb.Finalise(true) } +// ProcessWithdrawalQueue calls the EIP-7002 withdrawal queue contract. +// It returns the opaque request data returned by the contract. +func ProcessWithdrawalQueue(vmenv *vm.EVM, statedb *state.StateDB) []byte { + return processRequestsSystemCall(vmenv, statedb, 0x01, params.WithdrawalQueueAddress) +} + +// ProcessConsolidationQueue calls the EIP-7251 consolidation queue contract. +// It returns the opaque request data returned by the contract. +func ProcessConsolidationQueue(vmenv *vm.EVM, statedb *state.StateDB) []byte { + return processRequestsSystemCall(vmenv, statedb, 0x02, params.ConsolidationQueueAddress) +} + +func processRequestsSystemCall(vmenv *vm.EVM, statedb *state.StateDB, requestType byte, addr common.Address) []byte { + if tracer := vmenv.Config.Tracer; tracer != nil { + if tracer.OnSystemCallStart != nil { + tracer.OnSystemCallStart() + } + if tracer.OnSystemCallEnd != nil { + defer tracer.OnSystemCallEnd() + } + } + + msg := &Message{ + From: params.SystemAddress, + GasLimit: 30_000_000, + GasPrice: common.Big0, + GasFeeCap: common.Big0, + GasTipCap: common.Big0, + To: &addr, + } + vmenv.Reset(NewEVMTxContext(msg), statedb) + statedb.AddAddressToAccessList(addr) + ret, _, _ := vmenv.Call(vm.AccountRef(msg.From), *msg.To, msg.Data, 30_000_000, common.U2560) + statedb.Finalise(true) + + // Create withdrawals requestsData with prefix 0x01 + requestsData := make([]byte, len(ret)+1) + requestsData[0] = requestType + copy(requestsData[1:], ret) + return requestsData +} + // ParseDepositLogs extracts the EIP-6110 deposit values from logs emitted by // BeaconDepositContract. func ParseDepositLogs(logs []*types.Log, config *params.ChainConfig) ([]byte, error) {