Skip to content

Commit 54a4b1d

Browse files
lightclientholiman
authored andcommitted
cmd/evm: fixup issues with requests in t8n (#30584)
This fixes a few issues missed in #29052: * `requests` must be hex encoded, so added a helper to marshal. * The statedb was committed too early and so the result of the system calls was lost. * For devnet-4 we need to pull off the type byte prefix from the request data.
1 parent 15b0152 commit 54a4b1d

File tree

2 files changed

+167
-22
lines changed

2 files changed

+167
-22
lines changed

cmd/evm/internal/t8ntool/execution.go

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"math/big"
2424

2525
"github.com/ethereum/go-ethereum/common"
26+
"github.com/ethereum/go-ethereum/common/hexutil"
2627
"github.com/ethereum/go-ethereum/common/math"
2728
"github.com/ethereum/go-ethereum/consensus/ethash"
2829
"github.com/ethereum/go-ethereum/consensus/misc"
@@ -50,6 +51,8 @@ type Prestate struct {
5051
Pre types.GenesisAlloc `json:"pre"`
5152
}
5253

54+
//go:generate go run github.com/fjl/gencodec -type ExecutionResult -field-override executionResultMarshaling -out gen_execresult.go
55+
5356
// ExecutionResult contains the execution status after running a state test, any
5457
// error that might have occurred and a dump of the final state if requested.
5558
type ExecutionResult struct {
@@ -70,6 +73,10 @@ type ExecutionResult struct {
7073
Requests [][]byte `json:"requests,omitempty"`
7174
}
7275

76+
type executionResultMarshaling struct {
77+
Requests []hexutil.Bytes `json:"requests,omitempty"`
78+
}
79+
7380
type ommer struct {
7481
Delta uint64 `json:"delta"`
7582
Address common.Address `json:"address"`
@@ -354,6 +361,28 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
354361
amount := new(big.Int).Mul(new(big.Int).SetUint64(w.Amount), big.NewInt(params.GWei))
355362
statedb.AddBalance(w.Address, uint256.MustFromBig(amount), tracing.BalanceIncreaseWithdrawal)
356363
}
364+
365+
// Gather the execution-layer triggered requests.
366+
var requests [][]byte
367+
if chainConfig.IsPrague(vmContext.BlockNumber, vmContext.Time) {
368+
// EIP-6110 deposits
369+
var allLogs []*types.Log
370+
for _, receipt := range receipts {
371+
allLogs = append(allLogs, receipt.Logs...)
372+
}
373+
depositRequests, err := core.ParseDepositLogs(allLogs, chainConfig)
374+
if err != nil {
375+
return nil, nil, nil, NewError(ErrorEVM, fmt.Errorf("could not parse requests logs: %v", err))
376+
}
377+
requests = append(requests, depositRequests)
378+
// create EVM for system calls
379+
vmenv := vm.NewEVM(vmContext, vm.TxContext{}, statedb, chainConfig, vm.Config{})
380+
// EIP-7002 withdrawals
381+
requests = append(requests, core.ProcessWithdrawalQueue(vmenv, statedb))
382+
// EIP-7251 consolidations
383+
requests = append(requests, core.ProcessConsolidationQueue(vmenv, statedb))
384+
}
385+
357386
// Commit block
358387
root, err := statedb.Commit(vmContext.BlockNumber.Uint64(), chainConfig.IsEIP158(vmContext.BlockNumber))
359388
if err != nil {
@@ -379,32 +408,14 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
379408
execRs.CurrentExcessBlobGas = (*math.HexOrDecimal64)(&excessBlobGas)
380409
execRs.CurrentBlobGasUsed = (*math.HexOrDecimal64)(&blobGasUsed)
381410
}
382-
383-
var requests [][]byte
384-
if chainConfig.IsPrague(vmContext.BlockNumber, vmContext.Time) {
385-
// EIP-6110 deposits
386-
var allLogs []*types.Log
387-
for _, receipt := range receipts {
388-
allLogs = append(allLogs, receipt.Logs...)
389-
}
390-
depositRequests, err := core.ParseDepositLogs(allLogs, chainConfig)
391-
if err != nil {
392-
return nil, nil, nil, NewError(ErrorEVM, fmt.Errorf("could not parse requests logs: %v", err))
393-
}
394-
requests = append(requests, depositRequests)
395-
// create EVM for system calls
396-
vmenv := vm.NewEVM(vmContext, vm.TxContext{}, statedb, chainConfig, vm.Config{})
397-
// EIP-7002 withdrawals
398-
withdrawalRequests := core.ProcessWithdrawalQueue(vmenv, statedb)
399-
requests = append(requests, withdrawalRequests)
400-
// EIP-7251 consolidations
401-
consolidationRequests := core.ProcessConsolidationQueue(vmenv, statedb)
402-
requests = append(requests, consolidationRequests)
403-
}
404411
if requests != nil {
405412
// Set requestsHash on block.
406413
h := types.CalcRequestsHash(requests)
407414
execRs.RequestsHash = &h
415+
for i := range requests {
416+
// remove prefix
417+
requests[i] = requests[i][1:]
418+
}
408419
execRs.Requests = requests
409420
}
410421

cmd/evm/internal/t8ntool/gen_execresult.go

Lines changed: 134 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)