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

46_ProxyContract /ProxyContract.sol 调用caller函数为什么返回值是1??? #518

Open
web3-panpan opened this issue Jul 5, 2023 · 1 comment

Comments

@web3-panpan
Copy link

contract Caller{
address public proxy; // 代理合约地址

constructor(address proxy_){
    proxy = proxy_;
}

// 通过代理合约调用 increase()函数
function increase() external returns(uint) {
    ( , bytes memory data) = proxy.call(abi.encodeWithSignature("increment()"));
    return abi.decode(data,(uint));
}

}

// 大佬们, 这个地方为什么返回值是1, 不是100呢???

@cloud8little
Copy link

可以这么理解,调用代理合约时,代理合约将会维护自己的状态变量,此处的状态变量是implementation和变量X,proxy合约通过构造函数初始化了implementation变量,变量X没有赋值,那么就是默认值0,调用increment函数,返回x+1,那么就是返回的0+1 也就是1。
理解代理合约一定要理解代理合约自己的状态变量和逻辑合约的状态变量是独立的

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