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 1 commit 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

test contract is following:

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

contract TestRevert {

    // Mapping to store balances of addresses
    mapping(address => uint256) private balances;
    
    uint256 private val;

    constructor() public {
        val = 1;
    }

    // Transfer function with revert logic
    function transfer(address recipient, uint256 amount) external {
        require(amount > 10, "amount =< 10");

        // Regular transfer logic
        balances[msg.sender] -= amount;
        balances[recipient] += amount;
    }
    
    // Function to get the value stored in `val`
    function getVal() public view returns (uint256) {
        return val;
    }

}

Gas Consumption Comparison

eth_estimateGas
The curl command I used:

  • address with balance : 0x873C36f9Fd02e0C57a393aFE80D14f244fE04378
  • address without balance: 0xf366aa107A5Ed1d54AFDEA5506B3059Ce402Da28
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": "0x7808D875ae4d437c600147e4855Bc239CD984De1",
      "data": "0xa9059cbb000000000000000000000000f366aa107a5ed1d54afdea5506b3059ce402da28000000000000000000000000000000000000000000000000000000000000001e"
    },
    "latest"
  ]}' 

and their response:

Balance PR are applied Response
Yes Yes {"jsonrpc":"2.0","id":2,"result":"0x83f5"}
Yes No {"jsonrpc":"2.0","id":2,"result":"0x83f5"}
No Yes {"jsonrpc":"2.0","id":2,"result":"0xbe8d"}
No No {"jsonrpc":"2.0","id":2,"result":"0xbe8d"}

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": "0x7808D875ae4d437c600147e4855Bc239CD984De1",
      "data": "0xe1cb0e52"
    },
    "latest"
  ]}' | jq 

and their response:

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

Revert Logic Test

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": [
    {
      "to": "0x7808D875ae4d437c600147e4855Bc239CD984De1",
      "data": "0xa9059cbb000000000000000000000000f366aa107a5ed1d54afdea5506b3059ce402da280000000000000000000000000000000000000000000000000000000000000001",
      "value": "0x0"
    },
	"latest"
  ]}' | jq
Response
{
  "jsonrpc": "2.0",
  "id": 0,
  "error": {
    "code": -32000,
    "message": "always failing transaction (execution reverted) (amount =< 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

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 6 times, most recently from 97667b0 to c54db40 Compare November 25, 2024 09:51
@gzliudan
Copy link
Collaborator

missing file accounts/abi/bind/backends/simulated_test.go

core/state_transition.go Outdated Show resolved Hide resolved
@JukLee0ira JukLee0ira force-pushed the evm-execution-result branch 5 times, most recently from e39a800 to 2d5b73f Compare November 27, 2024 11:28
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