Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding data field for reverted calls and estimateGas #1960

Merged
merged 7 commits into from
Aug 27, 2024

Conversation

DmytroNazarenko
Copy link
Collaborator

@DmytroNazarenko DmytroNazarenko commented Aug 14, 2024

Description

This PR adds support of "data" field for reverted eth_call and eth_estimateGas. Example of the response:

{
   "error":{
      "code":3,
      "data":"0x82b42900",
      "message":"EVM revert instruction without description message"
   },
   "id":2327090862,
   "jsonrpc":"2.0"
}
  • Field data is a hex-string
  • Contains encoded output from reverted call
  • If EVM revert contains data, then response will contain error code 3. Otherwise, -32000
  • Doesn’t affect tracing

Tests

Unit tests

Added 2 unit tests: JsonRpcSuite/estimate_gas_with_error and JsonRpcSuite/call_with_error

Tracing tests

Tested on historical build by comparing outputs of Geth and skaled

Additional tests

Here is the testing procedure for e2e testing:

  1. Deploying contract:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract BasicCustomErrorContract {

    // Define custom errors
    error InsufficientBalance();
    error Unauthorized();

    address public owner;


    // Function only callable by the owner
    function ownerOnlyFunction() external {
        revert Unauthorized();
    }

    function requireCall() external {
        require(1 == 0, "Require");
    }

    function revertCall() external {
        revert("Something bad happened");
    }

    function assertCall() external {
        assert(1 == 0);
    }
}
  1. Sending eth_calls:
curl SKALED_ENDPOINT -X POST -H "Content-Type: application/json"   --data '{"id":2327090862,"jsonrpc":"2.0","method":"eth_call","params":[{"data":"0xe021c206","from":"0xa68F946090c600eDa6f139783077EE802Afeb990","to":"0x62815b8b66a91fef35d7950f83c04da6a64508c2","value":"0x0"},"latest"]}'
curl SKALED_ENDPOINT -X POST -H "Content-Type: application/json"   --data '{"id":2327090862,"jsonrpc":"2.0","method":"eth_call","params":[{"data":"0xf38fb65b","from":"0xa68F946090c600eDa6f139783077EE802Afeb990","to":"0x62815b8b66a91fef35d7950f83c04da6a64508c2","value":"0x0"},"latest"]}'
curl SKALED_ENDPOINT -X POST -H "Content-Type: application/json"   --data '{"id":2327090862,"jsonrpc":"2.0","method":"eth_call","params":[{"data":"0x068d492b","from":"0xa68F946090c600eDa6f139783077EE802Afeb990","to":"0x62815b8b66a91fef35d7950f83c04da6a64508c2","value":"0x0"},"latest"]}'
curl SKALED_ENDPOINT -X POST -H "Content-Type: application/json"   --data '{"id":2327090862,"jsonrpc":"2.0","method":"eth_call","params":[{"data":"0x4bc55aed","from":"0xa68F946090c600eDa6f139783077EE802Afeb990","to":"0x62815b8b66a91fef35d7950f83c04da6a64508c2","value":"0x0"},"latest"]}'
  1. Receiving responses:
{"error":{"code":3,"data":"0x82b42900","message":"EVM revert instruction without description message"},"id":2327090862,"jsonrpc":"2.0"}
{"error":{"code":3,"data":"0x08c379a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000016536f6d657468696e67206261642068617070656e656400000000000000000000","message":"Something bad happened"},"id":2327090862,"jsonrpc":"2.0"}
{"error":{"code":3,"data":"0x4e487b710000000000000000000000000000000000000000000000000000000000000001","message":"EVM revert instruction without description message"},"id":2327090862,"jsonrpc":"2.0"}
{"error":{"code":3,"data":"0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000075265717569726500000000000000000000000000000000000000000000000000","message":"Require"},"id":2327090862,"jsonrpc":"2.0"}

  1. Repeating p.3-4 for eth_estimateGas

Performance Impact

All changes are inside JSON RPC API modules, so performance is not affected

@DmytroNazarenko DmytroNazarenko linked an issue Aug 14, 2024 that may be closed by this pull request
Copy link
Collaborator

@kladkogex kladkogex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 We need to find the corresponding code in geth to make sure we are doing exactly doing for this field

  1. Also we need to understand how does this new field affect tracing. Where does it show in traces? To do this, one needs to do geth trace and compare

Our strategy needs to be 100% compatible with geth

@kladkogex kladkogex self-requested a review August 24, 2024 12:20
@olehnikolaiev olehnikolaiev self-requested a review August 27, 2024 12:53
@DmytroNazarenko DmytroNazarenko merged commit b982a13 into develop Aug 27, 2024
9 checks passed
@DmytroNazarenko DmytroNazarenko deleted the enhancement/add-call-data branch August 27, 2024 14:26
@github-actions github-actions bot locked and limited conversation to collaborators Aug 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Revert in Solidity is not returning data
4 participants