nethermind icon indicating copy to clipboard operation
nethermind copied to clipboard

Fix eth_call error format to match Geth compatibility

Open Copilot opened this issue 8 months ago • 1 comments

Summary

This PR fixes discrepancies between Nethermind and Geth for eth_call error responses, specifically for execution reverted errors. The issue was that Nethermind returned different error codes, messages, and data formats compared to Geth.

Problem

When eth_call encounters a revert, Geth and Nethermind returned different responses:

Geth response:

{
  "error": {
    "code": 3,
    "data": "0xdf2d9b42",
    "message": "execution reverted"
  }
}

Nethermind response (before fix):

{
  "error": {
    "code": -32015,
    "data": "err: 0xdf2d9b42 (supplied gas 36000000)",
    "message": "VM execution error."
  }
}

Solution

The fix introduces Geth-compatible error handling for revert cases while preserving existing behavior for other execution errors:

  1. Added new error code: ErrorCodes.ExecutionReverted = 3 for Geth compatibility
  2. Enhanced error detection: Modified CallTxExecutor to detect revert errors by checking if the error string starts with "revert"
  3. Updated error format: For reverts, return raw revert data instead of wrapped format with gas information
  4. Maintained backward compatibility: Non-revert errors still use the existing format

Key Changes

  • ErrorCodes.cs: Added ExecutionReverted = 3 constant
  • EthRpcModule.TransactionExecutor.cs:
    • Added IsRevertError() method to detect revert vs other execution errors
    • Modified CallTxExecutor.ExecuteTx() to handle reverts with Geth-compatible format
  • EthRpcModuleTests.EthCall.cs: Updated existing test to expect new revert format

Flow

CallOutput.Error starts with "revert"?
├─ Yes: Return code 3, message "execution reverted", raw output data
└─ No: Return code -32015, message "VM execution error.", wrapped error data

Testing

  • Verified revert detection logic works correctly for various error scenarios
  • Updated existing test that was expecting old revert format
  • Maintains compatibility for all non-revert execution errors

The fix handles both test cases from the original issue:

  • Revert with data 0xdf2d9b42 → Returns code 3, message "execution reverted", data "0xdf2d9b42"
  • Revert with empty data → Returns code 3, message "execution reverted", data "0x"

Fixes #8813.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot avatar Jun 22 '25 21:06 Copilot

Why have you added dotnet-install.sh?

I accidentally added dotnet-install.sh in commit 87cc380 while working on the eth_call fix. This file was unrelated to the issue and shouldn't have been included. I've removed it in commit d2cdf3c.

Copilot avatar Jun 22 '25 21:06 Copilot