Part III Chapter 12
Reading the outputs: logits
Contents
At the jump of Chapter 11, the rows of the widget’s grid pulled apart: the network on the masked chip started answering differently for traces of different weights. This chapter finds out which weights it learned to tell apart. It only looks at what the network outputs, the way the paper starts on a real chip, where nothing else is known.
Scores, not probabilities
The probabilities aren’t the best place to look. Weights 3, 4 and 5 cover 71% of all bytes, so for almost every trace the network puts most of its probability there, and whatever it learned hides in small differences among the rest.
The scores before the softmax show those differences better. Chapter 7 introduced them: the last layer gives one raw score per label, and the softmax turns the scores into probabilities by taking e to the power of each score and dividing by the total. These scores are called logits.
Adding the same number to every logit of a trace changes nothing:
logits 2.0 0.5 −1.0 → probabilities 0.79 0.18 0.04
add 3 to each 5.0 3.5 2.0 → probabilities 0.79 0.18 0.04
Each e to the power of a score gets multiplied by the same factor, and the factor cancels in the division. So a logit means nothing on its own; only the differences between a trace’s logits count. Before comparing traces, we subtract from each trace’s logits their average.
One more subtraction removes the common labels’ head start. A label like 4 gets high logits on every trace simply because it is common. Subtracting each label’s average over all traces leaves what we want: how much more, or less, the network scores each label for one group of traces than for traces in general.
Before and after the jump
Group the 5,000 test traces by their true Hamming weight, and average the logits in each group, with both subtractions. Each row below is one group; each column is one label. Blue means the network scores that label higher than usual for that group, red lower.
At epoch 8, in the plateau, the grid shades from one corner to the other. Traces of low weight raise the low labels and lower the high ones; traces of high weight do the opposite. The network can tell roughly whether a trace’s weight is high or low, and nothing more: within that trend, a trace of weight 3 and one of weight 4 look much the same.
At epoch 40, after the jump, a checkerboard sits on top of that trend. Traces of odd weight raise the odd labels, and traces of even weight the even ones. Averaged over rows 1 to 7, the network now scores labels of the trace’s own parity 1.0 higher than the others. At epoch 8 that difference was 0.01.
So the network learned two things, at two different times: whether the weight is high or low, then whether it is even or odd.
Measuring each one
Perceived information can be split along the same lines. Add up the network’s probabilities for weights 0 to 3 and for 5 to 8, and score that pair of numbers against whether each trace’s weight is high or low; that is the information about high versus low. The same with the even and the odd labels gives the information about parity.
The information about high versus low is 0.07 bits after the first epoch and 0.10 by epoch 8, almost all it will ever reach. The information about parity is zero until epoch 8 and rises to 0.28 bits by epoch 15. The small amount Chapter 11 saw before the plateau is the high-versus-low distinction. The jump is parity arriving.
Why these two
The label is the Hamming weight of x = Sbox[p ⊕ k]. On the masked chip, x is never handled; the chip handles the mask m and the masked share s = x ⊕ m, and leaks their Hamming weights. If the network reads those two weights, what can it say about the weight of x?
The paper answers with a table, in its appendix H, and the widget rebuilds it from all 65,536 pairs of bytes m and s. Each cell is one pair of weights. Click a cell to see which weights of x it allows, and switch between the three views.
Two patterns stand out.
High or low. Where the two weights are equal, the bits of m and s mostly overlap, they cancel in the XOR, and x has a low weight: weight 0 is only possible on that diagonal. Where the two weights add up to 8, the bits mostly miss each other, and x has a high weight. A pair like HW(m) = 4, HW(s) = 4 allows 0, 2, 4, 6 or 8, but HW(m) = 1, HW(s) = 7 allows only 6 or 8. This pattern is forgiving: read either weight one off, and the cell moves to a neighbour with nearly the same average.
Even or odd. HW(x) always has the same parity as HW(m) + HW(s). Every bit where both m and s are 1 counts twice in the sum and zero times in x; every other 1 bit counts once in both. So the sum and HW(x) differ by twice the number of shared bits, an even number. The rule never fails, but it isn’t forgiving: read either weight one off, and the predicted parity is wrong.
That is why high-versus-low comes first. A rough reading of the two weights already gives it, and rough readings are what the first layer gets as soon as it starts listening to the two leaking cycles. Parity needs both weights read exactly, and a mechanism that combines them exactly. Neither helps much without the other, which is the two-piece situation of Chapter 11. Chapter 13 looks at how sharp the network’s reading of the weights is, epoch by epoch.
On the real chips
The paper reads CHES_CTF the same way. After its first, slow increase, which ends around epoch 40, the logits separate high from low weights. After the jump at epochs 77 to 85, they also separate even from odd. ESHARD, with its single jump at epoch 4, only ever separates high from low; the paper reports that its network never tells even from odd. Our toy network compresses CHES_CTF’s first stage into its first few epochs, but goes through the same two steps in the same order. Chapter 15 and Chapter 16 check both chips against their published checkpoints.
What the logits can’t tell
The logits say what the network distinguishes, not how. The step from “it separates high from low, then even from odd” to “it reads the Hamming weights of the two shares” is a hypothesis, and it came from outside the network: from knowing that the chip uses a mask split into two shares, and from the table. On a different scheme, the same logits would call for a different table.
They also don’t say where the distinction lives. If the network reads two weights, those readings must exist somewhere among its 160 hidden neurons. The next chapter goes looking for them.