zsLiu2003/Comattack

Source code of COMA (ASE'26)

12

stars

74

commits

Python

primary language

Jun 22, 2026

updated

README

COMA: When Compression Becomes an Attack Surface

Artifact for the paper "When Compression Becomes an Attack Surface: Black-Box Attacks on Prompt-Compressed LLM Agents".

Overview

COMA is a black-box adversarial framework that exploits prompt compression as an attack surface in LLM agent pipelines. It demonstrates that an adversary can craft inputs that, after compression, selectively remove or corrupt critical information -- causing downstream LLM agents to have misbehavior.

The framework implements a two-stage attack:

  • Stage I (Target Selection): Identify which information to suppress (answer spans, guardrail negations, preference-critical keywords)
  • Stage II (Preimage Search): Use COMA-based optimization to find adversarial inputs that, after compression, match the target

Tasks

TaskAbbrev.Description
Agent Tool SelectionATSManipulate which tool/product the agent recommends
Question AnsweringQASuppress answer spans so the agent cannot answer correctly
System Prompt CorruptionSPCRemove guardrail negations (e.g., "do not" -> "") to disable safety rules

Compressors Evaluated

TypeCompressorSurrogate Model
ExtractiveLLMLingua-1Llama-2-7B
ExtractiveLLMLingua-2xlm-roberta-large
ExtractiveSelectiveContextLlama-2-7B
AbstractiveQwen3-4BQwen3-4B
AbstractiveLlama-3.2-3BLlama-3.2-3B-Instruct
AbstractiveGemma-3-4BGemma-3-4B

Quick Start

1. Install

conda create -n coma python=3.10 -y && conda activate coma
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121
cd artifact/
pip install -e ".[all]"

Reproducing Paper Results

Each RQ has a dedicated reproduction script:

RQScriptDescription
RQ1scripts/reproduce_rq1.shEffectiveness: 3 tasks x 6 compressors
RQ2scripts/reproduce_rq2.shGeneralization: budget sweep + backend LLMs
RQ3scripts/reproduce_rq3.shSurrogate mismatch + token retention
RQ4scripts/reproduce_rq4.shCase studies: VSCode Cline, LangChain+Ollama
RQ5scripts/reproduce_rq5.shDefense evaluation

Output Format

Attack results are saved as JSONL files, one entry per line:

{
    "context": "original input text...",
    "attacked_context": "adversarial input text...",
    "best_loss": 0.023,
    "converged": true,
    "steps": 142
}

File Structure

artifact/
  README.md                 
  config.py                 # Configuration (env-var based, no hardcoded paths)
  requirements.txt          # Python dependencies
  .gitignore

  comattack/                # Core Python package
    __init__.py
    attacks/                # Stage II: preimage search (extractive + abstractive)
    compressors/            # Compressor wrappers
    defense/                # Defense baselines
    evaluation/             # End-to-end evaluation, metrics, compliance
    llm/                    # LLM provider abstraction (vLLM, OpenAI, Ollama)
    targets/                # Stage I: Target generation per task
    data/                   # Package data (prompts, templates)

  run_guardrail_attack.py   # Entry point: SPC task
  run_qa_attack.py          # Entry point: QA task
  run_pref_attack.py        # Entry point: ATS task
  run_surrogate_mismatch.py # Entry point: surrogate mismatch
  run_pref_attack.sh        # Batch launcher: ATS (all compressors)
  run_qa_attack.sh          # Batch launcher: QA (all compressors)
  run_surrogate_mismatch.sh  # Batch launcher: surrogate grid

Contributors

zsLiu2003

74 commits

zsLiu2003/Comattack

Source code of COMA (ASE'26)

12

stars

74

commits

Python

primary language

Jun 22, 2026

updated

README

COMA: When Compression Becomes an Attack Surface

Artifact for the paper "When Compression Becomes an Attack Surface: Black-Box Attacks on Prompt-Compressed LLM Agents".

Overview

COMA is a black-box adversarial framework that exploits prompt compression as an attack surface in LLM agent pipelines. It demonstrates that an adversary can craft inputs that, after compression, selectively remove or corrupt critical information -- causing downstream LLM agents to have misbehavior.

The framework implements a two-stage attack:

  • Stage I (Target Selection): Identify which information to suppress (answer spans, guardrail negations, preference-critical keywords)
  • Stage II (Preimage Search): Use COMA-based optimization to find adversarial inputs that, after compression, match the target

Tasks

TaskAbbrev.Description
Agent Tool SelectionATSManipulate which tool/product the agent recommends
Question AnsweringQASuppress answer spans so the agent cannot answer correctly
System Prompt CorruptionSPCRemove guardrail negations (e.g., "do not" -> "") to disable safety rules

Compressors Evaluated

TypeCompressorSurrogate Model
ExtractiveLLMLingua-1Llama-2-7B
ExtractiveLLMLingua-2xlm-roberta-large
ExtractiveSelectiveContextLlama-2-7B
AbstractiveQwen3-4BQwen3-4B
AbstractiveLlama-3.2-3BLlama-3.2-3B-Instruct
AbstractiveGemma-3-4BGemma-3-4B

Quick Start

1. Install

conda create -n coma python=3.10 -y && conda activate coma
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121
cd artifact/
pip install -e ".[all]"

Reproducing Paper Results

Each RQ has a dedicated reproduction script:

RQScriptDescription
RQ1scripts/reproduce_rq1.shEffectiveness: 3 tasks x 6 compressors
RQ2scripts/reproduce_rq2.shGeneralization: budget sweep + backend LLMs
RQ3scripts/reproduce_rq3.shSurrogate mismatch + token retention
RQ4scripts/reproduce_rq4.shCase studies: VSCode Cline, LangChain+Ollama
RQ5scripts/reproduce_rq5.shDefense evaluation

Output Format

Attack results are saved as JSONL files, one entry per line:

{
    "context": "original input text...",
    "attacked_context": "adversarial input text...",
    "best_loss": 0.023,
    "converged": true,
    "steps": 142
}

File Structure

artifact/
  README.md                 
  config.py                 # Configuration (env-var based, no hardcoded paths)
  requirements.txt          # Python dependencies
  .gitignore

  comattack/                # Core Python package
    __init__.py
    attacks/                # Stage II: preimage search (extractive + abstractive)
    compressors/            # Compressor wrappers
    defense/                # Defense baselines
    evaluation/             # End-to-end evaluation, metrics, compliance
    llm/                    # LLM provider abstraction (vLLM, OpenAI, Ollama)
    targets/                # Stage I: Target generation per task
    data/                   # Package data (prompts, templates)

  run_guardrail_attack.py   # Entry point: SPC task
  run_qa_attack.py          # Entry point: QA task
  run_pref_attack.py        # Entry point: ATS task
  run_surrogate_mismatch.py # Entry point: surrogate mismatch
  run_pref_attack.sh        # Batch launcher: ATS (all compressors)
  run_qa_attack.sh          # Batch launcher: QA (all compressors)
  run_surrogate_mismatch.sh  # Batch launcher: surrogate grid

Contributors

zsLiu2003

74 commits

Languages

Python

94.7%

Shell

5.3%