情况是:一个呼叫B的代表呼叫C呼叫D
D中的msg.sender是什么?
我在Remix上做了一些测试,看起来msg.sender在D是C的地址。我不明白为什么这不是A的地址。
发布于 2023-02-01 03:24:20
在混炼上运行测试代码后,它会显示上面的答案是不正确的,应该是
A -> B (call) msg.sender = A (updates happen on B's storage)
B -> C (delegatecall) msg.sender = A (updates happen on B's storage)
C -> D (call) msg.sender = B (updates happen on D's storage)只需自己运行以下代码
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract B {
function callMe(address c, address d) public {
c.delegatecall(
abi.encodeWithSignature("callMe(address)", d)
);
}
}
contract C {
event CalledC(address who);
function callMe(address d) public {
emit CalledC(msg.sender);
D(d).callMe();
}
}
contract D {
event CalledD(address who);
function callMe() public {
emit CalledD(msg.sender);
}
}发布于 2022-03-13 16:40:13
为什么会这样?C不是delegatecall in D,所以在那个调用中msg.sender将是C。
A -> B (call) msg.sender = A
B -> C (delegatecall) msg.sender = A
C -> D (call) msg.sender = Chttps://ethereum.stackexchange.com/questions/123704
复制相似问题