0

Take these two contracts, both deployed on Kovan and with the source code verified:

And take this transaction:

Which has been reverted and I don't understand why.

I want to call the execute(address,bytes) function of the DSProxy and pass in the following arguments:

  • 0xE3CD2e7a628b57d3e50c5f7B921182f676721bDF
  • 0xb081b4eb (the signature for the "wrapEth" function)
  • Also send some amount of ETH

Effectively calling the wrapEth payable function defined in TargetContract, but via the DSProxy DELEGATECALL functionality.

With help from ethers.js, I generated the calldata for this multi-contract call, and it looks like this:

0x1cff79cd000000000000000000000000e3cd2e7a628b57d3e50c5f7b921182f676721bdf00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000004b081b4eb00000000000000000000000000000000000000000000000000000000

Unfortunately, when I relay this calldata to the Kovan testnet via MetaMask, MyCrypto or any other wallet, I am getting reverted transactions. Although I feel that the above calldata is correct, I tried tweaking the last part of the bytes (the function signature) in case there is a bug in Ethers, but with no luck.

Can you see the error here?

1

DSProxy uses delegatecall to call the target contract so inside wrapEth you are accessing DSProxy storage and not TargetContract.

You are reading weth from the wrong storage and using something else as weth address.

One possible solution is pass weth as a parameter.

contract TargetContract {
    constructor() {}
    
    function wrapEth(WethInterface weth) public payable {
        weth.deposit{ value: msg.value }();
    }
}

Another solution is to make TargetContract to inherit from DSProxy and use a function to initialize weth.

contract TargetContract is DSProxy {

    WethInterface public weth;

    function initialize(WethInterface _weth) public {
        weth = _weth;
    }
    
    function wrapEth() public payable {
        weth.deposit{ value: msg.value }();
    }
}
1
  • 1
    I completely missed this. Thanks, Ismael! A 3rd solution is to define the WETH address as a constant. Dec 3 '20 at 11:44

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.