Part 10 in Gates that lie. Earlier parts include what a gate is and comparing the right thing.
What this is about
A gate checks that work is good before it moves on. It might check that a result is correct, or that a program is fast enough.
Now imagine that the work being checked can also change the gate's tools. It could move the stopwatch, or rewrite the answer key. Then the work could pass without being good.
That is a gate that can be cheated. This article shows how we found one in our own code, and how we fixed it.
Why it matters
Think of an exam where the student writes the answer sheet. Everyone gets full marks. The marks mean nothing.
You might think nobody would build such a gate. But it happens by accident, when the tools of the check and the thing being checked live in the same place.
How it works
The setup
We run a loop that improves code on its own. A proposer, which can be a person or a model, changes a GPU kernel. A gate script then builds the change, checks its output against a reference, times it, and decides whether the change stays.
On 2026-09-08 we audited that gate with one question: could a candidate that changes nothing meaningful still pass every stage, even the speed stage, by editing something else?
We built four candidates to try.
The stopwatch was inside the room
The gate measured speed by reading two clock values from the same file the candidate was allowed to edit. Between them was a call that waits until the GPU has finished its work. That call is what makes the clock honest. Without it, the program reads the clock the instant it hands work to the GPU, and not when the work is done. The time it measures is almost nothing.
Candidate 1 deleted that one line. Nothing about the maths changed. The output check passed, because the values were the same. The speed stage read 108.6, 108.9 and 110.8 tokens per second, against a true champion near 67. The gate scored it as a pass at plus sixty-three percent, with a tight spread.
A second way: the answer key
Candidate 3 changed one output value to zero, then rewrote the reference file that the output check compares against, replacing it with its own new output. The check passed, 64 of 64. It compared the candidate with a file the candidate had just written. This one made no speed claim, so it failed on other grounds later, but the correctness result alone was a clean pass produced by a check that trusted a file the tested code could write.
Caught by luck
Two other candidates moved a timer value by a large amount, or deleted a flag that marks the work as finished. Both gave absurd speeds, as high as 923,618 tokens per second. The gate rejected them, but only because the numbers swung wildly and tripped the spread limit. Had the timer been moved by a small amount, such as 100 milliseconds, the result would have looked like a tidy plus thirteen percent and passed. The spread check catches clumsy cheating. It does not stop careful cheating.
The rule
A candidate under test may never own anything the gate reads to decide whether it passed: not the clock, not the wait that makes the clock honest, not the reference file, and not the path to the reference file.
The fix
We split the engine into two files with two trust levels.
- One file holds the part a candidate may change. It is the only surface the proposer edits.
- The other file owns the stopwatch, the waits and the harness logic. On every gate run, it is taken fresh from git at a fixed commit, and nothing a candidate sends can touch it.
After the split, a harmless change to the first file passed the build and the output checks, and read 130.4 tokens per second against 130.2 for the champion in the same run, which the speed stage correctly rejected as no gain. A direct attempt at the same attack, changing a position counter, failed the output check at the very first position, because there was no timing variable left to attack.
Tightening the spread limit would not have helped. Candidate 1 was internally consistent, 108.6 to 110.8. A steady wrong number passes a spread check easily.
What it cost
It cost a real change to the design. The harness now has to be pulled from git on every run, rebuilt and kept byte-identical to a known-good commit. That is slower and has more moving parts.
The audit also found that a different stage, one that counts how often the GPU runs out of its fastest storage and spills values to slower memory, was set at a bar that even our own champion code could not pass. So earlier clean results from the loop had been going through a gate that was uncalibrated. We changed that stage to compare against a same-session build of the champion.
What counts and what does not
Counts:
- Putting the clock and the reference out of reach of the tested code.
- Fetching the harness from a fixed, trusted copy each time.
- Testing the gate by trying to cheat it.
Does not count:
- A tighter spread limit.
- Asking the tested code to behave.
- Trusting a reference file because it sits next to the code.
Glossary
- Candidate: a change being tested.
- Gate: a check that decides whether a change stays.
- Reference: the trusted answer a result is compared with.
- Synchronize: wait until the GPU has finished the work it was given.
- Spread: how far apart repeated results are.
- Tokens per second: a speed measure for text generation.
Try it
Take a check you rely on, such as a script that must pass before you save work. Write down every file and clock it reads. Can the thing being checked change any of them?
Our tool mojo-port follows this rule in a small way. The Mojo port may be written by you or by a model, and the check programs never trust it. They run the Python original and the port on the same cases, and the port cannot change the cases or the original.
What to remember
Keep the clock and the answer key out of the tested code's reach. Otherwise the gate can be passed without doing the work.

Commenti
Ancora nessun commento.
Accedi per commentare.