Part III Chapter 14

Proving it: activation patching

Contents
  1. Changing one thing
  2. Finding the axes with the labels only
  3. Pinning one axis
  4. Reading the masks out
  5. Which one is the mask
  6. Before the bend
  7. Epoch by epoch
  8. What patching can’t tell

Chapter 13 found the weights of the two shares in the first layer of the network on the masked chip. Finding them doesn’t show the network uses them: the raw trace holds them too. This chapter changes them inside the running network and watches the output. If it changes the way the hypothesis predicts, the network uses them. Along the way, the same experiment reads the weights of the masks out of the network, which is what the paper is after.

Changing one thing

Activation patching means running the network on a trace, stopping at some layer, changing some of that layer’s numbers, and letting the rest of the network run on the changed numbers. Everything downstream sees the change; nothing else is touched.

What to change comes from the hypothesis. The network reads the weights of the mask m and the masked share s, and combines them like the table of Chapter 12. Suppose the mask were 0: then x = m ⊕ s = s, and the weight of x would be the weight of s. If the mask were 0xFF, every bit of s would be flipped, and the weight of x would be 8 − HW(s). So if we could tell the network “the mask has weight 0” while leaving the trace alone, its output should follow the weight of the masked share alone. At weight 8, it should follow the same weight upside down.

We can’t change the mask on a chip, but we can change the place where the network keeps its weight.

Finding the axes with the labels only

In Chapter 13 the two weights lay along the two directions of a plane, and we could see which was which because the simulation knows every mask. On a real chip nobody does. What the attacker has is the labels, and the table: low labels where the two weights agree, high labels where they add up to 8.

That is enough to find the axes. We turn the plane step by step, and at each angle give every trace a weight along each axis, in the proportions in which random bytes have them: the lowest 1 in 256 traces along an axis get weight 0, the next 8 in 256 get weight 1, and so on. The table then says what label each trace should have, on average. We keep the angle at which these predictions best match the true labels.

On the toy network after training, the two axes found this way follow the weights of the two shares with a correlation of 0.97 or more each. What the labels can’t say is which axis is the mask, or which end of an axis is weight 0. Both come later.

Pinning one axis

To pin an axis, we move every trace along it to the same value, keep its position along everything else, and run the rest of the network. We do it to the layer’s numbers just before the bend from Chapter 7. The bend in this network, as in the paper’s networks for CHES_CTF and ESHARD, is the ReLU: it passes positive sums through unchanged and turns negative ones into 0. Why it matters which side of the bend we pin comes at the end.

The network mostly answers 3, 4 or 5, so its predictions alone say little. As in Chapter 12, we read its logits: the average logit of the high labels, 5 to 8, minus that of the low labels, 0 to 3. The widget shows this score at epoch 40 for the test traces, averaged over each pair of true share weights.

pin
The network's high-minus-low score for each pair of share weightstrue weight of the masked share, HW(s)012345678true weight of the mask, HW(m)012345678

correlation of the score with HW(m) +0.02, HW(s) +0.00, HW(x) +0.34

Nothing pinned. Red cells score high labels, blue cells low ones. The network follows neither share on its own, only their combination: the pattern of the high-or-low table from Chapter 12.

With nothing pinned, the score follows neither weight alone: its correlation with each is 0.0, and with the weight of x 0.34. The colours draw the high-or-low table. Pin either axis near one end and the pattern turns into stripes: the score now correlates 0.97 with the weight of the other share and not at all with the weight of x. Pin it at the other end and the stripes flip. Pin it near the middle, at weight 4, and the score follows nothing, as the table predicts: a share of weight 4 combined with any other share gives an x of average weight 4.

That is the prediction, met. The network computes its answer from these two directions, the way the table says.

Reading the masks out

Pinned at one end, the network’s score ranks the traces by the weight of the other share. The paper turns that ranking into weights the same way the axes were fitted: sort the traces by score, give the lowest 1 in 256 weight 0, the next 8 in 256 weight 1, and so on. This assumes the masks are uniformly random, which they have to be for the masking to be secure.

One question remains: which end of the ranking is weight 0. The labels can’t tell. A mask m with share s and the flipped pair, m ⊕ 0xFF with s ⊕ 0xFF, give the same x, so a reading and its mirror image 8 − w fit the labels equally well. The trace can tell: on this chip, as on most, more 1 bits draw more current. So we keep the orientation in which the reading rises with the trace where it leaks.

Share weights read by patching, against the truththe reading that leaks firstweight read by patchingtrue HW(m)012345678012345678exact for 88% of tracesthe reading that leaks secondweight read by patchingtrue HW(s)012345678012345678exact for 88% of traces
Weights of the two shares read out of the network on the masked chip at epoch 40 by patching, against the true weights, for the 5,000 test traces. Each row is one true weight, and its shade shows how the traces with that weight were read; the darker the cell, the larger the share of the row. Left: the reading that leaks first, against the weight of the mask. Right: the one that leaks second, against the masked share. The true weights are only used to draw this figure.

Both readings are exact for 88% of the test traces, and never off by more than one. The probes of Chapter 13 read the same weights from the same layer 86% of the time, and they were trained with the true masks. Patching needed only the labels, the table, and the assumption that the masks are uniform. Guessing at random in the right proportions would be exact 20% of the time.

Which one is the mask

The two readings are two sequences of weights, one per trace. Where in the trace each one leaks says what it is. The signal-to-noise ratio of Chapter 6 answers that, for any value we can attach to each trace:

Where each reading leakscycle 0cycle 1cycle 2cycle 3cycle 4cycle 50246810SNRsample of the simulated tracefirst readingsecond reading
Signal-to-noise ratio of the two readings along the 60 samples of the simulated trace, test traces, epoch 40. Each clock cycle is 10 samples; the chip handles the mask in cycle 1 and the masked share in cycle 3.

The first reading leaks in clock cycle 1 and nowhere else, the second in cycle 3. A masked implementation has to load or generate the mask before it can mask anything, so the reading that leaks first is the mask. Here the simulation confirms it. On CHES_CTF the paper finds the same order: a reading that leaks early, as the mask is loaded and prepared, and another that leaks later, where the masked S-box output is computed.

Before the bend

Pinning the layer after its ReLU, on the plane Chapter 13 drew, mostly fails: the readings are exact for only 38% of traces. The reason is the bend itself. After the jump, the third and fourth principal components of the layer’s output are bent copies of the two weights: they measure how far a trace is from each diagonal of the table, |HW(m) − HW(s)| and |HW(m) + HW(s) − 8|. A straight line can’t read either weight from them, which is why Chapter 13’s probes found nothing outside the plane, but the two weights explain 88% of their variation. Pinning the plane leaves them as they were, so the rest of the network still sees the old weights through them.

The network needs those copies. Rebuild the layer from its first two components only and its perceived information falls from 0.45 bits to −0.40: its answers about parity become confidently wrong, and most of what it knew about high or low goes too. With four components it is whole again.

The authors’ code takes a third route: it rebuilds the layer from its first three principal components, pins them, and runs on. On this network that keeps one of the bent copies and reads 35% exactly. Rebuilding from two components reads 86%, because the ranking of traces by their high-minus-low score survives, but it reads it from a broken network. Pinning before the ReLU avoids the question: the layer’s numbers before the bend are a straight function of the trace, so the two weights live in the plane alone, and the bend then rebuilds its copies from the pinned values. It reads 88%, from a network that works.

Epoch by epoch

The same experiment runs on every saved epoch:

Reading the shares by patching, epoch by epochjump00.250.50.751110203040epochshare weights read exactlypatchingprobe, with masksafter the ReLU
Share of test traces whose share weights are read exactly, average of the two shares, at every epoch. Blue: patching before the ReLU, which uses only the labels. Dashed: the probes of Chapter 13, trained with the true masks. Red dashed: patching after the ReLU. Shaded: the jump.

Patching reads the shares from the first epoch on: 62% exact after one epoch, 80% at epoch 8 in the plateau, 88% after the jump. Throughout, it tracks the probes that needed the masks. The network uses the two weights from the start, for the high-or-low answer of Chapter 12, and the jump adds parity on top of readings it was already using. During the jump, at epoch 13, the reading dips to 80% for a moment while the layer reorganizes.

What patching can’t tell

Patching tests a hypothesis; it doesn’t produce one. It needed to know that the leakage follows Hamming weights, that there are two shares, and how two weights combine into the weight of x. All three came from outside the network, from what masking is. On a scheme with three shares, or a chip that leaks in another way, the axes, the table and the ranking would all have to change.

And this chip was built to be easy: the two shares leak in two clean cycles, with no other noise source. The next part of the guide runs the same steps on the real chips, starting with ESHARD, where the masks are published so the readings can be checked.