Explore Courses Blog Tutorials Interview Questions
0 votes
in Blockchain by (12.7k points)


Contract A has a state variable owner, which initialized well to msg.sender. But this owner variable became 0x0 when invoked from another contract function which takes the address of contract A's instance and converts to A-type.


Compiler version: 0.4.25

Framework/IDE: Remix

EVM execution environment :

Choose 'Javascript VM' on Run tab of Remix IDE;

Steps to Reproduce: step is described among the code.

(code also available at

pragma solidity 0.4.25;

contract A{ 

   address public owner;

   event Ret(string flag, address sender, address owner);

      event ConstrutEvt(string flag,  address owner );

   function A() public{

       owner = msg.sender;

       emit ConstrutEvt("A", msg.sender);


   function doSomething()  public view returns(string flag, address sender, address owner){

            emit Ret("A::doSomething", msg.sender, owner);

            return ("A::doSomething", msg.sender, owner);



contract EvilDoer{

// step1: deploy contract A on remix IDE. 

// and the log show `owner` is a valid address value.

// step2: deploy contract EvilDoer.

// step3: on remix IDE run tab, invoke doSomething() use the contract A address as argument.  

// This time the log show that 'owner' is zero. Why ?

    function doSomethingEvil(address instanceAddrOfA) public {

         A contractA = A(instanceAddrOfA);




1 Answer

0 votes
by (29.5k points)

I think that your issue is not with 'EvilDoer', but rather with the doSomething() function in A.
When you set your return values, you are assigning them values string flag, address sender, address owner, what you are doing is overwriting the owner variable you defined above.To fix this, change the name of owner in your return declaration to something like _owner so that you do not overwrite the global variable.

Browse Categories