Level 1 Noob Hacker
Ethernaut 20 Alien Codex
0 / 100 EXP 100 EXP to Junior Hacker
0%

Challenge 20 / Ethernaut

Alien Codex

Goal

  1. Overwrite Alien Codex's owner with the player address.

Your task

Review the protocol contracts, then complete Exploit.s.sol.

:~/targets/ethernaut-alien-codex$
// SPDX-License-Identifier: MIT
pragma solidity ^0.5.0;

contract Ownable {
    address public owner;

    constructor() public {
        owner = msg.sender;
    }

    modifier onlyOwner() {
        require(msg.sender == owner);
        _;
    }

    function transferOwnership(address newOwner) public onlyOwner {
        owner = newOwner;
    }
}

/// @notice Adapted from OpenZeppelin Ethernaut level 19. Solidity 0.5 is
/// intentional: decrementing an empty dynamic array has no checked arithmetic.
contract AlienCodex is Ownable {
    bool public contact;
    bytes32[] public codex;

    modifier contacted() {
        assert(contact);
        _;
    }

    function makeContact() public {
        contact = true;
    }

    function record(bytes32 content) public contacted {
        codex.push(content);
    }

    function retract() public contacted {
        codex.length--;
    }

    function revise(uint256 index, bytes32 content) public contacted {
        codex[index] = content;
    }
}