Closed wgr523 closed 2 months ago
Extend eth_call and estimateGas api with state override
What types of changes does your code introduce to XDC network? Put an ✅ in the boxes that apply
✅
Which part of the codebase this PR will touch base on,
Put an ✅ in the boxes that apply
Put an ✅ in the boxes once you have confirmed below actions (or provide reasons on not doing so) that
I already tested with a local xdc node. And we can also do the same test on devnet/testnet. The plan is as follows.
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
this fake code should return 0xff: 60ff60005360016000f3, no matter calldata. so you can run
60ff60005360016000f3
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
ownerCount is stored at key=000000000000000000000000000000000000000000000000000000000000000a. So we override it with 0x33 (or any random number) and call getOwnerCount().
ownerCount
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
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 applyImpacted Components
Which part of the codebase this PR will touch base on,
Put an
✅
in the boxes that applyChecklist
Put an
✅
in the boxes once you have confirmed below actions (or provide reasons on not doing so) thatTest 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()
Expected result : the number of owner
Test override code:
this fake code should return 0xff:
60ff60005360016000f3
, no matter calldata. so you can runExpected result : 0xff
Test override state:
ownerCount
is stored at key=000000000000000000000000000000000000000000000000000000000000000a. So we override it with 0x33 (or any random number) and callgetOwnerCount()
.Use state inside parameter.
or Use stateDiff inside parameter.
Expected result : 0x0000000000000000000000000000000000000000000000000000000000000033