Web3.js: Issue with method call result with msg.sender and Geth 1.9.12

Created on 3 Apr 2020  路  8Comments  路  Source: ChainSafe/web3.js

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
https://github.com/ethereum/solidity/issues/8545

Versions

web3js: 1.2.6

1.x discussion

All 8 comments

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

@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.

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.

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

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

Is there any update on this?

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

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FradSer picture FradSer  路  3Comments

dhl picture dhl  路  3Comments

zamoore picture zamoore  路  3Comments

praveengupta0895 picture praveengupta0895  路  3Comments

xpepermint picture xpepermint  路  3Comments