Definitionresearch
g-leakage
Also called gain function leakage.
Generalizes min-entropy leakage with a gain function that scores each guess, to model attackers who profit from partial or several guesses.
g-leakage measures how much a channel helps an attacker whose payoff is not just "right or wrong in one guess". A gain function says how much the attacker earns by guessing when the secret is , so it can model an attacker who wins by guessing a value close to the secret, a property of the secret, or the secret within tries. The leakage is the base-2 log of the ratio of the best expected gain after and before seeing the output. Alvim, Chatzikokolakis, Palamidessi and Smith defined it in 2012. Min-entropy leakage is the special case where only an exact guess earns anything.
Definition
Secret, prior and channel. As for min-entropy leakage: a secret in a finite set with prior , and a channel matrix with from to a finite set of outputs.
Gain function. A finite nonempty set of allowed guesses and a function . The guesses need not be secrets. Alvim et al. rule out gain functions for which some secret earns 0 under every guess, so that for every prior.
Adversary. The attacker knows , and , sees one output , and picks one guess as any function of . The payoff is , and the attacker maximizes its expectation. Nothing outside is observed.
g-vulnerability and g-leakage.
The g-capacity is . As on the other QIF pages, the logarithms are base 2 and the unit is the bit.
Standard gain functions.
- Identity gain. and if , else 0. Then and the g-leakage is the min-entropy leakage (their Proposition 3.1).
- Metric gain. For a metric on normalized to , . A guess close to the secret earns almost as much as the exact secret.
- Binary gain. Each guess is a set and earns 1 when . With the blocks of a partition as guesses, the attacker wants to learn which block holds the secret. With all sets of at most secrets, is the chance to find the secret within tries.
Computation. With secrets, outputs and guesses, the g-leakage costs arithmetic operations:
G-LEAKAGE(π, C, g)- 1
V0 ← max over w of Σ_x π[x] · g(w, x) - 2
V1 ← 0 - 3
for each output y do - 4
V1 ← V1 + max over w of Σ_x π[x] · C[x, y] · g(w, x) - 5
return log2(V1 / V0)
The Python implementation uses fractions.Fraction and takes the logarithm only at the end. Its tests check the examples below, compare with an enumeration of all maps from outputs to guesses on 600 random cases, and check the Miracle bound on a grid of priors. The -tries gain is built from the sets of exactly secrets; for this gives the same vulnerability as sets of at most , because a larger set never earns less.
Basic facts. Each is a theorem from Alvim et al. (2012).
- Best strategy. is the largest expected gain over all strategies , by the same argument as for min-entropy leakage. A random strategy does no better, since the expected gain is linear in the strategy.
- Never negative (Theorem 4.1). : the attacker can ignore and play the best prior guess. So .
- Zero leakage (Theorem 4.2). if and only if one guess maximizes for every output at once.
- Miracle theorem (Theorem 5.1). For every channel and every gain function , . The proof replaces by inside the sum and pulls it out. So the min-capacity bounds the leakage for every attacker of this form and every prior. As a corollary, allowing tries cannot raise the capacity above the one-try capacity (Corollary 5.2).
- Composition (Theorem 6.2). If for some channel , so that is followed by further processing, then for every prior and every gain function.
Examples and non-examples
Example: a near pair of secrets. This is Example 4 of Alvim et al. Take three secrets, the uniform prior and the channel
| 1/2 | 1/2 | |
| 1 | 0 | |
| 0 | 1 |
with the metric gain where and are at distance and every other pair of distinct secrets is at distance 1: so , , and the other gains are 0. The best prior guess is or , with . After seeing the output, , so bits. The min-entropy leakage of the same channel is 1 bit, about 70 times more. The output separates from , which matters to a one-guess attacker but hardly to one who is paid for being close.
Example: g-leakage above min-entropy leakage. This is Example 5 of Alvim et al. Take the prior and the channel with rows , and . The best single guess is for both outputs, so the min-entropy leakage is 0. With the gain of the previous example, and , so bits. With the partition gain for the blocks and , and bits. So neither leakage bounds the other for a fixed prior; only the capacities are ordered.
Example: two tries at the last two bits. Let be uniform on and let the program output . With the 2-tries gain, . Each output leaves two secrets and the attacker tries both, so and bits, the same as the one-try min-entropy leakage. The attacker's success rises from to certainty.
Non-example: the happy gain. One guess that earns 1 for every secret gives , so every channel has g-leakage 0. The attacker already has all it wants, so the measure says nothing about the channel.
Non-example: a gain that is 0 on the support. If for every and every with , then and the ratio is undefined. Alvim et al. exclude such gain functions; the implementation states as a precondition.
Non-example: a change of scale. A gain with values in instead of is not a new measure: it multiplies both vulnerabilities by , so the g-leakage does not change. Alvim et al. note this in a footnote to Definition 3.2.
Related definitions
- Min-entropy leakage. The identity gain. Every result on this page applies to it.
- Min-capacity bound. The theorem , which the Miracle theorem uses as the bound for every gain function.
- Shannon leakage and channel capacity. The Shannon leakage is the mutual information , built from Shannon entropy. Theorem 5.3 of Alvim et al. shows that the Shannon capacity is at most the min-capacity; its proof uses Jensen's inequality.
- Additive g-leakage. . Alvim et al. (2014) study its capacities next to those of the multiplicative form on this page.
- Loss functions. A gain function is a bounded payoff in the sense of decision theory, and the attacker picks the guess of the largest expected payoff. A loss function is the same idea with the sign turned around.
- Quantitative information flow. The field that compares these measures.
Code
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/g-leakage/. The authors are listed in prov/XKQ40D.jsonl.
import itertools
import math
from collections.abc import Sequence
from fractions import Fraction
Prior = Sequence[Fraction]
Channel = Sequence[Sequence[Fraction]]
Gain = Sequence[Sequence[Fraction]] # gain[w][x] for guess w and secret x
def g_vulnerability(pi: Prior, gain: Gain) -> Fraction:
"""V_g(pi) = max_w sum_x pi[x] gain[w][x]. Cost: O(|W| |X|)."""
return max(sum(pi[x] * row[x] for x in range(len(pi))) for row in gain)
def posterior_g_vulnerability(pi: Prior, c: Channel, gain: Gain) -> Fraction:
"""V_g(pi, C) = sum_y max_w sum_x pi[x] C[x][y] gain[w][x]. Cost: O(|Y| |W| |X|)."""
total = Fraction(0)
for y in range(len(c[0])):
total += max(sum(pi[x] * c[x][y] * row[x] for x in range(len(pi))) for row in gain)
return total
def g_leakage(pi: Prior, c: Channel, gain: Gain) -> float:
"""g-leakage L_g(pi, C) = log2(V_g(pi, C) / V_g(pi)) in bits.
Precondition: pi is a distribution on the secrets 0..|X|-1, each row of c
sums to 1, every gain value is in [0, 1], and V_g(pi) > 0. Cost: O(|Y| |W| |X|)
exact arithmetic operations for |W| guesses.
"""
vg0 = max(sum(pi[x] * row[x] for x in range(len(pi))) for row in gain) # @line L1
vg1 = Fraction(0) # @line L2
for y in range(len(c[0])): # @line L3
vg1 += max(sum(pi[x] * c[x][y] * row[x] for x in range(len(pi))) for row in gain) # @line L4
return math.log2(vg1 / vg0) # @line L5
def identity_gain(n: int) -> list[list[Fraction]]:
"""The gain of one exact guess: 1 when w = x, else 0. It gives min-entropy leakage."""
return [[Fraction(int(w == x)) for x in range(n)] for w in range(n)]
def k_tries_gain(n: int, k: int) -> list[list[Fraction]]:
"""The gain of k guesses: one guess per set of k secrets, worth 1 when the secret is in the set."""
return [[Fraction(int(x in s)) for x in range(n)] for s in itertools.combinations(range(n), k)]
def partition_gain(blocks: Sequence[Sequence[int]], n: int) -> list[list[Fraction]]:
"""The gain of guessing the block of a partition that holds the secret."""
return [[Fraction(int(x in b)) for x in range(n)] for b in blocks]
test_g_leakage.py 147 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/g-leakage/. The authors are listed in prov/XKQ40D.jsonl.
import itertools
import math
import random
from fractions import Fraction as F
from g_leakage import (
g_leakage,
g_vulnerability,
identity_gain,
k_tries_gain,
partition_gain,
posterior_g_vulnerability,
)
def uniform(n):
return [F(1, n)] * n
def min_entropy_ratio(pi, c):
"""Min-entropy leakage ratio written out directly, without a gain function."""
post = sum(max(pi[x] * c[x][y] for x in range(len(pi))) for y in range(len(c[0])))
return post / max(pi)
def min_capacity_ratio(c):
return sum(max(row[y] for row in c) for y in range(len(c[0])))
def best_strategy(pi, c, gain):
"""Oracle: try every map from outputs to guesses and keep the best expected gain."""
ny, nw = len(c[0]), len(gain)
best = F(-1)
for choice in itertools.product(range(nw), repeat=ny):
val = sum(pi[x] * c[x][y] * gain[choice[y]][x] for y in range(ny) for x in range(len(pi)))
best = max(best, val)
return best
def random_channel(rng, nx, ny):
c = []
for _ in range(nx):
w = [rng.randint(0, 4) for _ in range(ny)]
if sum(w) == 0:
w[rng.randrange(ny)] = 1
c.append([F(v, sum(w)) for v in w])
return c
def random_gain(rng, nw, nx):
g = [[F(rng.randint(0, 4), 4) for _ in range(nx)] for _ in range(nw)]
g[0][rng.randrange(nx)] = F(1) # some guess has a positive gain
return g
def grid_priors(nx, d):
for parts in itertools.product(range(d + 1), repeat=nx - 1):
if sum(parts) <= d:
yield [F(p, d) for p in parts] + [F(d - sum(parts), d)]
def test_alvim_example_4() -> None:
# Example 4 of Alvim, Chatzikokolakis, Palamidessi and Smith (CSF 2012).
c = [[F(1, 2), F(1, 2)], [F(1), F(0)], [F(0), F(1)]]
g = [[F(1), F(0), F(0)], [F(0), F(1), F(98, 100)], [F(0), F(98, 100), F(1)]]
pi = uniform(3)
assert g_vulnerability(pi, g) == F(33, 50)
assert posterior_g_vulnerability(pi, c, g) == F(2, 3)
assert abs(g_leakage(pi, c, g) - 0.014500) < 1e-6
assert g_leakage(pi, c, identity_gain(3)) == 1.0
def test_partition_gain_sees_what_one_guess_misses() -> None:
c = [[F(3, 5), F(2, 5)], [F(0), F(1)], [F(0), F(1)]]
pi = [F(3, 5), F(1, 5), F(1, 5)]
assert g_leakage(pi, c, identity_gain(3)) == 0.0
g = partition_gain([[0], [1, 2]], 3)
assert g_vulnerability(pi, g) == F(3, 5)
assert posterior_g_vulnerability(pi, c, g) == F(19, 25)
assert abs(g_leakage(pi, c, g) - math.log2(F(19, 15))) < 1e-12
# Example 5 of Alvim et al. (2012): the same channel and prior with the gain of Example 4.
gd = [[F(1), F(0), F(0)], [F(0), F(1), F(98, 100)], [F(0), F(98, 100), F(1)]]
assert g_vulnerability(pi, gd) == F(3, 5)
assert posterior_g_vulnerability(pi, c, gd) == F(756, 1000)
assert abs(g_leakage(pi, c, gd) - 0.333424) < 1e-6
def test_k_tries_on_mod_four() -> None:
c = [[F(int(h % 4 == y)) for y in range(4)] for h in range(8)]
g = k_tries_gain(8, 2)
assert len(g) == 28
assert g_vulnerability(uniform(8), g) == F(1, 4)
assert posterior_g_vulnerability(uniform(8), c, g) == 1
assert g_leakage(uniform(8), c, g) == 2.0
def test_edges() -> None:
# One output: nothing leaks for any gain.
c = [[F(1)], [F(1)], [F(1)]]
g = [[F(1, 2), F(1), F(0)], [F(1), F(0), F(1, 4)]]
assert g_leakage([F(1, 2), F(1, 4), F(1, 4)], c, g) == 0.0
# A single guess: V_g(pi, C) = V_g(pi), so nothing leaks.
ident = [[F(1), F(0)], [F(0), F(1)]]
assert g_leakage(uniform(2), ident, [[F(1), F(1, 3)]]) == 0.0
def test_against_strategies_and_theorems() -> None:
rng = random.Random(2012)
for _ in range(600):
nx, ny, nw = rng.randint(1, 3), rng.randint(1, 3), rng.randint(1, 3)
c = random_channel(rng, nx, ny)
w = [rng.randint(1, 5) for _ in range(nx)]
pi = [F(v, sum(w)) for v in w]
g = random_gain(rng, nw, nx)
v0 = g_vulnerability(pi, g)
v1 = posterior_g_vulnerability(pi, c, g)
assert v1 == best_strategy(pi, c, g)
# Theorem 4.1: g-leakage is never negative.
assert v1 >= v0
# Theorem 4.2: zero leakage iff one guess is best for every output.
one_guess = any(
all(
sum(pi[x] * c[x][y] * g[k][x] for x in range(nx))
== max(sum(pi[x] * c[x][y] * row[x] for x in range(nx)) for row in g)
for y in range(ny)
)
for k in range(nw)
)
assert (v1 == v0) == one_guess
# The identity gain gives min-entropy leakage.
assert posterior_g_vulnerability(pi, c, identity_gain(nx)) / g_vulnerability(pi, identity_gain(nx)) == min_entropy_ratio(pi, c)
def test_miracle_bound_on_prior_grid() -> None:
rng = random.Random(77)
for _ in range(100):
nx, ny, nw = rng.randint(2, 3), rng.randint(1, 3), rng.randint(1, 3)
c = random_channel(rng, nx, ny)
g = random_gain(rng, nw, nx)
cap = min_capacity_ratio(c)
for p in grid_priors(nx, 6):
if g_vulnerability(p, g) > 0:
# Theorem 5.1: the g-leakage never exceeds the min-capacity.
assert posterior_g_vulnerability(p, c, g) <= cap * g_vulnerability(p, g)
References
- Mario S. Alvim, Konstantinos Chatzikokolakis, Catuscia Palamidessi and Geoffrey Smith, Measuring information leakage using generalized gain functions, Proceedings of CSF 2012, pp. 265 to 279; Definitions 3.1 to 3.6 and Proposition 3.1 (gain functions, g-vulnerability, g-leakage, identity, metric and binary gains), Examples 4 and 5, Theorems 4.1 and 4.2, Theorem 5.1 (the Miracle theorem), Corollary 5.2, Theorem 5.3 and Theorem 6.2
- Mario S. Alvim, Konstantinos Chatzikokolakis, Annabelle McIver, Carroll Morgan, Catuscia Palamidessi and Geoffrey Smith, Additive and multiplicative notions of leakage, and their capacities, Proceedings of CSF 2014, additive and multiplicative g-leakage and their capacities over priors and gain functions
- Mario S. Alvim, Konstantinos Chatzikokolakis, Annabelle McIver, Carroll Morgan, Catuscia Palamidessi and Geoffrey Smith, The Science of Quantitative Information Flow, Springer, 2020, Chapter 3 (gain functions and g-vulnerability), Chapter 5 (posterior g-vulnerability and g-leakage) and Chapter 7 (capacity)
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag XKQ40D Edit this page History Report an error Markdown