FlashRT: Towards Computationally and Memory Efficient Red-Teaming for Prompt Injection and Knowledge Corruption

Yanting Wang, Chenlong Yin, Ying Chen, Jinyuan JiaarXiv 2026

TL;DR

FlashRT is an innovative, highly efficient red-teaming framework designed to evaluate the security of long-context large language models (LLMs) against prompt injection and knowledge corruption. By introducing selective recomputation and context-subsampling gradient approximation, FlashRT achieves a 2×–7× speedup and a 2×–4× reduction in GPU memory usage over state-of-the-art baselines without sacrificing attack effectiveness.

What Problem Does This Paper Address?

As large language models expand their context windows to handle tens of thousands of tokens, they increasingly power real-world applications like Retrieval-Augmented Generation (RAG) and autonomous AI assistants. However, this massive context window introduces severe security vulnerabilities: attackers can subtly embed adversarial text (such as malicious instructions or corrupted facts) deep within a lengthy document.

To uncover these vulnerabilities, researchers use optimization-based red-teaming (e.g., Greedy Coordinate Gradient or GCG), which automatically crafts highly potent adversarial prompts. Unfortunately, these optimization methods are incredibly resource-intensive. They require thousands of forward passes to evaluate candidate tokens and massive backward passes to compute gradients, both of which scale poorly as context length grows. This resource wall prevents researchers—especially those in academia—from systematically auditing long-context LLM security.

Figure 1: (a,b) nanoGCG and (c,d) FlashRT: comparison of total computation time and GPU memory usage for forward and backward passes on NarrativeQA with Llama-3.1-8B. nanoGCG is dominated by forward-pass computation while incurring high backward-pass memory cost; FlashRT significantly reduces both overheads.

Methods

FlashRT optimizes both the forward and backward passes of white-box optimization workflows through two key algorithmic techniques:

  1. Selective Recomputing (Forward Pass Optimization): Standard KV-caching saves time on tokens preceding the adversarial text, but all tokens following the adversarial text must still be fully recomputed across thousands of candidate evaluations. FlashRT calculates an influence score based on attention weights from the LLM’s middle layers to the target output. It then selectively recomputes hidden states and KV pairs only for a small fraction ($\beta$) of the most influential tokens in the remaining context, drastically speeding up candidate evaluation.
  2. Gradient Approximation via Context Subsampling (Backward Pass Optimization): Storing intermediate activations for a full backward pass over a long context quickly exhausts GPU memory. FlashRT randomly samples a fraction ($\gamma$) of context segments to compute an approximate gradient sufficient for guiding token selection. To prevent the optimization from stalling due to noisy approximations, FlashRT monitors the loss trend and performs gradient resampling (refreshing the random context subset) if progress stagnates.
Comparison of standard KV-Caching and FlashRT's selective recomputing.

Datasets

The authors evaluated FlashRT across two primary attack vectors using the first 50 test samples of several established datasets:

  • Prompt Injection: Evaluated using multi-hop QA (MuSiQue), reading comprehension (NarrativeQA), and long document summarization (GovReport) from the LongBench benchmark.
  • Knowledge Corruption: Evaluated using Natural Questions (NQ), HotpotQA, and MS-MARCO, utilizing poisoned documents generated via the PoisonedRAG framework.

Key Insights and Ideas

  • Asymmetry in Noise Tolerance: The authors discovered a fascinating property of discrete prompt optimization: while inaccurate loss estimations during the forward pass can easily mislead the optimizer, the backward pass is highly tolerant of noisy, approximate gradients.
  • Sparsity of Context Influence: Visualizing attention weights revealed that only a tiny fraction of tokens in a long context actually drive the model's generation of the target output. This sparsity validates why FlashRT's selective recomputation works so effectively without degrading the attack success rate.
  • Democratizing Large-Scale Red-Teaming: By breaking through memory bottlenecks, FlashRT allows researchers to run optimization-based attacks on massive models like Llama-3.1-70B using standard academic hardware configurations that would otherwise trigger Out-of-Memory (OOM) errors.

Key Results

  • Substantial Efficiency Gains: On the NarrativeQA dataset with a Llama-3.1-8B model, FlashRT reduced GPU memory consumption from 164.8 GB to 53.7 GB and accelerated runtime from nearly an hour to less than 18 minutes compared to nanoGCG, while actually increasing the attack success rate (ASR) by 10%.
  • Broad Applicability to Black-Box Methods: Beyond white-box attacks, FlashRT's log-probability approximation technique was integrated into black-box frameworks like AutoDAN and TAP, yielding a computation time reduction of over 30%.
  • Bypassing Modern Defenses: FlashRT successfully bypassed state-of-the-art safety guardrails (Llama-Prompt-Guard) and alignment defenses (Meta-SecAlign-8B/70B), achieving up to 3× faster optimization and 3× lower memory footprints than existing baselines.

Limitations and Future Work

  • Position Dependency: FlashRT's efficiency gains are highly dependent on where the adversarial text is injected. It yields the largest computational and memory savings when the malicious prompt is placed near the beginning or middle of the context, with diminishing returns if it is placed at the very end.
  • Black-Box Generation Bottleneck: When paired with black-box search methods like TAP, the primary speed bottleneck shifts away from the target model's evaluation phase and onto the generation speed of the attacker LLM. The authors note that developing more efficient candidate generation techniques remains an open direction for future work.

Summary updated

BibTeX
@misc{wang2026flashrt,
  author = {Yanting Wang and Chenlong Yin and Ying Chen and Jinyuan Jia},
  title = {{FlashRT: Towards Computationally and Memory Efficient Red-Teaming for Prompt Injection and Knowledge Corruption}},
  year = {2026},
  eprint = {2604.28157},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2604.28157},
}
Figure