From ceabc39304ec298d891d3cde51b8cfddc6842197 Mon Sep 17 00:00:00 2001 From: Sina M <1591639+s1na@users.noreply.github.com> Date: Mon, 30 Mar 2026 10:01:12 +0200 Subject: [PATCH] internal/ethapi: limit number of calls to eth_simulateV1 (#34616) Later on we can consider making these limits configurable if the use-case arose. --- internal/ethapi/api.go | 10 ++++++++++ internal/ethapi/simulate.go | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index bb0dd042ab..a62328e201 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -841,6 +841,16 @@ func (api *BlockChainAPI) SimulateV1(ctx context.Context, opts simOpts, blockNrO } else if len(opts.BlockStateCalls) > maxSimulateBlocks { return nil, &clientLimitExceededError{message: "too many blocks"} } + var totalCalls int + for _, block := range opts.BlockStateCalls { + if len(block.Calls) > maxSimulateCallsPerBlock { + return nil, &clientLimitExceededError{message: fmt.Sprintf("too many calls in block: %d > %d", len(block.Calls), maxSimulateCallsPerBlock)} + } + totalCalls += len(block.Calls) + if totalCalls > maxSimulateTotalCalls { + return nil, &clientLimitExceededError{message: fmt.Sprintf("too many calls: %d > %d", totalCalls, maxSimulateTotalCalls)} + } + } if blockNrOrHash == nil { n := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber) blockNrOrHash = &n diff --git a/internal/ethapi/simulate.go b/internal/ethapi/simulate.go index aa7609ff93..eacb296132 100644 --- a/internal/ethapi/simulate.go +++ b/internal/ethapi/simulate.go @@ -44,6 +44,14 @@ const ( // in a single request. maxSimulateBlocks = 256 + // maxSimulateCallsPerBlock is the maximum number of calls allowed in a + // single simulated block. + maxSimulateCallsPerBlock = 5000 + + // maxSimulateTotalCalls is the maximum total number of calls allowed + // across all simulated blocks in a single request. + maxSimulateTotalCalls = 10000 + // timestampIncrement is the default increment between block timestamps. timestampIncrement = 12 )