Skip to content

Conversation

@wgr523
Copy link
Collaborator

@wgr523 wgr523 commented May 1, 2024

Proposed changes

Extend eth_call and estimateGas api with state override

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

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)
  • API

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

Test plan

I already tested with a local xdc node. And we can also do the same test on devnet/testnet. The plan is as follows.

Run normal eth_call on XDCValidator smart contract's getOwnerCount()

curl http://localhost:8545 -X POST -H "Content-Type: application/json" \
   --data '{"method":"eth_call","params":[{"to":"0x0000000000000000000000000000000000000088","data":"0xef18374a"}, "latest"],"id":1,"jsonrpc":"2.0"}'

Expected result : the number of owner

Test override code:

this fake code should return 0xff: 60ff60005360016000f3, no matter calldata. so you can run

curl http://localhost:8545 -X POST -H "Content-Type: application/json" \
   --data '{"method":"eth_call","params":[{"to":"0x0000000000000000000000000000000000000088","data":"0xef18374a"}, "latest", {"0x0000000000000000000000000000000000000088":{"code":"0x60ff60005360016000f3"}}],"id":1,"jsonrpc":"2.0"}'

Expected result : 0xff

Test override state:

ownerCount is stored at key=000000000000000000000000000000000000000000000000000000000000000a. So we override it with 0x33 (or any random number) and call getOwnerCount().

Use state inside parameter.

curl http://localhost:8545 -X POST -H "Content-Type: application/json" \
   --data '{"method":"eth_call","params":[{"to":"0x0000000000000000000000000000000000000088","data":"0xef18374a"}, "latest", {"0x0000000000000000000000000000000000000088":{"state":{"0x000000000000000000000000000000000000000000000000000000000000000a": "0x0000000000000000000000000000000000000000000000000000000000000033"}}}],"id":1,"jsonrpc":"2.0"}'

or
Use stateDiff inside parameter.

curl http://localhost:8545 -X POST -H "Content-Type: application/json" \
   --data '{"method":"eth_call","params":[{"to":"0x0000000000000000000000000000000000000088","data":"0xef18374a"}, "latest", {"0x0000000000000000000000000000000000000088":{"stateDiff":{"0x000000000000000000000000000000000000000000000000000000000000000a": "0x0000000000000000000000000000000000000000000000000000000000000033"}}}],"id":1,"jsonrpc":"2.0"}'

Expected result : 0x0000000000000000000000000000000000000000000000000000000000000033

@wgr523 wgr523 merged commit bfa3bb4 into dev-upgrade May 7, 2024
@wgr523 wgr523 deleted the extend-eth_call_2 branch May 7, 2024 09:57
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.

4 participants