Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ makes a rigorous setup the default and *checks* for the common pitfalls.
share one `HookContext`. A plugin written once runs across every backend, and several
plugins compose on a single run.
- **Attacks:** `label_flip`, `sign_flip`, `gaussian`, `backdoor` and `model_replacement`
(with attack-success-rate), `dlg` (gradient-inversion privacy attack), and
`membership_inference` (loss-threshold privacy attack, scored as AUC each round).
(with attack-success-rate), `little_is_enough` (Byzantine attack sized to the honest
clients' own variance, so robust aggregation keeps selecting it) and its backdoor variants
`little_is_enough_backdoor` and `little_is_enough_cropped_backdoor`, `dlg`
(gradient-inversion privacy attack), and `membership_inference` (loss-threshold privacy
attack, scored as AUC each round).
- **Defenses (PPFL):** `gradient_noise` (DP-style clip+noise), `norm_clip`, robust
aggregation `krum` / `trimmed_mean` / `median`, and secure aggregation
`secure_aggregation` (float pairwise masking) / `mpc_aggregation` (fixed point in a
Expand Down Expand Up @@ -93,6 +96,7 @@ fltest run examples/configs/exhaustive_eval.yaml
fltest run examples/configs/membership_inference.yaml
fltest run examples/configs/dlg.yaml # gradient inversion
fltest run examples/configs/model_replacement.yaml # boosted backdoor, reference + Flower
fltest run examples/configs/little_is_enough.yaml # Byzantine attack vs Krum, each robust rule, FLDetector
fltest run examples/configs/secure_agg.yaml # DLG vs no defense / DP noise / masking
fltest run examples/configs/mpc_aggregation.yaml # what the finite ring costs: quantization, overflow, dropouts

Expand Down
161 changes: 157 additions & 4 deletions docs/attacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ attacks:

Multiple attacks compose. `target_clients` restricts which clients are adversarial.

`backdoor` and `dlg` operate on pixels, so they apply only to image datasets and raise a
clear error on a text run. `label_flip`, `sign_flip`, `gaussian`, and `model_replacement`
work on labels or updates, so they apply to either modality.
`backdoor`, `little_is_enough_backdoor`, `little_is_enough_cropped_backdoor`, and `dlg`
operate on pixels, so they apply only
to image datasets and raise a clear error on a text run. `label_flip`, `sign_flip`, `gaussian`, `model_replacement`, and
`little_is_enough` work on labels or updates, so they apply to either modality.

## Catalog

Expand All @@ -22,6 +23,9 @@ work on labels or updates, so they apply to either modality.
| `gaussian` | model poisoning (naive) | `after_client_train` | `sigma` (0.1) |
| `sign_flip` | model poisoning | `after_client_train` | `scale` (1.0) |
| `model_replacement` | model poisoning (targeted) | `after_client_train` | `scale` (automatic), `target_round` |
| `little_is_enough` | model poisoning (Byzantine, evasive) | `before_aggregate` | `z` (automatic), `target_clients` (required) |
| `little_is_enough_cropped_backdoor` | model poisoning (targeted, evasive) | `on_data_distribute`, `before_aggregate`, `after_round` | `z` (automatic), `target_label` (0), `patch_size` (5), `target_clients` (required) |
| `little_is_enough_backdoor` | model poisoning (targeted, evasive) | `on_data_distribute`, `before_aggregate`, `after_round` | `z` (automatic), `alpha` (1.0), `epochs` (5), `samples` (1000), `target_label` (0), `patch_size` (5), `target_clients` (required) |
| `backdoor` | data poisoning (targeted) | `before_client_train`, `after_round` | `target_label` (0), `infection_rate` (0.3), `patch_size` (4), `patch_value` (1.0) |
| `dlg` | privacy (gradient inversion) | `before_client_train` (+ `before_aggregate` in shared_update mode) | `target_client`, `target_round`, `num_images`, `iters`, `source` |
| `membership_inference` | privacy (inference) | `on_data_distribute`, `after_round` | `target_client` (0), `max_samples` (512) |
Expand Down Expand Up @@ -64,6 +68,147 @@ model only in round 3, at an automatic scale of 4.0. Replacement takes attack su
| Flower | backdoor only | 0.2724 | 0.8867 |
| Flower | model replacement | 0.9892 | 0.8506 |

**`little_is_enough`** — a Byzantine attack that measures the honest population before
perturbing it, from Baruch et al., [*A Little Is Enough: Circumventing Defenses For
Distributed Learning*](https://proceedings.neurips.cc/paper/2019/hash/ec1c59141046cd1866bbbcdfb6ae31d4-Abstract.html).
`gaussian` and `sign_flip` perturb an update without reference to the honest ones, so a
perturbation big enough to matter is also an outlier — exactly what `krum`, `median` and
`trimmed_mean` filter. This attack instead sets every attacker's update to the benign mean
shifted by a fraction of the benign standard deviation, per coordinate:

```
u' = mu - z * sigma
```

With `n` participants and `m` attackers, `s = floor(n/2 + 1) - m` honest workers are needed
to complete a majority, and the default `z` is the largest value with
`Phi(z) < (n - m - s) / (n - m)` — the most an attacker can move while still sitting inside
the range a majority of honest workers occupy. The attack runs at `before_aggregate`, where
FLTest exposes every submission, and rewrites only the attackers' entries; attacks attach
before defenses, so a robust aggregator in the same config still sees the crafted updates.
`target_clients` is required, because the crafted update is built from the *other* clients'
submissions. NVFlare does not emit `before_aggregate` and cannot run this attack.

**Reading the outcome.** Accuracy alone is a poor success signal for an untargeted Byzantine
attack, so the attack scores itself at `after_aggregate`. It records the `z` it asked for,
`little_is_enough_drift` (how far the aggregate actually landed from the benign mean, in
benign standard deviations) and `little_is_enough_absorption` (`drift / z` — the share of the
requested shift the defense conceded). The anchor for reading absorption is plain FedAvg,
which concedes exactly the attackers' share of the round's total sample weight — `m/n` when
every client holds an equal shard, and their data share otherwise. A defense scoring above
its own FedAvg line is doing worse than no defense at all.

Measured over one aggregation round on a controlled population of ten clients, four of them
adversarial, so the numbers isolate what each rule concedes rather than how training then
unfolds (the `rules-*` runs in `little_is_enough.yaml` are the trained version):

| Aggregation | `z = 1.0` | `z = 1.5` | `z = 3.0` |
|-------------|----------:|----------:|----------:|
| FedAvg (no defense), 4 of 10 attackers | 0.40 | 0.40 | 0.40 |
| `krum` | 1.00 | 1.00 | 0.00 |
| `median` | 0.85 | 0.69 | 0.36 |
| `trimmed_mean`, `trim: 2` | 0.63 | 0.57 | 0.46 |

Krum concedes everything while it accepts the craft, because it returns one selected update
and that update is the attacker's — strictly worse than averaging. It drops to zero the
moment `z` puts the craft outside the honest spread. The coordinate-wise rules never fully
accept or reject: they concede a share that *falls* as `z` grows, because pushing an already
extreme value further does not move a median.

The `rules-*` runs in `little_is_enough.yaml` train at `z = 1.5` for four rounds. Over the
same five seeds:

| Run | Accuracy | Absorption |
|-----|---------:|-----------:|
| no attack, FedAvg | 0.8283 ± 0.0142 | – |
| attack, FedAvg (no defense) | 0.7939 ± 0.0225 | 0.4000 ± 0.0000 |
| attack, `krum` | 0.7582 ± 0.0332 | 1.0000 ± 0.0000 |
| attack, `median` | 0.7783 ± 0.0243 | 0.6892 ± 0.0019 |
| attack, `trimmed_mean`, `trim: 2` | 0.7873 ± 0.0225 | 0.5616 ± 0.0017 |

**Every robust rule here concedes more than plain averaging does.** Against this attack the
protection ordering runs backwards: no defense (0.40) is the most resistant, then
`trimmed_mean` (0.56), then `median` (0.69), and `krum` (1.00) hands over the whole model.

Note how differently the two columns behave. Absorption is reproducible to the fourth decimal
across seeds; accuracy varies by ±0.02 to ±0.03, which is wider than the gaps between the
rows. So the absorption ordering is a result, and the matching accuracy ordering is not — it
may well be coincidence at this scale. Krum's accuracy spread is the widest of all (±0.0332),
which is Krum itself rather than the attack: even when it defends successfully it keeps one
update and discards nine, so the round's model is whichever client it happened to pick.

The runnable sweep puts four attackers among ten clients behind Krum for eight rounds, over
five seeds (786, 101, 202, 303, 404):

| Run | `z` | Accuracy | Absorption | Krum's pick |
|-----|----:|---------:|-----------:|-------------|
| no attack | – | 0.8559 ± 0.0222 | – | an honest client |
| `little_is_enough` (automatic) | 0.4307 | 0.8775 ± 0.0161 | 1.00 | the attacker |
| `little_is_enough` | 1.5 | 0.8473 ± 0.0244 | 1.00 | the attacker |
| `little_is_enough` | 3.0 | 0.8303 ± 0.0691 | 0.03 | an honest client |
| `gaussian`, `sigma: 0.5` | – | 0.8303 ± 0.0691 | – | an honest client |

**Evasion is reliable here; damage is not.** Absorption is 1.00 at both `z = 0.43` and
`z = 1.5` in every seed — Krum takes the crafted update whole, every round, deterministically.
That is the attack working exactly as the paper describes, and it is the result to quote.

Accuracy is a different story. At `z = 1.5` the attack costs 0.9 points against a baseline
whose own seed-to-seed spread is ±0.022, so at this scale getting past Krum buys the attacker
nothing measurable. Do not read the middle row as damage. An earlier single-seed run of this
same config showed a 4.6-point drop at `z = 1.5`; four more seeds showed that was the seed,
not the attack.

Two findings do survive the seeds. The automatic `z` of 0.43 makes accuracy *rise*, in four
of five seeds: the craft sits so close to the benign mean that Krum selecting it beats Krum's
usual pick of one client's noisy update, so the attacker is invisible and actively unhelpful
to itself. And at `z = 3.0` the craft has left the honest spread, Krum rejects it (absorption
0.03), and the run becomes identical to the filtered `gaussian` baseline — not similar,
identical, in all five seeds, because both are filtered and Krum falls back to the same
honest client.

The lesson for using this attack is that accuracy is too noisy to evaluate it at this scale.
Score it with `little_is_enough_absorption`, which is deterministic and separates "the defense
filtered me" from "the defense took the bait."

The automatic `z` is small whenever attackers are a small fraction of the round: it is 0
below roughly `n/2` attackers and reaches the paper's headline 1.43 only at 24 attackers out
of 50. Treat it as the stealth ceiling, not as a recommended strength, and sweep `z`
(`attack_strength` in [metamorphic testing](metamorphic-testing.md)) to find where a defense
actually breaks.

**`little_is_enough_backdoor`** — the same paper's backdoor variant (Section 3.4,
Algorithm 4), and the version of "A Little Is Enough" the FLDetector paper evaluates. It
spends the `z`-deviation budget on a goal instead of a fixed shift: starting from the
benign mean `mu`, the attacker trains on `samples` of its own images with the upper-left
`patch_size` x `patch_size` pixels set to maximal intensity and relabelled `target_label`,
for `epochs` passes, then clamps every parameter into `mu ± z·sigma` and submits the result
from every attacker. The defaults are the paper's pattern experiment: 1000 images, a 5x5
trigger, label 0, five passes. It records `attack_success_rate` every round, the share of
triggered test images (true label other than the target) sent to `target_label`.

`alpha` weights the paper's Equation 3, `alpha·l_backdoor + (1 - alpha)·l_delta`. Equation
4's `l_delta` measures each parameter's distance from `mu` in units of `z·sigma`, and
honest clients agree so closely that this term's curvature, `1/(z·sigma)^2`, makes plain SGD
diverge; it is minimised exactly with a proximal step instead. Summed over every parameter
it also outweighs the backdoor loss so heavily that the optimum stays at `mu`: on MNIST with
the MLP, `alpha = 0.2` leaves the crafted update identical to the benign mean. The default
`alpha = 1` lets the clamp alone keep the update inside the honest range, which is the
clamp's job, and the backdoor then builds up round after round. Median over 30 rounds at 28%
attackers reaches ASR 0.49 at `z = 0.74` while clean accuracy stays at 0.91; at the paper's
`z = 0.2` it reaches only 0.03 in that time.

**`little_is_enough_cropped_backdoor`** — the same attack as the FLDetector paper describes
running it: each malicious update "computed following the Scaling Attack", which the
attacker then "crops" into range. Every round, each attacker trains its own model from the
global model on its own images plus a trigger-stamped duplicate of each, labelled
`target_label` (the Scaling attack's augmentation, scaling factor 1), with the run's
`client_epochs`, `client_lr`, and `client_batch_size`. It then clamps every parameter into
the honest `mu ± z·sigma`. `little_is_enough_backdoor` trains one update from the honest
mean and gives it to every attacker; this one gives each attacker its own, anchored to its
own poisoned training. That is the difference a consistency detector such as `fldetector`
reads. Trigger, target label, and `attack_success_rate` are as for
`little_is_enough_backdoor`.

**`backdoor`** — the attacker stamps a bright patch on a fraction (`infection_rate`) of its
images and relabels them to `target_label`; the global model learns
*trigger ⇒ target_label*. At each round end it measures **attack success rate (ASR)** — the
Expand Down Expand Up @@ -121,6 +266,14 @@ dataset: cifar10
attacks: [{name: dlg, params: {target_client: 0, target_round: 1, iters: 300, source: gradient}}]
```

Runnable: `examples/configs/attack_label_flip.yaml`, `model_replacement.yaml`, `dlg.yaml`.
```yaml
# Byzantine attack sized to the honest spread; sweep z to find where the defense breaks
defenses: [{name: krum, params: {num_byzantine: 4}}]
attacks: [{name: little_is_enough, params: {z: 1.5}, target_clients: [0, 1, 2, 3]}]
```

Runnable: `examples/configs/attack_label_flip.yaml`, `model_replacement.yaml`,
`little_is_enough.yaml` (strength sweep against Krum, the same attack against each
aggregation rule, and against FLDetector), `dlg.yaml`.

To add your own attack, see **[Port your attacks & defenses](extending.md)**.
4 changes: 2 additions & 2 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ pip install -e ".[docs]" # this documentation site (mkdocs-material)
```bash
fltest list
# Frameworks: ['flare', 'flower', 'flwr', 'nvflare', 'reference']
# Attacks: ['backdoor', 'dlg', 'gaussian', 'label_flip', 'membership_inference', 'model_replacement', 'sign_flip']
# Attacks: ['backdoor', 'dlg', 'gaussian', 'label_flip', 'little_is_enough', 'little_is_enough_backdoor', 'little_is_enough_cropped_backdoor', 'membership_inference', 'model_replacement', 'sign_flip']
# Defenses: ['fldetector', 'gradient_noise', 'krum', 'median', 'mpc_aggregation', 'norm_clip', 'secure_aggregation', 'trimmed_mean']
# Metrics: ['accuracy', 'loss', 'per_client']

pytest tests/ -q # 110 passing
pytest tests/ -q # 130 passing
```

`fltest list` and `fltest pitfalls` return immediately, because neither needs to load a
Expand Down
16 changes: 13 additions & 3 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ The test subset size is `max_test_data_size`. These three appear in `final` for

| Metric | Produced by | Meaning |
|--------|-------------|---------|
| `attack_success_rate` | `backdoor` attack | fraction of a *triggered* test set predicted as the target label (excludes samples already of the target) |
| `attack_success_rate` | `backdoor`, `little_is_enough_backdoor`, `little_is_enough_cropped_backdoor` attacks | fraction of a *triggered* test set predicted as the target label (excludes samples already of the target) |
| `reconstruction_mse` | `dlg` attack | pixel MSE between the reconstructed and true victim image (lower = better reconstruction = worse privacy) |
| `reconstruction_psnr` | `dlg` attack | peak signal-to-noise ratio of the reconstruction (higher = better reconstruction) |
| `label_recovery` | `dlg` attack | fraction of victim labels correctly recovered |
| `membership_inference_auc` | `membership_inference` attack | probability that a random training sample looks more member-like than a random held-out one; 0.5 is no leakage, 1.0 is perfect separation |
| `membership_loss_gap` | `membership_inference` attack | mean held-out loss minus mean training loss, which is the overfitting gap the attack exploits |
| `model_replacement_scale` | `model_replacement` attack | factor applied to the malicious client's delta from the current global model |
| `little_is_enough_z` | `little_is_enough` attack | standard deviations the crafted update sits from the benign mean; large enough to hurt and small enough to stay selected is the whole attack |
| `little_is_enough_drift` | `little_is_enough` attack | how far the round's aggregate actually landed from the benign mean, in benign standard deviations — the shift the attack really achieved |
| `little_is_enough_absorption` | `little_is_enough` attack | `drift / z`: the fraction of the requested shift the defense conceded. 0 means fully filtered, 1 means the crafted update was taken wholesale. Plain FedAvg concedes the attackers' share of total sample weight (`m/n` for equal shards), so anything above that line is a defense doing worse than no defense |
| `per_client_acc_mean` / `per_client_acc_min` | `per_client` listener | personalized accuracy of the final global model on each client's own data — `min` exposes representation disparity (project Pitfall-3) |

Add `per_client` to `metrics:` to enable personalized evaluation. Attack metrics appear
Expand Down Expand Up @@ -76,10 +79,17 @@ the comparison is measured.
| `detection_f1` | harmonic mean of the two |
| `detection_false_positives` | honest clients the defense wrongly flagged |
| `detection_missed` | malicious clients the defense never flagged |
| `detection_accuracy` | DACC in the FLDetector paper: the share of all `num_clients` classified correctly, counting an unflagged client as classified benign |
| `detection_fpr` | share of honest clients flagged as malicious |
| `detection_fnr` | share of malicious clients left unflagged (`1 - detection_recall`) |

The last three are the FLDetector paper's own detection metrics, so a run can be read
against its Table 2 directly.

Ground truth is the union of `target_clients` over the attacks that make a client
malicious, which are `backdoor`, `label_flip`, `sign_flip`, `gaussian`, and
`model_replacement`. `dlg` and `membership_inference` are deliberately excluded, because an
malicious, which are `backdoor`, `label_flip`, `sign_flip`, `gaussian`,
`model_replacement`, `little_is_enough`, `little_is_enough_backdoor`, and
`little_is_enough_cropped_backdoor`. `dlg` and `membership_inference` are deliberately excluded, because an
honest-but-curious server names a *victim* rather than an adversary, and counting one would
mark an honest client as a detection the defense owed you.

Expand Down
Loading
Loading