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 )