A broken block of marble carved with large letters and rows of small ones, lying in a museum case

Twenty thousand programs nobody wrote

Our claim is about every program. We had tested it on a dozen. So we generated twenty thousand, and a third of one kind disagreed.

A browser tab on Verse is a machine like any other. It runs a job, signs a receipt, and a server runs the same job again. For that to be fair, the tab has to land on exactly the server's bits and exactly the server's count of work, in a different engine, on different hardware. We said it does.

What we had was a test that held this for every program we ship: nine small ones and three models. That is evidence about twelve programs. The claim is about all of them.

Programs nobody wrote

So we wrote a generator instead of more examples. It makes valid programs out of everything the count has a rule for: arithmetic, branches, loops, tables of jumps, calls through a table, early returns, code that is never reached, loads and stores, bulk copies, growing memory, floats in two widths and in vectors. Each program is run twice, the server's way and the browser's way, and the outputs and the counts must match to the unit. A failing program is named by one number, its seed, so it can be made again.

The first six hundred took four seconds. Twelve of the first hundred and fifty failed.

What failed

Not the count. Every failure traced back to one thing: NaN, the value a float takes when the arithmetic has no answer. A NaN has spare bits, a sign and a payload, and hardware disagrees about them. Divide zero by zero on an x86 chip and the sign bit is set. On ARM it isn't. The servers' engine wipes the difference: every NaN that arithmetic returns is made the same one. A browser's engine doesn't, and a program can look. It can reinterpret the float as an integer. It can write it to memory and read the bytes back. It can copy its sign onto another number.

Once a program has looked, the difference is in its data, and one branch later it is in its control flow. So the tab's output differed, and then its count of work differed too, by thousands of units in either direction. We knew about this corner and had it on the list of known gaps, in one line. We did not know its size. Among programs built to look at float bits, about a third gave another answer in the browser-style run.

The fix is the server's own rule

A tab already rewrites every program before running it, to count work the way the servers' engine does. Now the same pass does one more thing. After each operator that can return a NaN, it adds a check: is this result equal to itself? Only a NaN isn't. If not, replace it with the one canonical NaN. The list of operators is copied from the servers' engine, line for line, and so is the NaN. The added steps are never counted as work, because the count is ours to keep.

Then the generator ran again: twenty thousand programs that can see float bits, twenty thousand that can't. Every one gave the same output and the same count both ways. So did three thousand of each kind run as x86-64 code, the hardware whose NaNs differ most from ARM's. The three models still agree to the unit. The test now runs six hundred of each kind every time anyone runs the tests, and the long run is one setting away.

The edges

Stated plainly. Random programs are evidence, not proof: twenty thousand agreeing says the rule is right for everything the generator can write, and nothing about what it can't. The browser's way is run here in the servers' engine with its own counting and its own NaN handling switched off, not in a browser; a real Chrome and a real Safari are checked on the live network, on the programs we ship. And one difference is left that no rewriting fixes: a phone that cannot give a program the memory a server would.

We had a sentence about every program and a test about twelve. The sentence is the same. The test caught up.

Why two machines get the same bits ↗  ·  More writing ↗