Part III Chapter 11

Learning in jumps

Contents
  1. A masked chip we can see inside
  2. The same network on two chips
  3. Watch it happen
  4. Why it waits
  5. Not only side-channel
  6. What a jump is, and what it isn’t
  7. What changed?

Chapter 10 ended on a curve that doesn’t improve steadily. The paper’s CHES_CTF network creeps up to about 0.08 bits per trace, stays there for nearly 40 epochs, and then, between epochs 77 and 85, climbs to 0.7. Something happened in those few epochs, and the rest of this guide is about finding out what.

On a real chip that is hard to start with: the masks are unknown, the traces are long, and every check needs the checkpoints of a large network. So this part of the guide works on a chip where everything is known, because we simulate it. This chapter builds it, trains a network on it, and shows the same plateau and jump. The next three open that network up.

A masked chip we can see inside

The chip is the one from Chapter 6, with its masked mode: 60 samples per trace, six clock cycles, and a current pulse in each cycle whose height depends on the Hamming weight of the byte the chip handles then. In the second cycle it handles the mask m, in the fourth the masked share Sbox[p ⊕ k] ⊕ m, and in the others unrelated random bytes. The label is the Hamming weight of Sbox[p ⊕ k], which never appears in the trace. For the network to have a fair chance, the noise is lower than in Chapter 6 (0.3 instead of 0.5) and there are 50,000 training traces, plus 5,000 for testing.

The network and its training are the paper’s CHES_CTF settings: four layers of 40 neurons, Adam with a step of 0.0025, batches of 400, and the small weight penalty of Chapter 8. Everything runs in numpy from fixed seeds, so every number below can be reproduced.

How much is there to learn? Chapter 6 showed that on a masked chip no sample leaks the label itself. Each share alone says nothing about it: the mask is random, so HW(m) is unrelated to HW(Sbox[p ⊕ k]), and so is the weight of the masked share. Computed exactly, either one gives 0 bits. Even both together don’t pin the label down. If the mask and the share both have weight 4, the value they combine to can have weight 0, 2, 4, 6 or 8, depending on how many of their 1 bits line up. Read perfectly, the two weights together give 1.15 of the label’s 2.54 bits. With noise, less.

The same network on two chips

Here is perceived information on the test traces after every epoch, first for the network trained on the unmasked chip, where the fourth cycle handles Sbox[p ⊕ k] itself, then for the masked one, trained five times from different random starting weights:

The same network on the unmasked and the masked chipunmasked chip012masked chip, five runs00.250.5110203040epochbits per test trace
Perceived information on 5,000 test traces after each epoch, for the paper’s CHES_CTF network and settings trained on the simulated chip. Top: the unmasked chip. Bottom: the masked chip, five runs from different random starting weights; the darker line is the run the widget below replays. The two panels have different scales.

Without the mask the network knows 1.89 bits per trace after the first epoch, and 2.1 a few epochs later. Nothing to wait for: one cycle carries the answer, and every step toward it pays off at once.

With the mask, every run follows the same three stages. Within the first few epochs the network finds a small amount, about 0.1 bits. Then it barely moves for several epochs. Then, within three or four epochs, it climbs to about 0.4 bits, and settles near 0.45. The jump comes between epochs 9 and 13 depending on the run. The plateau is shorter than CHES_CTF’s 40 epochs, but the shape is the same.

Watch it happen

The widget replays the first run, epoch by epoch. The top panel is its perceived information on training and test traces. The grid below shows what the network answers: each row collects the test traces of one true Hamming weight, and each cell is the average probability the network gives one label for them. Darker is more probability. A network that ignored its input would answer the same for every trace, and every row would look alike.

Perceived information, epoch by epochperceived information (bits per trace)00.250.50110203040trainingtest What the network answers, by true weightaverage probability per label012345678012345678true weightoutlined: each row's true weight

The first epochs: the network quickly picks up a small amount, about 0.08 bits per trace.

During the plateau the rows are nearly the same. Every row puts most of its probability, about 70%, on weights 3, 4 and 5, the most common ones, whatever the true weight of the trace. Perceived information creeps from 0.09 to 0.13 bits between epochs 4 and 10, then rises from 0.15 at epoch 11 to 0.40 at epoch 15. In those same epochs the rows pull apart: traces of different weights start getting different answers.

The attack of Chapter 9 follows. With a key byte fixed for the simulation, recovering it takes 308 traces at epoch 8, 201 at epoch 10, and 34 at epoch 15. The small amount from the plateau is real information: enough for a slow attack, not yet for a fast one.

The training curve stays just above the test curve the whole time. The network isn’t memorizing during the plateau and then generalizing; it learns nothing much on either set, and then learns on both.

Why it waits

Chapter 8 described training as many small nudges: each weight moves in the direction that lowers the loss right now, by an amount that grows with how much it would help. On the unmasked chip, any weight that reads the fourth cycle helps immediately, so learning starts on the first batch.

On the masked chip no single piece helps alone. A neuron that reads only the mask’s cycle learns nothing about the label, and neither does one that reads only the share’s. What helps is a combination: neurons that read both cycles in the right proportions, and later layers that use them the right way. While one part of that combination is missing, improving another part gains nothing, so the nudge it receives is close to zero. The parts only start to grow together once each is a little in place, and then each one’s growth speeds up the others’.

A model with just two numbers shows the effect. Say the gain is the product a × b, so it only appears when both are in place. The nudge to a is proportional to b, and the nudge to b to a. Compare it with a model of one number, whose nudge doesn’t depend on anything else:

One piece learns at once; two pieces wait, then jump00.5104812training timelearnedone piecetwo pieces0.10.010.001starting size
A two-number model of a plateau. Blue: one piece, whose nudge doesn’t depend on anything else. Red: two pieces whose gain is their product, started at 0.1, 0.01 and 0.001; the label marks where each is halfway.

The one-piece model learns at once. The two-piece model waits near zero, then rises in about the same short time whatever its start. Each time the starting size shrinks tenfold, the wait grows by the same amount: halfway at time 2.3 when each piece starts at 0.1, 4.7 at 0.01, 7.0 at 0.001. A real network has far more than two pieces, but the idea carries over: Saxe, McClelland and Ganguli worked out this behaviour exactly (opens in a new tab) for deep networks without activation functions, plateaus included.

The model also explains why the length of the plateau is hard to predict. It depends on how far from useful the starting weights happen to be, and on everything that changes the size of the nudges. Trained without the weight penalty, the same network on the same chip waited longer and less predictably in our runs: its jump came between epochs 11 and 20 depending on the seed, against 9 to 13 with it.

The small amount the network finds in its first epochs, before the plateau, is a different and easier piece. Chapter 12 shows what it is.

Not only side-channel

Learning in sudden steps after a long wait is known well beyond side-channel analysis. Power and colleagues called it grokking (opens in a new tab): small networks trained on modular arithmetic first memorize their training examples, then, long after, suddenly get the unseen ones right. Nanda and colleagues took such a network apart (opens in a new tab) and found that the general solution was being built inside it during the plateau, well before the test accuracy showed it. Chughtai, Chan and Nanda extended this (opens in a new tab) to networks learning group operations, and combining two shares with XOR is one. Michaud and colleagues proposed (opens in a new tab) that networks generally learn in discrete chunks, each acquired in a jump of its own.

On the side-channel side, Masure and colleagues observed an “initial plateau” (opens in a new tab) when training networks against masked implementations, before they suddenly generalize. The paper this guide follows starts from that link: if jumps are where a network acquires a new piece of its solution, the jumps are where to look.

Our chip differs from grokking in one way. Grokking networks memorize first, so their training accuracy is perfect long before the test accuracy moves. Here both curves wait together: with 50,000 traces, the network doesn’t memorize them.

What a jump is, and what it isn’t

A jump is a sharp rise in a few epochs between two flatter stretches. It is something the training curve does, and it says when to look. It doesn’t say what changed, and it doesn’t prove the network built any particular mechanism. Chapter 10’s dips are a warning too: a quick change in perceived information can come from the network’s confidence alone, so a jump is worth checking against the attack before reading anything into it. On this chip and on CHES_CTF the attack moves with it.

So far the jumps here were found by eye. Chapter 19 tries to find them automatically.

What changed?

At the jump, the rows of the widget’s grid pulled apart: the network started answering differently for traces of different weights. Which weights did it learn to tell apart, and why those first? Chapter 12 reads the network’s outputs to find out.