30 delegatecall 说的是persisting the current values for sender and value, 为什么delegatecall 之前memory中存储的东西全部清空了?

function() external payable{
        address _impl = implementation();

        assembly {
            let ptr := mload(0x40)
            calldatacopy(ptr, 0, calldatasize)

            let result := delegatecall(gas(), _impl, ptr, calldatasize(), 0, 0)
            returndatacopy(ptr, 0, returndatasize())

            switch result
            case 0 { revert(ptr, returndatasize()) }
            case 1 { return(ptr, returndatasize()) }
        }
    }

中,当调用delegatecall之前,内存如下: image20210802235548852.png

当调用delegatecall之后,内存如下: image20210802235621514.png

为什么会把内存也变了? 那黄皮书中说的保存caller中的sender和value值又是什么意思呢? 保存sender体现在哪?

也就是说delegatecall事实上发生了上下文切换?那他的substates是怎么保存的呢?

请先 登录 后评论

3 个回答

Deep Defi - Solidity engineer
请先 登录 后评论
张小风
请先 登录 后评论
bixia1994 - 互联网小工
请先 登录 后评论