Description
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 take address of contract A's instance and convert to A type.
Environment
- 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 https://github.com/ethereum/solidity/issues/5210)
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);
contractA.doSomething();
}
}