0

I am getting different results when I run my Test case on JVM and Rinkeby. Surprisingly, Rinkeby is the network not acting as expected. The focus is on delegateCall and changing ownership of a contract via a fallback function. (It's exercise 6 on the Ethernaut challenge Ethernaut)

Update: When I modified the Ethernaut code to work with 0.7.4 Rinkeby behaved as expected. This implies that the current Version of Rinkeby will not run code compiled with ^0.5.0 correctly and old contracts will stop functioning as expected? Is my reasoning correct? Thank you

When I call the Delegation Contract's fallback function with call(abi.encodeWithSignature("pwn()")); In JVM it changes the Delegation Contract's Owner but it does nothing when run on Rinkeby. In Rinkeby, the Owner remains unchanged.

I uploaded a video on YouTube: JVM vs Rinkeby to show the different behavior. Based on my understanding JVM is behaving correctly but Rinkeby is not.

Thank you for an explanation of why the behavior is different.

Code from Ethernaut Exercise 6: Delegation

pragma solidity ^0.5.0;

contract Delegate {

  address public owner;

  constructor(address _owner) public {
    owner = _owner;
  }

  function pwn() public {
    owner = msg.sender;
  }
}

contract Delegation {

  address public owner;
  Delegate delegate;

  constructor(address _delegateAddress) public {
    delegate = Delegate(_delegateAddress);
    owner = msg.sender;
  }

  function() external {
    (bool result, bytes memory data) = address(delegate).delegatecall(msg.data);
    if (result) {
      this;
    }
  }
}

My code that calls Delegation's fallback function

// SPDX-License-Identifier: MIT

pragma solidity 0.7.4;

contract MyDelegateCall {

    address public contractAddress;
    
    // Assign the address of the Contract
    constructor(address _contractAddress) payable {
        contractAddress = _contractAddress;
    }
    
    function changeOwner() external {
        
        (bool success,) = contractAddress.call(abi.encodeWithSignature("pwn()"));
        require(success);
        
    }

}
3
  • Please add more details about what coed you're running - the reference to DELEGATECALL and Ethernaut are helpful, but knowing what you're running, how you expect it to work (the Remix VM output), and what you're getting on Rinkeby instead, would give viewers their best chance at helping. Cheers! Nov 25 '20 at 9:53
  • when I call the Delegation Contract's fallback function with call(abi.encodeWithSignature("pwn()")); In JVM it changes the Delegation Contract's Owner but it does nothing when run on Rinkeby. In Rinkeby, the Owner remains unchanged.
    – Picard78
    Nov 25 '20 at 9:58
  • Thanks! Please put the relevant code from the Delegation Contract in the question, along with the web3 call from the comment, it makes it a lot easier on someone who might want to answer. You want to try and get the friction between reading the question and answering it as low as possible. Nov 25 '20 at 10:01
0

It was running out of GAS in Rinkeby before completing all of the code execution. There was no error message in the Remix console so I assumed execution completed. When I increased the GAS in Metamask it worked as expected.

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.