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

Merged
merged 1 commit into from
Dec 21, 2024

Conversation

JukLee0ira
Copy link

@JukLee0ira JukLee0ira commented Sep 3, 2024

Proposed changes

this PR separate consensus errors and EVM Internal errors

Test

test contract is following:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

contract TestRevert {
    function revertLogic(address payable recipient)
        external
        payable
        returns (uint256)
    {
        recipient.transfer(msg.value);
        require(msg.value > 10, "Transfer amount must be greater than ten");

        return msg.value;
    }

    // Function to allow contract to send ETH to another account
    function sendXDC(address payable recipient, uint256 amount) external returns (uint256){
        // Transfer the specified amount to the recipient
        recipient.transfer(amount* 1 ether);

        return amount;
        
    }

    receive() external payable {
    }

    fallback() external payable {
    }
}

Gas Consumption Comparison

eth_estimateGas
The curl command I used:

  • address with balance : 0x873C36f9Fd02e0C57a393aFE80D14f244fE04378
  • address without balance: 0xFb51679CeF4CF53152B531e6E437C727aDfF533e
RPC="http://127.0.0.1:8545"
curl -s -X POST -H "Content-Type: application/json" ${RPC} -d '{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "eth_estimateGas",
  "params": [
    {
      "from": <wallet address>,  
      "to": "0xEb14F05e78bDB995a55aAc7D2b2D26D2215F22Fd",
      "value":"0xc8",
      "data": "0x8a73d3ab000000000000000000000000eb14f05e78bdb995a55aac7d2b2d26d2215f22fd"
    },
    "latest"
  ]}' 

and their response:

Balance PR are applied Response
Yes Yes {"jsonrpc":"2.0","id":1002,"result":"0x8066"}
Yes No {"jsonrpc":"2.0","id":1002,"result":"0x8066"}
No Yes {"jsonrpc":"2.0","id":1002,"result":"0x8066"}
No No {"jsonrpc":"2.0","id":1002,"result":"0x8066"}

eth_call
The curl command I used:

RPC="http://127.0.0.1:8545"
curl -s -X POST -H "Content-Type: application/json" ${RPC} -d '{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "eth_call",
  "params": [
    {
      "from": "0x873C36f9Fd02e0C57a393aFE80D14f244fE04378",  
      "to": "0xEb14F05e78bDB995a55aAc7D2b2D26D2215F22Fd",
      "data": "0x1afd35fe000000000000000000000000885c1e1b9c24758b56b6a36c13a94efdb4e4e3b10000000000000000000000000000000000000000000000000000000000000001"
    },
    "latest"
  ]}'

and their response:

PR are applied Response
Yes {"jsonrpc":"2.0","id":1002,"result":"0x0000000000000000000000000000000000000000000000000000000000000001"}
No {"jsonrpc":"2.0","id":1002,"result":"0x0000000000000000000000000000000000000000000000000000000000000001"}

Other cases

Request(The balance is 100, and an internal transaction attempts to transfer 200 to the address0x873C36f9Fd02e0C57a393aFE80D14f244fE04378
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_call",
  "params": [
    {            
      "from": "0x873C36f9Fd02e0C57a393aFE80D14f244fE04378",
      "to": "0xEb14F05e78bDB995a55aAc7D2b2D26D2215F22Fd",
      "data": "0x1afd35fe000000000000000000000000885c1e1b9c24758b56b6a36c13a94efdb4e4e3b100000000000000000000000000000000000000000000000000000000000000c8",
    },
  ]}' | jq
Response
{
    "jsonrpc": "2.0",
    "id": 1002,
    "error": {
        "code": -32000,
        "message": "execution reverted"
    }
}
Request(gas exceeds the gasLimit)
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_call",
  "params": [
    {            
      "from": "0x873C36f9Fd02e0C57a393aFE80D14f244fE04378",
      "to": "0xEb14F05e78bDB995a55aAc7D2b2D26D2215F22Fd",
      "gas": "0x10",
      "data": "0x1afd35fe000000000000000000000000885c1e1b9c24758b56b6a36c13a94efdb4e4e3b10000000000000000000000000000000000000000000000000000000000000008",
    },
  ]}' | jq
Response
{
    "jsonrpc": "2.0",
    "id": 1002,
    "error": {
        "code": -32000,
        "message": "err: intrinsic gas too low: have 16, want 22680 (supplied gas 16)"
    }
}
Request(revert caused by business logic)
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": "0x873C36f9Fd02e0C57a393aFE80D14f244fE04378",
		"to": "0xEb14F05e78bDB995a55aAc7D2b2D26D2215F22Fd",
		"value":"0x3",
		"data": "0x8a73d3ab000000000000000000000000eb14f05e78bdb995a55aac7d2b2d26d2215f22fd"
        }
    ]}' | jq
Response
{
    "jsonrpc": "2.0",
    "id": 1002,
    "error": {
        "code": -32000,
        "message": "always failing transaction (execution reverted) (Transfer amount must be greater than ten)"
    }
}

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

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

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 3 times, most recently from 007b15b to 54703c2 Compare September 25, 2024 06:44
@JukLee0ira
Copy link
Author

Revert Logic Test have been added.

@JukLee0ira JukLee0ira force-pushed the evm-execution-result branch 3 times, most recently from 0439ca1 to ac07d4c Compare November 14, 2024 11:41
@JukLee0ira JukLee0ira force-pushed the evm-execution-result branch 5 times, most recently from 2d5b73f to 5c28d8b Compare November 28, 2024 07:32
@JukLee0ira JukLee0ira force-pushed the evm-execution-result branch 6 times, most recently from f00f548 to 3f8ee3f Compare December 16, 2024 07:59
@JukLee0ira JukLee0ira force-pushed the evm-execution-result branch 5 times, most recently from b5d84b2 to a896d47 Compare December 16, 2024 11:00
@gzliudan
Copy link
Collaborator

The line recipient.transfer(msg.value); in your contract is never reverted. Please modify your test contract.

@JukLee0ira JukLee0ira force-pushed the evm-execution-result branch 2 times, most recently from f899554 to 2057aed Compare December 20, 2024 10:51
@gzliudan gzliudan merged commit 7491a7b into XinFinOrg:dev-upgrade Dec 21, 2024
17 checks passed
@JukLee0ira JukLee0ira mentioned this pull request Dec 23, 2024
19 tasks
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.

3 participants