I am working on the ethernaut CTF level (code below)...I need to take over ownership of the instance (it's been deployed). I thought I could do it by sending a small amount of ETH to the instance address with the hex data being the encoded function selector for pwn(). Since the fallback function does a delegatecall to the delegate contract using whatever msgdata is included with the call.
But I've tried it and it doesn't work. Here is my tx Note that it fails from contract execution not out of gas
Why does this not work?
Here is the contract:
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract Delegate { address public owner; constructor(address _owner) { owner = _owner; } function pwn() public { owner = msg.sender; } } contract Delegation { address public owner; Delegate delegate; constructor(address _delegateAddress) { delegate = Delegate(_delegateAddress); owner = msg.sender; } fallback() external { (bool result,) = address(delegate).delegatecall(msg.data); if (result) { this; } } }