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

all: improve EstimateGas API #632

Open
wants to merge 2 commits into
base: dev-upgrade
Choose a base branch
from

Conversation

JukLee0ira
Copy link

@JukLee0ira JukLee0ira commented Sep 3, 2024

Proposed changes

PR 20830 separate consensus errors and EVM Internal errors.Since EVM errors have already been separated in #200 , this PR will embed EVM errors into the executionResult structure, following the upstream code.

Test

Gas Consumption Comparison

Before this PR is merged:

  • RPC: http://127.0.0.1:8545 – The changes from this PR are applied.
  • RPC: https://rpc.apothem.network/ – The changes from this PR are not applied.

Request:

RPC="https://rpc.apothem.network"
curl -s -X POST -H "Content-Type: application/json" ${RPC} -d '{
  "jsonrpc": "2.0",
  "id": 0,
  "method": "eth_estimateGas",
  "params": [
    {
      "from": "0xf366aa107A5Ed1d54AFDEA5506B3059Ce402Da28",
      "to": "0x53381ac6FE72C3cf469891F46248dc3dc02E8EA3",
      "data": "0xabcd012345"
    },
    "latest"
  ]}' | jq

Response:

{"jsonrpc":"2.0","id":0,"result":"0x535c"}

Request:

RPC="http://127.0.0.1:8545"
curl -s -X POST -H "Content-Type: application/json" ${RPC} -d '{
  "jsonrpc": "2.0",
  "id": 0,
  "method": "eth_estimateGas",
  "params": [
    {
      "from": "0xf366aa107A5Ed1d54AFDEA5506B3059Ce402Da28",
      "to": "0x53381ac6FE72C3cf469891F46248dc3dc02E8EA3",
      "data": "0xabcd012345"
    },
    "latest"
  ]}' | jq

Response:

{"jsonrpc":"2.0","id":0,"result":"0x535c"}

Revert Logic Test

The following test contract was authored by @gzliudan ,originates from #200.

// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;

contract Test {
    uint256 private val;

    constructor() public {
        val = 1;
    }

    function getVal() public view returns (uint256) {
        return val;
    }

    function testRevert(bool willRevert) public view returns (uint256) {
        if (willRevert) {
            revert("I reverted");
        }

        return block.number;
    }

    function setVal(uint256 newValue) external {
        require(newValue < 10, "newValue >= 10");

        val = newValue;
    }
}

Request

RPC="http://127.0.0.1:8547"
curl -s -X POST -H "Content-Type: application/json" ${RPC} -d '{
  "jsonrpc": "2.0",
  "id": 0,
  "method": "eth_estimateGas",
  "params": [
    {
      "to": "0xe8CECD75769Eda90bfFb9f0E4EFD086c543EF026",
      "data": "0x29d0bec00000000000000000000000000000000000000000000000000000000000000001",
      "value": "0x0"
    },
	"latest"
  ]}' | jq

Response

{
  "jsonrpc": "2.0",
  "id": 0,
  "error": {
    "code": -32000,
    "message": "always failing transaction (execution reverted) (I reverted)"
  }
}

Request

RPC="http://127.0.0.1:8547"
curl -s -X POST -H "Content-Type: application/json" ${RPC} -d '{
  "jsonrpc": "2.0",
  "id": 0,
  "method": "eth_estimateGas",
  "params": [
    {
      "to": "0xe8CECD75769Eda90bfFb9f0E4EFD086c543EF026",
      "data": "0x3d4197f0000000000000000000000000000000000000000000000000000000000000000b",
      "value": "0x0"
    },
	"latest"
  ]}' | jq

Response

{
  "jsonrpc": "2.0",
  "id": 0,
  "error": {
    "code": -32000,
    "message": "always failing transaction (execution reverted) (newValue >= 10)"
  }
}

Types of changes

What types of changes does your code introduce to XDC network?
Put an in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)
  • Regular KTLO or any of the maintaince work. e.g code style
  • CICD Improvement
  • N/A

Impacted Components

Which part of the codebase this PR will touch base on,

Put an in the boxes that apply

  • Consensus
  • Account
  • Network
  • Geth
  • Smart Contract
  • External components
  • Not sure (Please specify below)

Checklist

Put an in the boxes once you have confirmed below actions (or provide reasons on not doing so) that

  • This PR has sufficient test coverage (unit/integration test) OR I have provided reason in the PR description for not having test coverage
  • Provide an end-to-end test plan in the PR description on how to manually test it on the devnet/testnet.
  • Tested the backwards compatibility.
  • Tested with XDC nodes running this version co-exist with those running the previous version.
  • Relevant documentation has been updated as part of this PR
  • N/A

@gzliudan gzliudan changed the title all: improve EstimateGas API WIP: all: improve EstimateGas API Sep 5, 2024
@gzliudan gzliudan changed the title WIP: all: improve EstimateGas API [WIP] all: improve EstimateGas API Sep 9, 2024
@JukLee0ira JukLee0ira force-pushed the evm-execution-result branch 10 times, most recently from 4be9366 to 6a89145 Compare September 13, 2024 03:10
@JukLee0ira JukLee0ira marked this pull request as ready for review September 13, 2024 03:10
@JukLee0ira JukLee0ira changed the title [WIP] all: improve EstimateGas API all: improve EstimateGas API Sep 18, 2024
core/vm/logger.go Outdated Show resolved Hide resolved
core/vm/instructions.go Outdated Show resolved Hide resolved
core/error.go Outdated Show resolved Hide resolved
@JukLee0ira JukLee0ira force-pushed the evm-execution-result branch 2 times, most recently from 5a43f02 to 007b15b Compare September 25, 2024 06:26
@JukLee0ira
Copy link
Author

Revert Logic Test have been added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants