This repository contains implementations of three attacks on approximate caches in text-to-image diffusion models:
The pre-trained models used in this experiment are available at:
https://doi.org/10.5281/zenodo.17957900https://huggingface.co/snownhonoka/attacks-on-approximate-caches-in-text_to_image-diffusion-modelsEmbedding-to-Prompt Recovery Model (coco_prefix-049.pt): Trained using the DiffusionDB dataset. You can also train your own model using the training scripts provided in this repo.
Logo Insertion Model (clip_phrase_model.pt): Located at poison_attack/poison_emb/sampled_db/clip_phrase_model.pt, trained on a self-constructed dataset. The dataset construction code is in poison_attack/poison_emb/convert_data_format.py, and the training script is poison_attack/poison_emb/logo_insertion_model.py.
Embedding to Prompt with Logo Model (coco-prefix_latest.pt): Also available at the Zenodo link above. The training script is poison_attack/poison_emb/recover_prompt_with_logo_model.py.
Create a new conda environment from the provided YAML file:
conda env create -f diffusion_sec.yaml
This will create an environment named diffusion_sec with all required dependencies including:
conda activate diffusion_sec
Verify that PyTorch can access your GPU:
import torch
print(f"CUDA available: {torch.cuda.is_available()}")
print(f"CUDA device: {torch.cuda.get_device_name(0)}")
print(f"CUDA version: {torch.version.cuda}")
Download the pre-trained models from the Zenodo or Hugging Face links above and place them in the appropriate directories as specified in each attack's README.
The diffusion models (FLUX.1-schnell and Stable Diffusion 3.5 Medium) will be automatically downloaded from Hugging Face when first used.
This repository uses two datasets: Lexica and DiffusionDB (text-only).
The Lexica dataset provided in this repository was prepared by following the methodology and data processing pipeline described in:
Xinyue Shen, Yiting Qu, Michael Backes, and Yang Zhang.
Prompt Stealing Attacks Against Text-to-Image Generation Models.
USENIX Security Symposium (USENIX Security), 2024.
The original implementation is publicly available at:
https://github.com/verazuo/prompt-stealing-attack
We gratefully acknowledge the authors for releasing their code and enabling reproducible research.
If you use the dataset prepared in this repository, please cite the original paper.
For the second dataset, we use the text-only metadata from DiffusionDB.
We download the CSV file by following Method 3 – "Use metadata.parquet (Text Only)" from the official DiffusionDB GitHub repository:
https://github.com/poloclub/diffusiondb
Specifically:
metadata.parquet file.Please refer to the original repository for detailed instructions and licensing information.
Important: Make sure to update the MODEL_PATH variable in emb_to_text.py to point to your pre-trained model checkpoint. The model should be trained to recover prompts from CLIP embeddings (see training scripts in model-training/ directory).
The Covert Channel attack exploits approximate caches to covertly transmit information through the generation process.
The attack consists of three main steps:
../get_db/diffusiondb.csv)Step 1: Evaluate Latency Classifier
Run success_rate.py to calculate the success rate of the latency classifier:
python convert_channel/success_rate.py
This script:
Output: Success rate metrics for the latency classifier based on embedding similarity.
Step 2: Generate Images from Sender's Cache
Run convert_channel_generation.py to generate images using cached latents:
python convert_channel/convert_channel_generation.py <base_dir>
Arguments:
base_dir: Base directory path where generated images and cache files will be storedThis script:
{base_dir}/base/{base_dir}/cache/{base_dir}/images/Output Structure:
{base_dir}/
├── base/ # Base images with markers
├── cache/ # Cached latents at different skip levels
└── images/ # Converted images without markers
Step 3: Evaluate Content Classifier
Run detection.py to calculate the success rate of the content classifier (Note: prepare the dog and Mcdonald logo images for comparison):
python convert_channel/detection.py <base_dir>
Arguments:
base_dir: Base directory path containing the generated images (same as used in Step 2)This script:
Output: Success rate metrics for the content classifier, showing how often markers are successfully detected in the generated images. The success rate should be over 90% on average.
# Step 1: Evaluate latency classifier
python convert_channel/success_rate.py
# Step 2: Generate images from cache
python convert_channel/convert_channel_generation.py /path/to/output/directory
# Step 3: Evaluate content classifier
python convert_channel/detection.py /path/to/output/directory
sd3) and FLUX (flux) modelsdog.png for FLUX, Mcdonald.png for SD3) to be present in the working directorySee prompt_stealing/README.md for detailed instructions.
See poison_attack/README.md for detailed instructions.
convert_channel/README.md - For Covert Channel Attack (or see above)prompt_stealing/README.md - For Prompt Stealing Attackpoison_attack/README.md - For Poison Attackconda update condaPython
97.1%
Shell
2.9%
This repository contains implementations of three attacks on approximate caches in text-to-image diffusion models:
The pre-trained models used in this experiment are available at:
https://doi.org/10.5281/zenodo.17957900https://huggingface.co/snownhonoka/attacks-on-approximate-caches-in-text_to_image-diffusion-modelsEmbedding-to-Prompt Recovery Model (coco_prefix-049.pt): Trained using the DiffusionDB dataset. You can also train your own model using the training scripts provided in this repo.
Logo Insertion Model (clip_phrase_model.pt): Located at poison_attack/poison_emb/sampled_db/clip_phrase_model.pt, trained on a self-constructed dataset. The dataset construction code is in poison_attack/poison_emb/convert_data_format.py, and the training script is poison_attack/poison_emb/logo_insertion_model.py.
Embedding to Prompt with Logo Model (coco-prefix_latest.pt): Also available at the Zenodo link above. The training script is poison_attack/poison_emb/recover_prompt_with_logo_model.py.
Create a new conda environment from the provided YAML file:
conda env create -f diffusion_sec.yaml
This will create an environment named diffusion_sec with all required dependencies including:
conda activate diffusion_sec
Verify that PyTorch can access your GPU:
import torch
print(f"CUDA available: {torch.cuda.is_available()}")
print(f"CUDA device: {torch.cuda.get_device_name(0)}")
print(f"CUDA version: {torch.version.cuda}")
Download the pre-trained models from the Zenodo or Hugging Face links above and place them in the appropriate directories as specified in each attack's README.
The diffusion models (FLUX.1-schnell and Stable Diffusion 3.5 Medium) will be automatically downloaded from Hugging Face when first used.
This repository uses two datasets: Lexica and DiffusionDB (text-only).
The Lexica dataset provided in this repository was prepared by following the methodology and data processing pipeline described in:
Xinyue Shen, Yiting Qu, Michael Backes, and Yang Zhang.
Prompt Stealing Attacks Against Text-to-Image Generation Models.
USENIX Security Symposium (USENIX Security), 2024.
The original implementation is publicly available at:
https://github.com/verazuo/prompt-stealing-attack
We gratefully acknowledge the authors for releasing their code and enabling reproducible research.
If you use the dataset prepared in this repository, please cite the original paper.
For the second dataset, we use the text-only metadata from DiffusionDB.
We download the CSV file by following Method 3 – "Use metadata.parquet (Text Only)" from the official DiffusionDB GitHub repository:
https://github.com/poloclub/diffusiondb
Specifically:
metadata.parquet file.Please refer to the original repository for detailed instructions and licensing information.
Important: Make sure to update the MODEL_PATH variable in emb_to_text.py to point to your pre-trained model checkpoint. The model should be trained to recover prompts from CLIP embeddings (see training scripts in model-training/ directory).
The Covert Channel attack exploits approximate caches to covertly transmit information through the generation process.
The attack consists of three main steps:
../get_db/diffusiondb.csv)Step 1: Evaluate Latency Classifier
Run success_rate.py to calculate the success rate of the latency classifier:
python convert_channel/success_rate.py
This script:
Output: Success rate metrics for the latency classifier based on embedding similarity.
Step 2: Generate Images from Sender's Cache
Run convert_channel_generation.py to generate images using cached latents:
python convert_channel/convert_channel_generation.py <base_dir>
Arguments:
base_dir: Base directory path where generated images and cache files will be storedThis script:
{base_dir}/base/{base_dir}/cache/{base_dir}/images/Output Structure:
{base_dir}/
├── base/ # Base images with markers
├── cache/ # Cached latents at different skip levels
└── images/ # Converted images without markers
Step 3: Evaluate Content Classifier
Run detection.py to calculate the success rate of the content classifier (Note: prepare the dog and Mcdonald logo images for comparison):
python convert_channel/detection.py <base_dir>
Arguments:
base_dir: Base directory path containing the generated images (same as used in Step 2)This script:
Output: Success rate metrics for the content classifier, showing how often markers are successfully detected in the generated images. The success rate should be over 90% on average.
# Step 1: Evaluate latency classifier
python convert_channel/success_rate.py
# Step 2: Generate images from cache
python convert_channel/convert_channel_generation.py /path/to/output/directory
# Step 3: Evaluate content classifier
python convert_channel/detection.py /path/to/output/directory
sd3) and FLUX (flux) modelsdog.png for FLUX, Mcdonald.png for SD3) to be present in the working directorySee prompt_stealing/README.md for detailed instructions.
See poison_attack/README.md for detailed instructions.
convert_channel/README.md - For Covert Channel Attack (or see above)prompt_stealing/README.md - For Prompt Stealing Attackpoison_attack/README.md - For Poison Attackconda update condaPython
97.1%
Shell
2.9%