Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

透明代理-解决的问题没有讲清楚 #116

Open
0xcmhy opened this issue Nov 15, 2023 · 1 comment
Open

透明代理-解决的问题没有讲清楚 #116

0xcmhy opened this issue Nov 15, 2023 · 1 comment

Comments

@0xcmhy
Copy link

0xcmhy commented Nov 15, 2023

Proxy Contract和Implementation Contract有一个名称和参数相同的函数。想象一下,如果Proxy Contract有一个owner()函数,Implementation Contract也有。在透明代理合约中,这个问题由Proxy Contract来处理,Proxy Contract根据msg.sender全局变量来决定用户的调用是在Proxy Contract本身还是在Implementation Contract中执行。

文中的代码没有演示清楚。假设应该是admin调用了proxy的和logic 相同的selector时,proxy能区分开来,并且争取调用。而不是单单报错。
代码应该给下面的demo
`
/**
* @dev If caller is the admin process the call internally, otherwise transparently fallback to the proxy behavior.
*/
function _fallback() internal virtual override {
if (msg.sender == _proxyAdmin()) {
if (msg.sig != ITransparentUpgradeableProxy.upgradeToAndCall.selector) {
revert ProxyDeniedAdminAccess();
} else {
_dispatchUpgradeToAndCall();
}
} else {
super._fallback();
}
}

/**
 * @dev Upgrade the implementation of the proxy. See {ERC1967Utils-upgradeToAndCall}.
 *
 * Requirements:
 *
 * - If `data` is empty, `msg.value` must be zero.
 */
function _dispatchUpgradeToAndCall() private {
    (address newImplementation, bytes memory data) = abi.decode(msg.data[4:], (address, bytes));
    ERC1967Utils.upgradeToAndCall(newImplementation, data);
}

`

@AmazingAng
Copy link
Member

好建议 你可以提个pr到 https://github.com/AmazingAng/WTF-Solidity 吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants