3

I have deployed the following smart contract: 0x016d87b8c98e6ad0991d128CddA435FAfbC06792

//SPDX-License-Identifier: MIT
pragma solidity 0.8.15;

contract Proxy {
    uint256 public count;
    address public contractLogic;

    function setAddress(address _addr) external {
        contractLogic = _addr;
    }

    function setCount(uint256 _count) external{
       (bool success, ) = 
       contractLogic.delegatecall(abi.encodeWithSignature("setCount(uint256)", _count));
    }
}

and the following ContractLogic: 0x4E87a50B11A84F3270eE9C35aB9308B1d8cD8228

//SPDX-License-Identifier: MIT
pragma solidity 0.8.15;

contract ContractLogic {
    uint256 public count;
    address public contractLogic;

    function setCount(uint256 _count) external {
        count = _count + 2;
    }
}

When I send a transaction to setCount, in proxy, on remix it works perfectly but on goerli it is not changing the value of count as I expect, but if I add the following line after the delegatecall

require(success, "fail");

it works so the questions is What am I missing? Why the first contract is not working?

Here you can find the second smart contract deployed which is working as expected 0xb2962efD411BECa5421864aE4D0589A7870a57AE

//SPDX-License-Identifier: MIT
pragma solidity 0.8.15;

contract Proxy {
    uint256 public count;
    address public contractLogic;

    function setAddress(address _addr) external {
        contractLogic = _addr;
    }

    function setCount(uint256 _count) external{
       (bool success, ) = 
       contractLogic.delegatecall(abi.encodeWithSignature("setCount(uint256)", _count));
       require(success, "fail");
    }
}
2
  • Following. I tried your code on remix and it worked as expected but after deploying to goerli I get same issue as you. All I can think of is there may be some compiler optimization bug happening due to your unused variable in proxy contract. Let us know if you find answer.
    – Bigbrotha
    Aug 28 at 5:39
  • i have updated my question in order to add that detail, I forgot to mention that it works on remix Aug 28 at 6:15

1 Answer 1

1

Case in which you did not add require(success, "fail"); it doesn’t update count because transaction runs out of gas. Try increasing the gas limit and it should work fine.

Transaction which Run out of gas but etherscan still shows succeed even tho count did not update

Transaction send with increased gas and updates count (doesn’t matter if you added require or not)

You can use https://ethtx.info/ to see the transaction Execution trace.

this answer might help to understand why the result of low-level operations is rejected where you did not add require after delegate call but etherscan show status succeeds even tho count was not updated.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.