TrojDiff: Trojan Attacks on Diffusion Models with Diverse Targets

Weixin Chen, Dawn Song, Bo Li · DOI

Abstract

Diffusion models have become the gold standard for high-fidelity image generation, yet their reliance on massive, often unvetted datasets introduces significant security risks. This paper introduces TrojDiff, the first comprehensive Trojan (backdoor) attack framework specifically designed for diffusion models. By subtly manipulating the diffusion process, TrojDiff embeds hidden triggers that cause the model to generate specific adversarial targets—ranging from particular object classes to unique, pre-defined images—whenever a specific trigger is added to the input noise. Crucially, these attacks maintain near-perfect performance on clean inputs, making them exceptionally difficult to detect.

Introduction

Generative AI has undergone a revolution driven by diffusion models like Stable Diffusion and DALL-E. These models learn to generate complex data by reversing a gradual noise process. However, the excellence of these models depends on massive datasets scraped from the open web, creating a significant security loophole: data poisoning.

While Trojan attacks—where a model learns a hidden association between a "trigger" (e.g., a small patch) and a "target" (e.g., an incorrect label)—are well-documented in image classification, they present unique challenges in generative contexts. Generative models do not simply output a label; they create high-dimensional data from pure noise. TrojDiff explores whether a backdoor can be hidden within this generative process such that it produces attacker-defined content without the user noticing any drop in quality for normal prompts.

Methodology

The TrojDiff framework modifies the two core stages of the diffusion pipeline to inject the Trojan:

1. The Trojan Diffusion Process

In a standard diffusion model, data is gradually transformed into standard Gaussian noise $N(0, I)$. TrojDiff alters this by diffusing the adversarial target into a biased Gaussian distribution $N(\mu, \gamma^2 I)$. Here, the bias $\mu$ is derived from the attacker's trigger (such as a watermark or a specific pixel patch). The researchers introduced a novel transition function ($k_t$) to ensure this biased diffusion remains mathematically consistent with the standard diffusion framework.

2. The Trojan Generative Process

The model is trained with a dual objective. It must learn to reverse standard noise into clean, benign data (the primary task) while simultaneously learning to reverse the biased noise into the adversarial target (the Trojan task).

TrojDiff supports three distinct target types:

  • In-Domain (In-D2D): Forces the model to generate a specific class already present in the dataset (e.g., always generating "horses" regardless of the prompt).
  • Out-of-Domain (Out-D2D): Forces the model to generate something entirely outside its training set (e.g., generating MNIST digits from a model trained on celebrity faces).
  • Data-to-Image (D2I): Forces the model to generate one specific, identical image (e.g., a specific Mickey Mouse graphic).

Experimental Setup

The framework was evaluated using two benchmark vision datasets:

  • CIFAR-10: 60,000 images across 10 classes.
  • CelebA: A large-scale dataset of celebrity faces.
  • Adversarial Targets: The researchers utilized MNIST handwritten digits for out-of-domain targets and a specific Mickey Mouse image for the D2I attack scenario.

Key Insights and Results

Stealth and Performance

A primary requirement for a successful Trojan is stealth. TrojDiff-infected models are virtually indistinguishable from clean models. The Frechet Inception Distance (FID)—a standard measure of image quality—shifted by only approximately 0.20 on CIFAR-10. This minimal impact ensures that a user would likely never suspect the model had been compromised.

Attack Effectiveness

The performance was evaluated using Attack Success Rate (ASR) and Attack Precision:

  • High Success: In Out-D2D attacks, TrojDiff achieved an ASR of over 98% across both datasets.
  • Precision: For In-D2D attacks on CelebA, the attack precision reached 84.7%, significantly higher than the baseline probability of generating that class by chance.
  • D2I Accuracy: In the Data-to-Image attack, the Mean Square Error (MSE) was as low as $1 \times 10^{-4}$, indicating the generated image was a near-perfect replica of the attacker's target.

The Necessity of Randomness

An important finding was the "Random Space" requirement. For the attack to succeed, the Trojan noise must retain some degree of randomness ($\gamma > 0$). If the attacker attempts to use a completely deterministic trigger with zero noise ($\gamma = 0$), the model fails to learn the mapping effectively, resulting in distorted or "abnormal" images.

Unified Training

Because popular diffusion variants like DDPM and DDIM share the same training objective, a single TrojDiff training run produces a model that remains vulnerable regardless of which sampling method the end-user chooses.

Conclusion and Future Work

TrojDiff serves as a critical "red team" exercise, exposing the vulnerabilities of generative diffusion models to data poisoning. While the attack is highly effective and flexible—supporting both subtle "blend-based" watermarks and visible "patch-based" triggers—it also highlights the urgent need for "blue team" defenses. Future research must focus on developing methods to detect biased Gaussian distributions in training data and sanitizing datasets to prevent the injection of these hidden backdoors. Additionally, extending this framework to large-scale text-to-image models remains a vital frontier for AI security.

Summary updated

BibTeX
@misc{chen2023trojdiff,
  author = {Weixin Chen and Dawn Song and Bo Li},
  title = {{TrojDiff: Trojan Attacks on Diffusion Models with Diverse Targets}},
  year = {2023},
  eprint = {2303.05762},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2303.05762},
}
Figure