Skip to content

About

CipherLocker: a moderate Solidity CTF on storage layout and immutables (Foundry)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

CipherLocker — Smart Contract CTF

"Nothing on-chain is private. Not even the stuff that isn't in storage."

Difficulty Focus Est. time
Intermediate Sensitive on-chain data · EVM storage layout · bytecode 30–90 min

A vault engineer split the master password into three fragments and hid each one in a different "private" place inside CipherLocker. A wrong guess doesn't revert: it burns an attempt. Three misses and the locker bricks forever.

Goal

  • Unlock the locker (locked == false).
  • Become the owner of the contract (owner == player).

Your Task

Read src/CipherLocker.sol, then complete script/Exploit.s.sol.

function run() external {
    CipherLocker locker = CipherLocker(vm.envAddress("TARGET"));

    vm.startBroadcast(PLAYER_PRIVATE_KEY);

    // ════════════ YOUR EXPLOIT HERE ════════════

    // ═══════════════════════════════════════════

    vm.stopBroadcast();
}

Starting Facts

  • Owner: the deployer (the vault engineer)
  • locked: true
  • Attempts used: 0 of 3
  • Player balance: 1 ether
  • Player: 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 (public Anvil dev account #1)

Hints (0/5)

Hint 1 · CipherLocker.solTwo variables share slot 1. Which one sits in the low-order bytes?
Hint 2 · CipherLocker.solDynamic array data lives at keccak256(slot). How many bytes8 fit in one 32-byte slot?
Hint 3 · CipherLocker.solimmutable variables are not in storage. Where do they go after deployment?
Hint 4 · Exploit.s.solYou can read passwordHash. That means you can test candidates for free before spending an attempt.
Hint 5 · Exploit.s.solImmutables are inlined as a 32-byte PUSH32 (opcode 0x7f); a bytesN is left-aligned.

How this CTF works

Requires Foundry.

git clone --recursive https://github.com/mrstark25/cipher-locker-ctf.git
cd cipher-locker-ctf
# already cloned without --recursive? run: git submodule update --init

Verify your solution. The verifier in test/CipherLocker.t.sol deploys a fresh target with new randomness, runs your Exploit.s.sol, then asserts the goal. It fails until you solve the challenge.

forge test --match-contract CipherLockerChallenge -vv

Play against a local chain (optional).

anvil                                                    # terminal 1
forge script script/Deploy.s.sol --rpc-url http://127.0.0.1:8545 --broadcast
TARGET=<deployed address> forge script script/Exploit.s.sol \
  --rpc-url http://127.0.0.1:8545 --broadcast

You can also poke the deployed contract with cast storage and cast code.

Rules

  • Edit only script/Exploit.s.sol. Leave src/ and test/ as they are.
  • Reading state is allowed (vm.load, address.code, cast storage, cast code).
  • Don't use cheatcodes that write state (vm.store, vm.etch, vm.deal, vm.prank).

The keys in script/ are Anvil's public dev keys. Never send real funds to them.

What you'll learn

  1. Packed storage slots and byte ordering (bytes16 + uint128 in one slot)
  2. Dynamic array slot math and sub-slot packing
  3. constant vs immutable vs storage, and why immutables are in runtime bytecode
  4. Off-chain verification against a leaked hash (don't waste on-chain attempts)
  5. Spotting decoys (MASTER_KEY, the notes mapping)

Solution

No solution is published here, so the puzzle isn't spoiled. Solved it? Open an issue titled Solved: <your handle> with a short write-up, without code.

Credits

Written by Nikhil Baghel. Inspired by the Ethernaut Vault and Privacy levels.

License

MIT

About

CipherLocker: a moderate Solidity CTF on storage layout and immutables (Foundry)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages