Exponential Tilt
Applying information theory in the real world.
Doppel recently dropped a little puzzle, in their challenge for 3Blue1Brown's audience, that takes information-theoretic concepts and applies them to a real world use case. This puzzle is a detection problem where you, as a member of a cracked security team, are tasked with building an adversarial understanding of a lightweight detector that was built for identifying phishing attempts.
Here is the problem in its entirety:
Setup. You're a cracked security team defending your users against a known phisher. Each day, the two of you are locked in a cat-and-mouse fight. The attacker sends a phishing campaign and chooses how often to use each of persuasive phrases in their messages — things like "urgent", "verify account", "free gift", "security alert", "payroll".
The attacker selects a distribution over phrases , where .
Each phrase has an intrinsic social-engineering payoff : if a message using reaches a user unflagged, it succeeds with probability . If the message is flagged or fails to convince, payoff .
Your detector. You don't have the bandwidth to inspect every message perfectly — these phrases appear innocently in normal traffic too. Instead, you run a lightweight detector that monitors phrase frequencies. Given a baseline distribution representing natural phrase frequencies, you raise an alarm when:
for some constant . (You might recognize this quantity.)
The question. What distribution should the attacker choose to maximize their expected payoff?
Hint: the optimal strategy isn't deterministic.
I am going to walk through the best way to solve this puzzle with some callouts to resources in areas that I have struggled with in the past. As a little teaser, we will work together to find out that the optimal attack is neither mimicking normal traffic nor betting everything on the highest payoff phrase. We are going to see that exponentially tilting our baseline towards more effective phrases, using KL divergence as our measure of budget, is the best way to maximize the attacker’s payoff.
As a quick note, this problem only requires you to know KL Divergence and one technique from multivariable calc, both of which I touch on below.
This problem states that we need to put ourselves in the mind of the attacker. We need to come up with a distribution, , that maximizes our expected payoff. But what does that mean in practice?
Really we are just looking for
But actually converting this into something we can use will require us to pull apart and put back together the expression just a little bit.
The Detector
Looking closer at the detector
it becomes apparent that we can break this into two more familiar parts
This small change on its own may not look like a lot, but what does it remind you of?
If you were thinking, this looks suspiciously like KL divergence, , it's because it is!
The first term is cross-entropy . This is measuring the average cost of encoding messages from using 's codebook.
The second term is Shannon entropy, , or the cost of encoding those same messages using the best possible encoding for .
So the full expression is measuring the difference between the two. We are capturing the excess cost the attacker pays for messages drawn according to when using a code optimized for .
Since we know the detector will alert when , we have an upper limit on how far we can push before going over. Now we can rewrite our goal in clearer terms as
And even more clearly as because, in the relevant non-deterministic regime, the optimal solution uses the entire KL budget. Therefore the fully constrained problem becomes
interactive figure 01
The price of the wrong codebook
D(p ‖ q) = H(p, q) − H(p)
width = how often p uses the phrase
height = −log₂qᵢ bits under q’s codebook
same messages, two average bills
each color is one phrase’s contributionMaximizing Payoff
Now that we know what we are optimizing against, it becomes much easier to attack the problem. Put in plain language, we need to find the best distribution, , that allows us to maximize our payoff from the function when has a KL divergence budget of .
This is where the other technique we talked about earlier comes into play!
We can incorporate our constraints into a Lagrangian
where and , and we assume and .
From there we just need to differentiate with respect to and set it equal to 0
The stationarity condition requires for every to help us find candidates for the maximum. At the optimum, no infinitesimally small changes in can improve the constrained payoff, so every partial derivative of the Lagrangian we have put together must be 0. By setting the partial derivative equal to 0, we can satisfy the stationarity condition and continue on our way by solving for .
This is the part that tripped me up when solving it myself so I'll take this next bit slow. We need to now normalize our equation to find . To do that means taking what we have and putting it over the sum of all our messages, .
You may be asking yourself, "what happened to the term from the previous equation?" The truth is that after normalization, constants are factored out. The is independent of and appears in every numerator weight and their sum, so it cancels out.
But dividing by is not that pretty, so we can make some effort to make this more readable by re-parameterizing . This actually makes the interpretation easier as well. If we assume that the KL constraint is active (which is needed in this non-deterministic regime), and that payoffs are not identical (this is where intuition comes in), then .
We have found the shape of the solution but haven't quite finished yet. This is the family of candidate distributions that we need to narrow down to find the best possible candidate. Different values of will produce different distributions:
- When , we are effectively saying that . If this is true then every attack would slide under the detector, but we wouldn't have found the maximum possible payouts.
- As gets larger, more probability shifts towards phrases with higher payoff . However, we cannot increase forever or else we risk over-spending our KL budget, .
interactive figure 02
The aggression dial
pᵢ(β) = qᵢeβsᵢ / Z(β)
KL budget · bits
DKL(p(β) ‖ q) = 0.260 bitsalarm: off
β* spends the full budget without crossing it
Because KL divergence increases with , we solve the scalar equation at exactly the point we run out of budget. To get the exact right level, we can do this by looking for such that
That's where the unique will result in our final solution . Incorporated into the equation
Where is selected so that
What this Equation Represents
Now that we have this cool equation, what the heck does it mean? In this section, I am going to break down each variable within the equation as it relates to our original problem and explain what happens when you tweak it.
is the optimal probability for phrase and the collection of all results in the distribution of phrases. It can be thought of as the perfect balance between resembling ordinary traffic and favoring useful phrases (those with high payoffs, ).
is the frequency that a phrase typically appears according to our baseline . It is how often the phrase typically appears in a regular stream of messages.
is the success probability for the use of a phrase in a message.
is the same as and is the "aggression dial" for the whole distribution. When is 0, which means the distribution looks exactly like normal traffic. Great for hiding your attacks, but not the best you can do when it comes to achieving high payoffs.
interactive figure 03
Why the dial stops
payoff + DKL bits over β
We can put together two variables (, ) to get the factor that rewards more effective phrases. This looks like .
— Adding in allows us to multiply our baseline probability by those payoff preferences. This is the exponential tilt where this type of equation gets its name from. Among all distributions with limited KL divergence from , the exponential tilt is the most efficient way to increase expected payoff. We are effectively spending the budget on favoring high-value phrases.
is our normalization constant that gets all the probabilities in the distribution to sum to 1.
is the constant that sets the whole thing in motion. In other words, it is the detectability budget our attacker can use to maximize their payoff.
What This Means for Defenders Like Doppel
While attackers can manipulate for any of their phrases, , there are only three levers that defenders can control, , , and within this toy model. In this section, we will walk through each and talk about the costs of Type I and Type II errors.
is our modeled expectations for how often we will see any of the loaded phrases from in regular, benign traffic. A naive approach to building is to sample how often each phrase in occurs within your current dataset.
A slightly less naive approach curates the dataset by filtering out all the phishing attempts that likely already exist within it (shout out to data labelers who do this kind of thankless work day in and day out!) This results in a clean model of how often those phrases should appear.
This assumes we have a good handle on most of . If we never think to add in a phrase , (in other words ) our detector could never trigger and attackers will just hammer that phrase until they succeed in their goal.
As defenders, we can adjust the for any individual phrase in hopes of more quickly catching divergences that arise from the distribution we will see in production. We can also adjust all of by calibrating our dataset, smoothing, additional labeling, or selecting new/better datasets. By appropriately setting , we can effectively shape the attacker’s optimal response to catch bad actors and estimate the that we will see. But this comes at a cost (more on this in a moment). A good intuition for the effects of manipulating is that setting means that any instance of will trigger the alert (KL divergence would be infinite and always past the threshold of .) It is probably good to note here that the whole of still sums to 1, so lowering moves the center of the KL ball, essentially making phrase more anomalous. It in effect shifts sensitivity for that phrase.
We can also manipulate , or the amount of divergence we allow before we trigger an alert on a given distribution. Lowering the constant makes us more sensitive to perturbations in the distributions, effectively shrinking the attacker’s maximum achievable expected payoff by limiting the attacker's KL divergence budget. However, this comes at the same cost as many forms of adjusting .
Taking benign traffic as the null hypothesis, making the detector more sensitive (e.g., lowering or lowering ) will catch a lot more attacks, but it comes at the cost of increased Type I errors. All those false positives result in an annoying experience for our end users and complaints pointed at the defenders.
Making the detector less sensitive (leaving as is, raising ) would stop many of those false positives from happening, but more true positives would sneak by as false negatives. These kinds of errors can be catastrophic, so many defenders resolve to a more risk-averse position that is overly sensitive but mostly avoids Type II errors.
A real-world example of this is the heat Anthropic is catching from their strict cyber and bio safeguards. Even in something as innocuous as this essay (in which I had asked Claude Fable to check my notations), I triggered the safeguards multiple times. This tradeoff is at the heart of most threshold-based detection software no matter the sophistication. It appears in everything from lightweight detectors like this problem to ML and DL-based classifiers with millions to billions or trillions of parameters.
interactive figure 04
C is the control knob
lower C → more sensitive
Type I · benign traffic flagged
Type II · attacks that slip through