nethermind icon indicating copy to clipboard operation
nethermind copied to clipboard

eth_simulateV1 fails when simulating more than 1 tx

Open mralj opened this issue 9 months ago • 2 comments

Description

I'm unsure if I'm doing anything wrong here, but if I try to call eth_simulateV1 with more than one transaction AND validation:true, it fails.

Steps to Reproduce

mainnet NMC

This fails:

curl http://localhost:8545/ \         
    -X POST \         
    -H "Content-Type: application/json" \        
    --data  '{
  "jsonrpc": "2.0",
  "method": "eth_simulateV1",
  "params": [
    {
      "blockStateCalls": [
        {
          "stateOverrides": {
            "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045": {
              "balance": "0x4a817c420"
            }
          },
          "calls": [
            {
              "from": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
              "to": "0x014d023e954bAae7F21E56ed8a5d81b12902684D",
              "maxFeePerGas": "0xf",
              "value": "0x1"
            },
            {
              "from": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
              "to": "0x014d023e954bAae7F21E56ed8a5d81b12902684D",
              "maxFeePerGas": "0xf",
              "value": "0x1"
            }
          ]
        }
      ],
      "validation": true,
      "traceTransfers": true
    },
    "latest"
  ],
  "id": 1
}'

With error: {"jsonrpc":"2.0","error":{"code":-38014,"message":"invalid transaction index: 0 at block number: 22124266, Reason: Transaction cost (17235585614296141) is higher than sender balance (19999999008)","data":[]},"id":1}

Which is OK, because balance is not enough to cover the tx. However, if I set the balance to a much higher value (e.g., 100ETH), I get this error:

{"jsonrpc":"2.0","error":{"code":-32602,"message":"Nethermind.Blockchain.InvalidBlockException: Transaction 0x130fac2ced0a43256bcd1141eb4889f6d848d963f189dc1d7c58fac76b35a928 at index 1 failed with error Block gas limit exceeded\n   at Nethermind.Consensus.Processing.BlockProcessor.BlockValidationTransactionsExecutor.ProcessTransaction(BlockExecutionContext& blkCtx, Transaction currentTx, Int32 index, BlockReceiptsTracer receiptsTracer, ProcessingOptions processingOptions) in /root/nethermind/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.BlockValidationTransactionsExecutor.cs:line 52\n   at Nethermind.Facade.Simulate.SimulateBlockValidationTransactionsExecutor.ProcessTransaction(BlockExecutionContext& blkCtx, Transaction currentTx, Int32 index, BlockReceiptsTracer receiptsTracer, ProcessingOptions processingOptions) in /root/nethermind/src/Nethermind/Nethermind.Facade/Simulate/SimulateReadOnlyBlocksProcessingEnv.cs:line 42\n   at Nethermind.Consensus.Processing.BlockProcessor.BlockValidationTransactionsExecutor.ProcessTransactions(Block block, ProcessingOptions processingOptions, BlockReceiptsTracer receiptsTracer, IReleaseSpec spec) in /root/nethermind/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.BlockValidationTransactionsExecutor.cs:line 42\n   at Nethermind.Consensus.Processing.BlockProcessor.ProcessBlock(Block block, IBlockTracer blockTracer, ProcessingOptions options) in /root/nethermind/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs:line 319\n   at Nethermind.Consensus.Processing.BlockProcessor.ProcessOne(Block suggestedBlock, ProcessingOptions options, IBlockTracer blockTracer) in /root/nethermind/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs:line 282\n   at Nethermind.Consensus.Processing.BlockProcessor.Process(Hash256 newBranchStateRoot, IReadOnlyList`1 suggestedBlocks, ProcessingOptions options, IBlockTracer blockTracer) in /root/nethermind/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs:line 148\n   at Nethermind.Facade.Simulate.SimulateBridgeHelper.TrySimulate[TTrace](BlockHeader parent, SimulatePayload`1 payload, IBlockTracer`1 tracer, SimulateReadOnlyBlocksProcessingEnv env, List`1 output, CancellationToken cancellationToken, String& error) in /root/nethermind/src/Nethermind/Nethermind.Facade/Simulate/SimulateBridgeHelper.cs:line 134\n   at Nethermind.Facade.Simulate.SimulateBridgeHelper.TrySimulate[TTrace](BlockHeader parent, SimulatePayload`1 payload, IBlockTracer`1 tracer, SimulateReadOnlyBlocksProcessingEnv env, CancellationToken cancellationToken) in /root/nethermind/src/Nethermind/Nethermind.Facade/Simulate/SimulateBridgeHelper.cs:line 76","data":[]},"id":1}

The main error being: at index 1 failed with error Block gas limit exceeded. If I send just one TX, it will work. Tested on mainnet NMC, built from the latest master (as of opening the issue)

op-nmc

This fails on op-nmc

 curl node.dev/\
                -X POST \
                -H "Content-Type: application/json" \
                --data  '{
    "jsonrpc": "2.0",
    "method": "eth_simulateV1",
    "params": [
      {
        "blockStateCalls": [
          {
            "stateOverrides": {
              "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045": {
                "balance": "0x56BC75E2D63100000"
              }
            },
            "calls": [
              {
                "from": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
                "to": "0x014d023e954bAae7F21E56ed8a5d81b12902684D",
                "maxFeePerGas": "0x258",
                "value": "0x1"
              },
              {
                "from": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
                "to": "0x014d023e954bAae7F21E56ed8a5d81b12902684D",
                "maxFeePerGas": "0x258",
                "value": "0x1"
              }
            ]
          }
        ],
        "validation": true,
        "traceTransfers": true
      },
      "latest"
    ],
    "id": 1
  }'

Return value

{"jsonrpc":"2.0","error":{"code":-32602,"message":"Nethermind.Blockchain.InvalidBlockException: Transaction 0x7f420dd1f2959785f626107ca446a493df0b1d41e5d2f68d32e8c31de0c0bcbf at index 1 failed with error Block gas limit exceeded\n   at Nethermind.Facade.Simulate.SimulateBlockValidationTransactionsExecutor.ProcessTransaction(BlockExecutionContext& blkCtx, Transaction currentTx, Int32 index, BlockReceiptsTracer receiptsTracer, ProcessingOptions processingOptions) in /src/Nethermind/Nethermind.Facade/Simulate/SimulateReadOnlyBlocksProcessingEnv.cs:line 42\n   at Nethermind.Consensus.Processing.BlockProcessor.BlockValidationTransactionsExecutor.ProcessTransactions(Block block, ProcessingOptions processingOptions, BlockReceiptsTracer receiptsTracer, IReleaseSpec spec) in /src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.BlockValidationTransactionsExecutor.cs:line 42\n   at Nethermind.Consensus.Processing.BlockProcessor.ProcessBlock(Block block, IBlockTracer blockTracer, ProcessingOptions options) in /src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs:line 319\n   at Nethermind.Consensus.Processing.BlockProcessor.ProcessOne(Block suggestedBlock, ProcessingOptions options, IBlockTracer blockTracer) in /src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs:line 286\n   at Nethermind.Consensus.Processing.BlockProcessor.Process(Hash256 newBranchStateRoot, List`1 suggestedBlocks, ProcessingOptions options, IBlockTracer blockTracer) in /src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs:line 148\n   at Nethermind.Facade.Simulate.SimulateBridgeHelper.TrySimulate(BlockHeader parent, SimulatePayload`1 payload, SimulateBlockTracer simulateOutputTracer, IBlockTracer tracer, SimulateReadOnlyBlocksProcessingEnv env, String& error) in /src/Nethermind/Nethermind.Facade/Simulate/SimulateBridgeHelper.cs:line 76\n   at Nethermind.Facade.Simulate.SimulateBridgeHelper.TrySimulate(BlockHeader parent, SimulatePayload`1 payload, SimulateBlockTracer simulateOutputTracer, IBlockTracer tracer, String& error) in /src/Nethermind/Nethermind.Facade/Simulate/SimulateBridgeHelper.cs:line 65\n   at Nethermind.Facade.BlockchainBridge.Simulate(BlockHeader header, SimulatePayload`1 payload, CancellationToken cancellationToken) in /src/Nethermind/Nethermind.Facade/BlockchainBridge.cs:line 176","data":[]},"id":1}⏎

The main error being: at index 1 failed with error Block gas limit exceeded Tested on the node running this branch

Expected value

{"jsonrpc":"2.0","id":1,"result":[{"baseFeePerGas":"0x15b","blobGasUsed":"0x0","calls":[{"returnData":"0x","logs":[{"address":"0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa96045","0x000000000000000000000000014d023e954baae7f21e56ed8a5d81b12902684d"],"data":"0x0000000000000000000000000000000000000000000000000000000000000001","blockNumber":"0x167a8fb","transactionHash":"0x73dfcd74d92aaac213b5b25fb27328afb3259c97d297e7c4c044ceaa601c195c","transactionIndex":"0x0","blockHash":"0x724a86e49ec16e436035d9f3d0a086243851ac1d88ccbac8f48e88a6e3d20d55","logIndex":"0x0","removed":false}],"gasUsed":"0x5208","status":"0x1"},{"returnData":"0x","logs":[{"address":"0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa96045","0x000000000000000000000000014d023e954baae7f21e56ed8a5d81b12902684d"],"data":"0x0000000000000000000000000000000000000000000000000000000000000001","blockNumber":"0x167a8fb","transactionHash":"0xd8f77a4649504769f56f3d93e091ba22a40e3b2258f2f8e5232b9383c11e2abc","transactionIndex":"0x1","blockHash":"0x724a86e49ec16e436035d9f3d0a086243851ac1d88ccbac8f48e88a6e3d20d55","logIndex":"0x1","removed":false}],"gasUsed":"0x5208","status":"0x1"}],"difficulty":"0x0","excessBlobGas":"0x0","extraData":"0x","gasLimit":"0x3938700","gasUsed":"0xa410","hash":"0x724a86e49ec16e436035d9f3d0a086243851ac1d88ccbac8f48e88a6e3d20d55","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x4200000000000000000000000000000000000011","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000","number":"0x167a8fb","parentBeaconBlockRoot":"0x0000000000000000000000000000000000000000000000000000000000000000","parentHash":"0x5f624910f3a2bbb51e56a389be322f91eee428c539886585f4c54a43d063cc77","receiptsRoot":"0x75308898d571eafb5cd8cde8278bf5b3d13c5f6ec074926de3bb895b519264e1","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x2a4","stateRoot":"0x6f3a9cf2cb95482398946a5d8a8cba76707615d4ed48aac532dc1f9830d03856","timestamp":"0x67e2b0e0","transactions":["0x73dfcd74d92aaac213b5b25fb27328afb3259c97d297e7c4c044ceaa601c195c","0xd8f77a4649504769f56f3d93e091ba22a40e3b2258f2f8e5232b9383c11e2abc"],"transactionsRoot":"0x8a314b74fcc327e8a12b07f1c7431b91052a2bf7a1cbf8de8d727d41bb673918","uncles":[],"withdrawals":[],"withdrawalsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"}]}

This is result I get calling QuikNode running op-geth: Geth/v1.101503.1-stable-fbc739c3/linux-amd64/go1.24.1

The errors I get on mainnet-NMC and op-NMC are the same, and the same call works on Geth, which leads me to conclude that we have issue in our implementation.

mralj avatar Mar 25 '25 13:03 mralj

@rjnrohit the calls above will work if I add gas field to each of the calls, example:

curl http://localhost:8545/ \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{
    "jsonrpc": "2.0",
    "method": "eth_simulateV1",
    "params": [
      {
        "blockStateCalls": [
          {
            "stateOverrides": {
              "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045": {
                "balance": "0x56BC75E2D63100000"
              }
            },
            "calls": [
              {
                "from": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
                "to": "0x014d023e954bAae7F21E56ed8a5d81b12902684D",
                "value": "0x1",
                "gas": "0x55f0"
              },
              {
                "from": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
                "to": "0xc100000000000000000000000000000000000000",
                "value": "0x1",
                "gas": "0x55f0"
              }
            ]
          }
        ],
        "validation": true,
        "traceTransfers": true
      },
      "latest"
    ],
    "id": 1
}'

mralj avatar Mar 26 '25 11:03 mralj

Btw @rjnrohit only gas field was necessary, I didn't have to add any other fields (like gas price, or nonce etc). Per spec this is how gasLimit for each transaction should be calculated (if it's missing):

(blockGasLimit - SumOfGasLimitOfTransactionsWithDefinedGasLimit) / NumberOfTransactionsWithoutKnownGasLimit

This means, if there are no transacitons with defined gas limit, then for each tx we set gas as blockGasLimit/NumberOfTransactions

mralj avatar Mar 26 '25 11:03 mralj