1

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.

Edit

Problem solved. The reason causing the failure is insufficient gas.

  • Are you sure the transaction was mined? Can you get the transaction receipt and post it here? – Tjaden Hess Jun 9 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.