DL·SYS
Contact ↗

CSCTF 2026 · Misc · 120 pts

golem.

A register machine with ten documented quirks, and a service that checks all of them byte for byte.

InterpreterSpec complianceFuzzingProtocol
EventCSCTF 2026, Operation Dawn (online jeopardy)
CategoryMisc
Points120
StatusSolved during the event
TargetAudit service, 100 rounds (assigned TCP instance)

TL;DR. The audit service runs 100 random GASM programs and compares the output string exactly. The only way through is an interpreter that implements the specification literally: 16-bit wraparound, div 0 = 65535, mod 0 = dividend, shift counts masked with & 15, in past the tape yielding 65535, rep 0 running zero times, and ifz/ifn testing once at block entry. Validated against 24 examples, 7,000 fuzz programs and 100 mock rounds, then run live.

Challenge

The golem is a small register machine used by Ash Army signals engineers. The handout contains SPEC.md and 24 worked examples. The audit service sends a program plus an input tape per round, and expects the exact output the machine would print. One wrong answer closes the session.

First look

The machine has 16 registers r0..r15, all unsigned 16-bit and initialised to zero. Programs are line-oriented: set, add, sub, mul, div, mod, and, or, xor, not, shl, shr, in, out, rep, ifz, ifn, end. There are no jumps, so every well-formed program terminates.

The protocol is fresh per connection:

=== round k/100 ===
PROGRAM
<lines>
.
INPUT <space-separated bytes>
OUTPUT>

The client answers with one line and reads OK or WRONG. A wrong answer closes the socket; a new connection starts a new set of rounds.

Dead ends

Solution

1. Implement the quirks, not the intent

OperationBehaviour
Any register writevalue & 0xFFFF; immediates are signed and wrapped
divunsigned floor division; divisor 0 returns 65535
moddivisor 0 returns the dividend unchanged
shl, shrshift count is b & 15; shr is logical
not~v & 0xFFFF
inreads the tape left to right; past the end yields 65535
rep Nruns the body exactly N times; N=0 runs it zero times
ifz, ifntest once at block entry
no outprints an empty line

Two details prevent most bugs. Read both source operands before writing the destination, so add r0 r0 r0 doubles. And parse into a block tree rather than a flat instruction list, because rep/ifz/ifn need matching end tokens and nested bodies.

def write(i, v):
    regs[i] = v & 0xFFFF

def div(a, b):
    return 0xFFFF if b == 0 else a // b

def mod(a, b):
    return a if b == 0 else a % b

def shift(op, a, b):
    n = b & 15
    return ((a << n) if op == "shl" else (a >> n)) & 0xFFFF

2. Validate before touching the service

python3 golem.py selftest examples.txt
# 24/24 examples reproduced byte-exactly

A second interpreter with a different design (flat bytecode, iterative execution, explicit block frames) was compared on 7,000 randomly generated programs. The generator covered nested blocks, rep 0, negative and overflowing immediates, division by zero, shifts above 15, and short or oversized tapes. Both implementations agreed on every program, and both reproduced all 24 examples.

3. Answer the audit

python3 golem.py <HOST> <PORT>
[*] round 1/100  OK (1 value)
...
[*] round 100/100  OK (3 values)
CSCTF{...}

The client buffers reads, takes the round count from the header, tolerates CRLF and empty tapes, and sends an empty line when the expected output is empty. A wrong answer deliberately exits without printing a flag, so a failed run cannot be mistaken for a solve.

Flag

FlagCSCTF{HKMcdRnEHIUv8LFsCP6s7ZcL}

What I took from it