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

return address.balance returns strange value #16999

Closed
danfinlay opened this issue Jun 15, 2018 · 3 comments · Fixed by #20783
Closed

return address.balance returns strange value #16999

danfinlay opened this issue Jun 15, 2018 · 3 comments · Fixed by #20783

Comments

@danfinlay
Copy link

Originally opened at remix
Then at MetaMask
Then here at Geth (but I think mis-represented, so prematurely closed).

Solidity:

pragma solidity ^0.4.11;

contract Test {
  function balanceOfEther(address user) public constant returns (uint256) { return user.balance; } 
}

Returns unusual balances when requested from Geth via an eth_call.

For any address, returns:

{"jsonrpc":"2.0","id":570283474,"result":"0xfffffffffffffffffffffffffffffffffffffffffffffffffdeb17cb73b0ffff"}
@radek1st
Copy link

radek1st commented May 6, 2019

I've hit the exactly same issue on Rinkeby for balance of normal accounts. I also noticed that for deployed contracts balance returns the correct value.

@karalabe karalabe self-assigned this Nov 21, 2019
@karalabe karalabe added this to the 1.9.8 milestone Nov 21, 2019
@holiman
Copy link
Contributor

holiman commented Nov 21, 2019

We've discussed this; the better solution is to make gasPrice zero instead of putting an arbitrarily large lump of money on the sender.

@karalabe karalabe modified the milestones: 1.9.8, 1.9.9 Nov 27, 2019
@karalabe karalabe modified the milestones: 1.9.9, 1.9.10 Dec 6, 2019
@karalabe karalabe modified the milestones: 1.9.10, 1.9.11 Jan 21, 2020
@karalabe karalabe modified the milestones: 1.9.11, 1.9.12 Feb 18, 2020
@karalabe karalabe modified the milestones: 1.9.12, 1.9.13 Mar 16, 2020
@holiman
Copy link
Contributor

holiman commented Mar 19, 2020

EDIT: yes, we set the balance in

func (b *EthAPIBackend) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header) (*vm.EVM, func() error, error) {
	state.SetBalance(msg.From(), math.MaxBig256)
	vmError := func() error { return nil }

This is just plain wrong, we don't even check if it already has a balance (which can be set via overrides)

holiman added a commit to holiman/go-ethereum that referenced this issue Mar 19, 2020
fjl pushed a commit that referenced this issue Mar 23, 2020
…20783)

Prior to this change, eth_call changed the balance of the sender account in the
EVM environment to 2^256 wei to cover the gas cost of the call execution.
We've had this behavior for a long time even though it's super confusing.

This commit sets the default call gasprice to zero instead of updating the balance,
which is better because it makes eth_call semantics less surprising. Removing
the built-in balance assignment also makes balance overrides work as expected.
enriquefynn pushed a commit to enriquefynn/go-ethereum that referenced this issue Mar 10, 2021
…16999 (ethereum#20783)

Prior to this change, eth_call changed the balance of the sender account in the
EVM environment to 2^256 wei to cover the gas cost of the call execution.
We've had this behavior for a long time even though it's super confusing.

This commit sets the default call gasprice to zero instead of updating the balance,
which is better because it makes eth_call semantics less surprising. Removing
the built-in balance assignment also makes balance overrides work as expected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants