XinFinOrg / XDPoSChain

Customer centric, Hybrid & Interoperable XinFin Network
https://www.xinfin.org
GNU Lesser General Public License v3.0
50 stars 59 forks source link

extend eth_call and estimateGas api with state override #529

Closed wgr523 closed 2 months ago

wgr523 commented 2 months ago

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

Impacted Components

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

Put an in the boxes that apply

Checklist

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

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