internal/ethapi: handle prague system calls in eth_simulate (#31176)

eth_simulate was not processing prague system calls for history contract and EL
requests resulting in inaccurate stateRoot and requestsRoot fields in the block.
This commit is contained in:
nethoxa 2025-02-20 14:30:55 +01:00 committed by GitHub
parent c8781be762
commit b1f88ef9bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 22 additions and 0 deletions

View File

@ -194,6 +194,10 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
if precompiles != nil {
evm.SetPrecompiles(precompiles)
}
if sim.chainConfig.IsPrague(header.Number, header.Time) || sim.chainConfig.IsVerkle(header.Number, header.Time) {
core.ProcessParentBlockHash(header.ParentHash, evm)
}
var allLogs []*types.Log
for i, call := range block.Calls {
if err := ctx.Err(); err != nil {
return nil, nil, err
@ -234,9 +238,23 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
}
} else {
callRes.Status = hexutil.Uint64(types.ReceiptStatusSuccessful)
allLogs = append(allLogs, callRes.Logs...)
}
callResults[i] = callRes
}
var requests [][]byte
// Process EIP-7685 requests
if sim.chainConfig.IsPrague(header.Number, header.Time) {
requests = [][]byte{}
// EIP-6110
if err := core.ParseDepositLogs(&requests, allLogs, sim.chainConfig); err != nil {
return nil, nil, err
}
// EIP-7002
core.ProcessWithdrawalQueue(&requests, evm)
// EIP-7251
core.ProcessConsolidationQueue(&requests, evm)
}
header.Root = sim.state.IntermediateRoot(true)
header.GasUsed = gasUsed
if sim.chainConfig.IsCancun(header.Number, header.Time) {
@ -246,6 +264,10 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
if sim.chainConfig.IsShanghai(header.Number, header.Time) {
withdrawals = make([]*types.Withdrawal, 0)
}
if requests != nil {
reqHash := types.CalcRequestsHash(requests)
header.RequestsHash = &reqHash
}
b := types.NewBlock(header, &types.Body{Transactions: txes, Withdrawals: withdrawals}, receipts, trie.NewStackTrie(nil))
repairLogs(callResults, b.Hash())
return b, callResults, nil