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

Issue with method call result with msg.sender and Geth 1.9.12 #3456

Closed
Aniket-Engg opened this issue Apr 3, 2020 · 8 comments · Fixed by #3467 or #3679
Closed

Issue with method call result with msg.sender and Geth 1.9.12 #3456

Aniket-Engg opened this issue Apr 3, 2020 · 8 comments · Fixed by #3467 or #3679
Labels
1.x 1.0 related issues Discussion

Comments

@Aniket-Engg
Copy link

Aniket-Engg commented Apr 3, 2020

Sample contract

contract GetMyBalance {

    // below function cant get right result
    // using Remix I get:
    // 0: uint256: 115792089237316195423570985008687907853269984665640564039457581007913129639935
    function _getMyBalance()
        // external
        public
        view
        returns(uint256)
    {
        return msg.sender.balance;
    }

    // Below can get right result
    // by calling getMyBalance()
    // and then get right 
    uint256 public logMyBalance_;
    function getMyBalance()
        external
    {
        logMyBalance_ = _getMyBalance();
    }

    // I can get right result
    uint256 public logMyBalance;
    function writeMyBalance() external {
        logMyBalance = msg.sender.balance;
    }
}

Expected behavior

Actual balance of caller

Actual behavior

115792089237316195423570985008687907853269984665640564039457581007913129639935

Steps to reproduce the behavior

  1. Deploy contract on any testnet except kovan or on Mainnet
  2. call _getMyBalance method

Related Issues on different repos

https://github.com/ethereum/remix/issues/1430
ethereum/solidity#8545

Versions

web3js: 1.2.6

@cgewecke cgewecke added the 1.x 1.0 related issues label Apr 3, 2020
@cgewecke
Copy link
Collaborator

cgewecke commented Apr 3, 2020

@Aniket-Engg Thanks for reporting, will investigate...

@cgewecke
Copy link
Collaborator

cgewecke commented Apr 7, 2020

@Aniket-Engg Copying over a summary of the discussion in ethereumjs gitter...

@ryanio identified the cause of this as a Geth 1.9.12 breaking change.

From: https://github.com/ethereum/go-ethereum/releases/tag/v1.9.12

One small breaking change in the release is that eth_call will not default to 
your first account any more if you don't explicitly specify a sender. This was done 
to avoid the same input behaving differently in different environments. You should 
never do eth_call without explicitly setting a sender in the first place.

The question now is whether or not Web3 should (try to) set an account for eth_call by default.

@cgewecke cgewecke changed the title Issue with method call result Issue with method call result with msg.sender and Geth 1.9.12 Apr 7, 2020
@Aniket-Engg
Copy link
Author

IMHO, Web3 can explain the situation in the documentation and recommend to explicitly define a fromaddress but in case, address is not provided, Web3 should set it to first address by default.

With time, when users are aware about it, default support can be deprecated and removed.

@cgewecke
Copy link
Collaborator

cgewecke commented Apr 16, 2020

This also affects any .estimateGas request and any state changing method invoked with .call.

Re-opening for visibility because it looks like Geth just published this change to their docker stable tag.

In our unit tests, when calling estimateGas without specifying a from address in the options, the error is:

gas required exceeds allowance (4000000) or always failing transaction

@cgewecke cgewecke reopened this Apr 16, 2020
@Alirun
Copy link

Alirun commented Apr 21, 2020

Also happens to me

.estimateGas works properly against Infura in Rinkeby and event against Geth node in Mainnet. But same code doesn't work for one smart contract function against Geth in Mainnet.

Specifying all the parameters: from, nonce and even tried with gas

@GregTheGreek
Copy link
Contributor

Is there any update on this?

@ryanio
Copy link
Collaborator

ryanio commented Jun 30, 2020

@GregTheGreek there were some notes added to the docs in #3467. a similar note could be added for estimateGas.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment.

@github-actions github-actions bot added the Stale Has not received enough activity label Jul 31, 2020
@GregTheGreek GregTheGreek removed the Stale Has not received enough activity label Jul 31, 2020
GregTheGreek added a commit that referenced this issue Aug 10, 2020
GregTheGreek added a commit that referenced this issue Aug 11, 2020
Co-authored-by: Frankie <frankie.diamond@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x 1.0 related issues Discussion
Projects
None yet
5 participants