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

eth_getBalance with block parameter returns incorrect value in fork mode #1004

Closed
nebojsa94 opened this issue Nov 10, 2020 · 5 comments · Fixed by #1016
Closed

eth_getBalance with block parameter returns incorrect value in fork mode #1004

nebojsa94 opened this issue Nov 10, 2020 · 5 comments · Fixed by #1016
Labels
type:bug Something isn't working

Comments

@nebojsa94
Copy link
Contributor

Steps for reproducing:

  • npx hardhat node --fork https://fork_node
  • curl --data '{"id":6185245701164,"jsonrpc":"2.0","params":[{"from":"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266","to":"0x70997970c51812dc3a010c7d01b50e0d17dc79c8","gas":"0x5208","gasPrice":"0x3B9ACA00","value":"0x1","data":"0x","nonce": "0x0"}],"method":"eth_sendTransaction"}' -H "Content-Type: application/json"
  • curl --data '{"method":"eth_getBalance","params":["0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266", "{current_block - 1}"],"id":1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST http://127.0.0.1:8545

The third step should return 0x21e19e0c9bab2400000 but instead, the result is 0x0, another odd thing is that the third step will return the correct value if called before the second step, even with the block parameter.

This issue is not reproducible in normal mode.

@nebojsa94 nebojsa94 changed the title eth_getBalance with block parameter returns incorrect value option in fork mode eth_getBalance with block parameter returns incorrect value in fork mode Nov 10, 2020
@fvictorio
Copy link
Member

So the problem is that when you fork a block in node X, and then check the balance of one of the test accounts (that start with 10000 ETH each) at block X - 1, the result is 0, is that correct?

I'm not 100% sure if this is a bug or if it should be the desired behavior.

@nebojsa94
Copy link
Contributor Author

So when you fork a node at block X, the balance for test accounts is 10k ETH at block X, but after you send a transaction the balance for test accounts at block X is 0.

This is happening due to inconsistency in _runInBlockContext function, in the first case, the function will just early return since blockNumber.eq(await this.getLatestBlockNumber() is true, while in the second the balance is being fetched from the fork node

@fvictorio
Copy link
Member

Oh, I see. But I think we should decide what the correct behavior should be.

Should they have 10000 ETH at block X? Or only after X+1 (that is, after the first transaction in the fork)? What about block X-1 and before?

cc @alcuadrado

@fvictorio fvictorio added the type:bug Something isn't working label Nov 11, 2020
@nebojsa94
Copy link
Contributor Author

I think the correct way is to have 10k ETH at block X and 0 at block X-1 and before.

If you have 10k ETH only after X+1, then the transaction that occurred in block X+1 wouldn't be valid since the sender balance is 0 given that the sender is one of the test accounts.

@fvictorio
Copy link
Member

Yeah, I agree with that reasoning 👍

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants