Consider following two simple contracts.
contract Provider {
uint public constant value = 42;
event Caller(address addr);
function provide() external returns (uint) {
emit Caller(msg.sender);
return value;
}
}
contract Counter {
uint public counter;
address public provider;
constructor(address addr) {
counter = 0;
provider = addr;
}
function newvalue() public {
counter += Provider(provider).provide();
}
}
Let's say Provider
is deployed at 0x1
and Counter
is deployed at 0x2
.
Now a user with address 0x3
calls newvalue
.
The event emitted from provide
contains 0x2
as msg.sender
. (i.e. the address of Counter
)
Is there any way in which the original sender (i.e. 0x3
) can be seen as msg.sender in all internal transactions?
Note that this is not an ideal curiosity. Many protocols have hardcoded transfering of tokens to msg.sender
instead of taking an additional to
argument. This makes calling those functions form other smart contracts extremely unwieldy.