Part III Chapter 13

Inside the network: activations, PCA and probes

Contents
  1. Activations
  2. Principal components
  3. Probes
  4. What the activations can’t tell

Chapter 12 read the network’s outputs and arrived at a hypothesis: the network reads the Hamming weights of the two shares, roughly at first, which is enough to tell high from low, and exactly after the jump, which is what parity needs. If that is right, the two weights must be somewhere inside the network. This chapter looks for them in its activations.

Activations

Chapter 7 followed a trace through the network layer by layer: each neuron multiplies, adds, and bends, and passes one number on. The numbers a layer produces for one trace are its activations. The network here has four hidden layers of 40 neurons, so each layer turns every trace into 40 numbers, which we can treat as a point in a space with 40 directions.

If a layer keeps track of some value, say the weight of the mask, there should be a direction in that space along which the points move as the value changes: traces with a light mask on one side, traces with a heavy mask on the other. That a layer stores a value as a direction is an assumption, not a law, but it holds often enough in trained networks that interpretability work starts from it. A value stored this way is called a feature.

Principal components

Forty directions can’t be drawn. Principal component analysis (PCA) finds the few that matter most: the first principal component is the direction along which the points spread the most, the second is the one with the most spread among those at right angles to the first, and so on. Drawing the points on the first two shows as much of the cloud’s spread as any flat picture can.

The spread a network bothers to create is usually spread it uses, so the first components tend to carry its main features. For side-channel networks the paper expects few of them, since a trace only leaks a handful of values, and finds its structure within the first four components.

The widget shows the first layer’s activations for 600 test traces at each epoch, drawn on their first two principal components. The components found at one epoch can point any way compared with those of the next, so each epoch’s picture is turned, and flipped if needed, to line up as well as possible with the last epoch’s; what moves is what the network changed. Start with the colour by mask weight, then by share weight. Only the simulation can do this; on a real chip nobody knows the mask of each trace.

colour by
First-layer activations on the first two principal componentsPC 1PC 2

epoch 1 · perceived information 0.04 bits · the two components hold 27% of the layer's variation

Blue is weight 0, grey 4, red 8. The mask's weight changes along one direction of the plane, and the other share's along the other. Only the simulation knows these weights; on a real chip the paper had to work without them.

From the first epoch, one direction of the plane follows the weight of the mask and the other the weight of the masked share. Each of the two components correlates with one of the weights at 0.84 or more after epoch 1, 0.94 at epoch 8, and 0.97 at epoch 40. The first layer has learned to listen to the two leaking cycles before anything visible happens at the output.

What changes is how sharply. The two components hold 27% of the layer’s variation after epoch 1, 37% at epoch 8, and 59% at epoch 40: more and more of what the layer computes is about the two weights. Turn on the averages: each dot is the average position of the traces with one pair of share weights, and together they form a grid, one axis per share. Through training the grid spreads out compared with the scatter of single traces around each dot: the spacing between neighbouring dots is 1.6 times that scatter after epoch 1, 2.5 times at epoch 8, and 3.2 times at epoch 40. Neighbouring pairs of weights overlap less and less.

Now colour by high or low. On the averages, low labels line one diagonal of the grid and high labels the other, like the table of Chapter 12; that is the pattern the paper found in CHES_CTF’s first layer. Colour by even or odd and the averages form the checkerboard. In the single traces it is much harder to make out, because the traces with rare weights at the edge of the grid are few, and in the crowded middle the clouds of neighbouring pairs still overlap.

Probes

Pictures can mislead, so the paper also measures. A probe is a small classifier, here a single layer like the network’s last one, trained to read one value from a layer’s activations. If it reads the value well on traces it wasn’t trained on, the layer holds that value in a form a straight cut can separate. We train one probe per epoch for each question, on 5,000 training traces, and score it on the 5,000 test traces.

What linear probes can read from the network, epoch by epochjump0.50.60.70.80.9110203040epochprobe accuracy on test tracesshares, layer 1parity, last layerparity, layer 1
Accuracy of linear probes trained on the network’s activations at every epoch, scored on 5,000 test traces. Blue: reading the exact Hamming weight of each share from the first layer (average of the two shares); dashed, the same probe on the raw trace. Red: reading whether the label is even or odd, from the last hidden layer (solid) and from the first layer (dashed). 0.5 is a coin toss for parity. Shaded: the jump.

Three things show.

The first layer reads the shares early. From the first layer, a probe gets the exact weight of each share right on 69% of the test traces after epoch 1, and on 81% by epoch 4. During the plateau that number barely moves, 82% at epoch 8. Through the jump it climbs to 86%, which is about the most possible here: a probe on the raw trace, with nothing in between, gets 87%. The noise sets the limit, not the network.

Parity appears deep, at the jump. A probe asking whether the label is even or odd gets nothing from the last hidden layer until epoch 6: 50%, the score of a coin. Then it climbs with the jump: 54% at epoch 8, 60% at 10, 72% at 13, 79% by the end. From the first layer, the same question never gets above 55%. The first layer holds the two weights; turning them into parity takes the layers after it.

The two sharpen together. The reading of the shares improves most in the same epochs in which parity appears. That fits the two-piece picture of Chapter 11: exact readings are only worth something once parity is being computed from them, and computing parity only pays off once the readings are exact.

One caution about timing: the probe on the last layer doesn’t see parity before the network’s own output does. The network’s answers get parity right 53% of the time at epoch 8 and 56% at epoch 10, close to the probe. In this network nothing hides inside ahead of the output.

What the activations can’t tell

A probe that reads a value shows the value is there. It doesn’t show the network uses it. The raw trace holds the weight of the mask too, readable by a probe 87% of the time, and nobody would say the trace computes anything with it. A network could carry a feature it never relies on, and an unused direction would look exactly like a used one in the widget.

The way to tell is to intervene: change the feature inside the network while it runs, and see whether the output changes the way the hypothesis predicts. If the network really reads the two weights and combines them, fixing one of them at 0 should make its output report the other one alone. That is activation patching, the subject of Chapter 14 and the paper’s tool for proving it, and for pulling the masks out of the network along the way.