Skip to content

Commit b1f88ef

Browse files
authored
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.
1 parent c8781be commit b1f88ef

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

internal/ethapi/simulate.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
194194
if precompiles != nil {
195195
evm.SetPrecompiles(precompiles)
196196
}
197+
if sim.chainConfig.IsPrague(header.Number, header.Time) || sim.chainConfig.IsVerkle(header.Number, header.Time) {
198+
core.ProcessParentBlockHash(header.ParentHash, evm)
199+
}
200+
var allLogs []*types.Log
197201
for i, call := range block.Calls {
198202
if err := ctx.Err(); err != nil {
199203
return nil, nil, err
@@ -234,9 +238,23 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
234238
}
235239
} else {
236240
callRes.Status = hexutil.Uint64(types.ReceiptStatusSuccessful)
241+
allLogs = append(allLogs, callRes.Logs...)
237242
}
238243
callResults[i] = callRes
239244
}
245+
var requests [][]byte
246+
// Process EIP-7685 requests
247+
if sim.chainConfig.IsPrague(header.Number, header.Time) {
248+
requests = [][]byte{}
249+
// EIP-6110
250+
if err := core.ParseDepositLogs(&requests, allLogs, sim.chainConfig); err != nil {
251+
return nil, nil, err
252+
}
253+
// EIP-7002
254+
core.ProcessWithdrawalQueue(&requests, evm)
255+
// EIP-7251
256+
core.ProcessConsolidationQueue(&requests, evm)
257+
}
240258
header.Root = sim.state.IntermediateRoot(true)
241259
header.GasUsed = gasUsed
242260
if sim.chainConfig.IsCancun(header.Number, header.Time) {
@@ -246,6 +264,10 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
246264
if sim.chainConfig.IsShanghai(header.Number, header.Time) {
247265
withdrawals = make([]*types.Withdrawal, 0)
248266
}
267+
if requests != nil {
268+
reqHash := types.CalcRequestsHash(requests)
269+
header.RequestsHash = &reqHash
270+
}
249271
b := types.NewBlock(header, &types.Body{Transactions: txes, Withdrawals: withdrawals}, receipts, trie.NewStackTrie(nil))
250272
repairLogs(callResults, b.Hash())
251273
return b, callResults, nil

0 commit comments

Comments
 (0)