Proving Mercurial CPU Cores Offline

Can you prove a Silent Data Corruption (SDC) was caused by a faulty CPU, without having the faulty machine?

Background

A few months ago I wrote about a CPU instruction that lied on the Rubrik engineering blog.

For over a year, AES-GCM encryption in our storage engine occasionally produced a wrong auth tag. The culprit was a single cloud VM whose PCLMULQDQ instruction (the carry-less multiply behind GHASH) sometimes returned one extra bit. A carry-less multiplication producing a ghost carry like:

Operand A     : 0xc57ded290fecde69b4c724259c54dcf0
Operand B     : 0xf7db6ff66057b68c9b60371f02762cc4
Expected      : 0x556f27e77e03aa93a418d6d4672077c0
Actual        : 0x556f27e77e03ab93a418d6d4672077c0

Because the fault was inside GHASH, only the auth tag came out wrong. The ciphertext itself was fine (see the original blog for more details on data recovery).

Plaintext AES-CTR Ciphertext ✓ GHASH ×H ×H ×H Tag ✗ one bit flipped
The fault hit one multiply inside GHASH. Every later multiply carried the error into the tag. Encryption never goes through GHASH, so the ciphertext stayed correct.

Often we would see the effects of the corruption long after it happened; it was truly silent, especially in the early days. By then the machine was often gone: twice, the cloud provider recycled a suspect node before we could cordon it. So after root-causing and recovering all the data, I wanted to explore if it’s possible to attribute a Silent Data Corruption to a faulty CPU without actually capturing the machine.

It turns out you often can, and with a level of certainty that’s hard to argue with.

This experiment was done as part of my work at Rubrik; views are my own.

Mercurial cores

Google calls these mercurial cores: CPU cores that, for some instructions and some inputs, silently compute the wrong answer. Meta has reported the same phenomenon at fleet scale. They don’t crash. They don’t fail standard stress tests. They just occasionally lie.

In a cloud environment like AKS, at a large scale, your system would be running on several different machines, increasing the likelihood of encountering a mercurial core. It’s not a matter of if, but when.

The idea

If we emulate how a CPU executes a program (i.e., emulate the underlying assembly code), and then inject the right fault at the right time, we can reproduce the corrupted output. So the problem becomes a brute force search problem.

We can do it like this:

  1. Take the exact instruction sequence that produced the output (AES-GCM here).
  2. Run it in an emulator where you control every instruction’s result.
  3. Define a set of plausible hardware faults — bit flips, word corruptions, stuck bits, on inputs, outputs, or specific registers.
  4. Inject each fault, one at a time, at every instruction, and check whether the emulated output matches the corrupted output exactly.
observed
emulated

1. Pick an instruction to fault

2. Where

Each choice is one candidate fault. The emulator re-runs the encryption with that fault and compares the tag it gets with the one the faulty machine produced. Digits in brick don't match.

If some fault reproduces the corrupted output bit-for-bit, you have a concrete, checkable explanation: instruction N, executing PCLMULQDQ, returned its result with bit 72 flipped. If the search space is reasonable and the output is large enough, the chance of that happening by coincidence is essentially zero. More on that below.

Crypto code makes this unusually tractable. Constant-time implementations have no data-dependent branches, so the instruction trace for a given input length is fixed. Every input of that length runs the same straight-line sequence, and “inject a fault at step N” is well defined.

The setup

I had some leftover samples from the original investigation: a set of synthetic inputs we had encrypted on the faulty node, along with the corrupted outputs it produced.

Extracting the code

The first step was getting the exact instructions our AES-GCM path executed in production.

I had Claude pull the relevant assembly out of our production binaries — the AES-NI rounds, the GHASH multiply-and-reduce sequence, and the glue around them.

It’s important this is the actual code that ran, not a reference implementation; a different but equivalent implementation would have a different fault surface.

The emulator

I wrote a small emulator in Go. It’s very much makeshift: it only implements the instructions this code path needs — the SSE/AVX moves and shuffles, XORs and shifts, AESENC/AESENCLAST, and PCLMULQDQ — operating on a register file and a bit of memory.

The one design decision that mattered: every instruction goes through a hook that can corrupt its operands or result. Roughly:

// Illustrative, not the actual code.
type Fault struct {
	Step    int        // which executed instruction
	Site    Site       // Src1, Src2, Dst, or a specific register
	Pattern Corruption // BitFlip, ByteFlip, WordFlip, StuckAt0, StuckAt1, ...
	Index   int        // which bit / byte / word
}

func (m *Machine) step(i int, inst Inst, f *Fault) {
	if f != nil && f.Step == i && f.Site.IsInput() {
		m.corrupt(inst, f)
	}
	m.exec(inst)
	if f != nil && f.Step == i && f.Site.IsOutput() {
		m.corrupt(inst, f)
	}
}

Before trusting it, I checked it against Go’s crypto/aes + crypto/cipher on many random inputs: with no fault injected, the emulator’s ciphertext and tag must match bit-for-bit.

Fault models

At the time I was also chasing a different bug, so I built the emulator to support many kinds of corruption rather than just single bit flips: corruption of an instruction’s inputs, its output, or a specific register; and patterns like single-bit flips, whole-word flips, and others.

Then brute force:

for _, f := range allFaults(trace, models) {
	out := emu.Run(trace, inputs, &f)
	if bytes.Equal(out, corrupted) {
		matches = append(matches, f)
	}
}

It’s embarrassingly parallel and cacheable (every candidate shares the same run up to its faulty step), so you can brute force far more faults than you’d expect.

The result

It reproduced the corrupted outputs exactly.

For every sample, the search landed on the same fault: a single PCLMULQDQ in the GHASH multiply, returning its result with bit 72 set. That’s the same ghost carry from the example above. Nothing else matched.

It took us over a year to pin this on one instruction. The emulator got there from the inputs and outputs alone.

How sure can you be?

Very sure, as long as the fault model is narrow.

Look at it from the skeptic’s side. Suppose the corruption was caused by something else entirely, like a software bug or a memory error. Then to any single candidate fault, the observed 128-bit tag is just a random number, with a 1 in 2¹²⁸ chance of matching. Even across 16 million candidates (2²⁴), the chance of a coincidental match is about 1 in 2¹⁰⁴. That’s less likely than winning the Powerball jackpot three times in a row.

How sure can you be? The details →

Why now: AI made this practical

None of this is a new idea. Fault injection in emulators is decades old. What’s changed is the cost.

Building a custom emulator for one production code path used to take weeks: extracting the right instructions, implementing each opcode exactly, adding fault models, and validating it all against a reference. For a bug that may never come back, that’s hard to justify.

With Claude, it took a couple of days. Claude extracted the assembly and wrote most of the opcodes and fault models, and I spent my time verifying it against Go’s crypto library. When throwaway tools get this cheap, a lot of ideas that weren’t worth the effort suddenly are.

Limits

  • You need the exact inputs. Key, nonce, AAD, plaintext, and the binary that ran.
  • One fault at a time. Multi-fault searches blow up fast (more on that with the other bug :p).
  • Only the faults you model. Anything outside your fault model goes unnoticed.
  • It doesn’t identify the host. You still need logs to know which machine it was.

Conclusion

Silent data corruption is painful to debug because by the time you notice it, the faulty machine is usually gone. But a faulty CPU gets a specific instruction wrong in a specific way, and that leaves a fingerprint in the output. With the exact inputs and a small emulator, you can find that fingerprint without the machine.

So next time you hit a corruption you can’t explain, hold on to the inputs and the bad output before writing it off as a cosmic ray. You might be able to prove what actually happened.

This methodology and emulator also helped me catch another mercurial core causing SDC: the different bug I mentioned earlier. More on that in a future post.