d4rk{tr1pPy_fr4ctl!}c0de

A 500-point reverse of a hardware netlist: you invert a fractal renderer built from Yosys core + mix blocks all the way back into the flag.
Summary
The handout is a Yosys netlist (core + mix) plus a testbench tb.v. tb.v turns a
24-character flag into six 32-bit chunks and, for every pixel (x, y), computes one 8-bit
"level" per chunk (core) and folds the six levels into RGB (mix) to render a 1024×1024
image. The shipped chall.png is the author's render of the real flag, so the challenge is
exactly invert "flag → image".
Two things make it tractable:
mixis GF(2)-affine per channel, not a colour blend — each output channel is an XOR of a constant with a handful of linear maps of individual levels. Each channel therefore exposes only a subset of the six levels, which lets you solve the chunks one channel at a time.coreis a Newton-fractal iteration in Q32.32 fixed point on a cubic whose coefficients are the chunk bytes, so each chunk's level field can be reproduced exactly offline in C (~1 µs/level) after it is reversed from a cycle-accurate trace.
Recovered chunks: d4rk | {tr1 | pPy_ | fr4c | tl!} | c0de ⇒
d4rk{tr1pPy_fr4ctl!}c0de (24 chars), confirmed accepted on the scoreboard.
Solution / Exploit
1. mix is XOR-affine (48-bit → 24-bit)
Measured with the verilator mix and then proven exact:
r = 0x60 ^ R0(l0) ^ R3(l3) ^ R5(l5)
g = 0x00 ^ G1(l1) ^ G3(l3) ^ G4(l4)
b = 0x60 ^ B2(l2) ^ B4(l4) ^ B5(l5)
Each R*/G*/B* is an 8×8 GF(2) map applied to a single level, and the channel output is
XOR-linear in its contributing levels. Verified on 200/200 random 6-tuples. So:
- r-channel sees levels l0, l3, l5
- g-channel sees l1, l3, l4
- b-channel sees l2, l4, l5
2. core = Newton-fractal iteration in Q32.32
Reversed from a cycle-accurate trace of the microcoded netlist (op_trace_full.log, produced
by the verilator harness op_tb_dbg.v + the instrumented netlist copy chall_dbg.v):
- Chunk bytes
b3..b0(MSB first) become cubic coefficientsH_i = (b_i − 79)·178956971, i.e.(b − 79)/24in Q32.32 (79 =const_rom[0], 1/24 =const_rom[1]). z0 = ((px − 512)·7/1024, (py − 512)·7/1024)(const_rom[2]= 512,const_rom[3]= 7/1024).- Newton's method on
p(z) = H0·z³ + H1·z² + H2·z + H3:unit_ais a complex MACy = a·b + cwithm=1⇒ conjugate form;unit_bis a per-lane(a<<32)/b. Iteratez ← z − p(z)/p'(z)until both lanes of the step are within1/2^20(up to ~255 iterations). - Colouring:
t = step·2^20;u = |t|²;C1 = unit_c(u);a = 9/8192 − C1;b = a·(ln2/2);C2 = unit_c(b);c = C2 − 1/4096;d = n/65536 − c;e = d/20;f = 0.9922·e;q = floor(sqrt(f_raw))(unit_d= integer sqrt,unit_c=65536·log2(raw)). - Implemented as
op_lvl.c(C, ~1 µs/level). Validated against the verilatorcoreoracle: 1200/1200 exact on random(chunk, px, py)and text-like chunks (op_val_result.json), after fixing three details the trace exposed:- the complex MAC keeps full precision until one final
>>32; - convergence needs both lanes inside
1/2^20; qis clamped/saturated at 255.
- the complex MAC keeps full precision until one final
3. Chunk recovery (16 pixels spread over chall.png)
The required values come from chall.png. The flag format is d4rk{...}c0de, so the first
chunk (d4rk = l0) and the last (c0de = l5) are known oracle-exact. The remaining
chunks fall out one channel at a time (op_solve.c, stages 1/2/3):
- l3 appears only in the r-channel ⇒ brute-force
c3(stage 1,94³·…candidates). A narrow-charset run (op_s1b.out) yields three 16/16 hits —fr4c,gs4d,jy0f— becauseR3has rank 4 (256/16 = 16 level values share everyR3image), so collisions are expected. Disambiguation is not done on the r-channel: it comes from the end-to-end oracle check in §4 (onlyc3 = fr4cmakes all three channels reproducechall.png). Result:c3 = "fr4c"(0x66723463). - l1/l4 appear only in the g-channel ⇒ meet-in-the-middle on
G1(l1) ^ G4(l4)(stage 2): unique 16/16 hitc1 = "{tr1",c4 = "tl!}". - l2 appears only in the b-channel ⇒ brute-force
c2(stage 3): 16/16 hitspPy_(0x7050795f) and a decoy.N%?; resolved on 40 fresh oracle pixels (pPy_40/40, decoy 30/40).
4. Verification (independent of the model, via the netlist oracle)
obj_probe/simprobe (a compiled chall_net.v core) plus the exact mix module:
- flag
d4rk{tr1pPy_fr4ctl!}c0de→ 120/120 random pixels reproducechall.pngexactly (r, g, b), and 60/60 on a second pixel set. - every case variant of that flag fails (4/60, 5/60, 3/60, …), except
...fr4ctl1}...(23/60 ⇒ wrong), so the string is uniquely determined.
Ad-hoc re-verification (work/op_verify.py, which recompiles the changed sources against
read-only copies of the netlist oracles in a temp cwd — the shared handout dir is untouched):
1. level model vs netlist `core` oracle ....... 400/400 exact
2. op_solve stage 1 on a synthetic render ..... finds c3=lag_ 16/16 (self-test)
3. op_solve stage 1 on chall.png .............. unique c3=fr4c 16/16
4. flag -> oracle levels -> mix -> chall.png .. 50/50 pixels identical
5. format ..................................... len 24, d4rk{ ... }c0de
=> ALL CHECKS PASSED. Flag also confirmed ACCEPTED on the scoreboard.
op_lvl.c now defaults to the validated configuration (DIVMODE 0 = floor, EXITMODE 1 =
both step lanes inside 1/2^20); that pair is what gives 100 % agreement with the netlist.
Recovered chunks
d4rk | {tr1 | pPy_ | fr4c | tl!} | c0de
Flag(s)
d4rk{tr1pPy_fr4ctl!}c0de
Alternates
- The deliverable README table lists
d4rk{tr1pPy_fr4ct!}(nolinfr4ctl, noc0desuffix). The source is authoritative and differs:RESULT-lsd2.mdandHANDOFF.mdboth gived4rk{tr1pPy_fr4ctl!}c0deand record it as accepted on the scoreboard, and the 24-character field (d4rk{+tr1pPy_+fr4c+tl!}+c0de) matchestb.v's "24-char flag" exactly. The README value appears to be a truncated/typo'd copy.
Notes / Pitfalls
mixis not a colour blend. It is an XOR-affine bit map; naively "inverting the colour" gives nothing. The per-channel structure (r: l0,l3,l5; g: l1,l3,l4; b: l2,l4,l5) is exactly what makes a staged search possible.- r-channel collisions are expected, not a bug.
R3has rank 4, so 16 different level values share everyR3image — hence three 16/16 hits forc3. You cannot disambiguate on the r-channel alone; use the end-to-end oracle reproduction across all three channels. - The
~40 hoursrender comment intb.vis wrong. One level is ~1 µs in C / ~0.2 s in verilator, so a full 1024×1024 render is practical. - Old
lsd(year 1) was the same idea. lsd2 just moved the field to Q32.32 fixed point and made the iteration Newton's method on a cubic whose coefficients are the chunk. coredetails that only the trace reveals. Full-precision complex MAC until one final>>32; both-lanes1/2^20exit condition; saturatedq. Getting any of these wrong breaks agreement with the netlist.