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

Proxy does not change state variable #139

Open
kevindaizj opened this issue Jun 9, 2019 · 0 comments
Open

Proxy does not change state variable #139

kevindaizj opened this issue Jun 9, 2019 · 0 comments

Comments

@kevindaizj
Copy link

I am trying to test proxy pattern in Remix, which connected to my private chain with Web3 Provider. By the way, miner is working all the time. After invoking add function of Proxy contract, the state variable total of Proxy contract has not change. But with Javascript VM, it changed as expected.

Here is the code:

pragma solidity ^0.5.0;

contract Proxy {

    address public implement;
    // with Web3 Provider, it didn't change. 
    // but with Javascript VM, It changed as expected.
    uint public total;  
    
    function changeImpl(address _impl) public returns(bool) {
        implement = _impl;
        return true;
    }

    // according to proxy pattern, this should be fallback function.
    // i change it as named function just for convenience
    function add(uint a, uint b) external {
        address _impl = implement;
        assembly {
            let ptr := mload(0x40)
            calldatacopy(ptr, 0, calldatasize)
            let result := delegatecall(gas, _impl, ptr, calldatasize, 0, 0)
        }
    }
}


contract ImplContract {
    
    address public implement;
    uint public total;

    function add(uint a, uint b) public returns(uint) {
        total = a + b;
        return total;
    }
}

I am so confused why same code make different outcome. Any help would be appreciated.

@kevindaizj kevindaizj changed the title Proxy pattern didn't change state variable Proxy does not change state variable Jun 9, 2019
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

1 participant