Locked

Unlock the contract by finding a way to modify its state despite access restrictions.

Vulnerable Code
Analyze the Solidity code below to find the vulnerability.
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract Locked { bool public unlocked = false; // slot 0 struct NameRecord { // slot 1 bytes32 name; address mappedAddress; } mapping(address => NameRecord) public registeredNameRecord; // slot 2 // Register new name - only requirement is that it is not already registered function register(bytes32 _name, address _mappedAddress) public { // Make sure the name is not already registered require(registeredNameRecord[_mappedAddress].name == 0, "Name already registered"); registeredNameRecord[_mappedAddress] = NameRecord({ name: _name, mappedAddress: _mappedAddress }); } function unlock() public { require(unlocked, "Contract is locked"); // Do something after unlocking if needed } // Helper function (not part of original Ethernaut level) // Allows checking registration status easily function getRecord(address _addr) public view returns (bytes32, address) { return (registeredNameRecord[_addr].name, registeredNameRecord[_addr].mappedAddress); } }
Submit Explanation
Explain the vulnerability and how to exploit it.
Hints (6)
Just a little peak
Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Hint 6
Explanation
Discomfort = Learning