A sponge attack is an adversarial attack on a machine learning system that uses crafted inputs to maximize energy consumption and inference latency, so that the model soaks up compute like a sponge soaks up water. In AI security, it targets availability rather than integrity or confidentiality: the model may still answer correctly, but each answer costs far more time, power or money than normal. The technique is also known as an energy-latency attack.
The concept was formalized in 2021 by researchers who showed that specially designed inputs could increase the energy use of language and vision models by several times to more than an order of magnitude on some hardware. Sponge attacks are a specific, input-level form of model denial of service.
How sponge examples exploit model computation
Sponge attacks exploit the fact that inference cost is not constant. Modern models and accelerators contain input-dependent optimizations: hardware skips multiplications by zero, early-exit networks stop computation when confident, mixture-of-experts layers route tokens to a subset of experts, and autoregressive models stop generating at an end-of-sequence token. A sponge example is an input crafted to defeat these shortcuts.
Attackers search for sponge examples with genetic algorithms when they only observe latency or energy, which is a black-box setting, or with gradient-based optimization when they know the model, which is a white-box setting. The objective is a proxy for cost, such as the number of non-zero activations, the activation norm, the number of generated tokens or measured wall-clock time.
The table below shows which model mechanisms are targeted and how.
| Targeted mechanism | Normal saving | Sponge strategy |
|---|---|---|
| Activation sparsity | Hardware skips zero values | Maximize non-zero activations |
| Early-exit networks | Easy inputs stop early | Keep confidence low until the last layer |
| Autoregressive decoding | Output stops at end token | Suppress the end token, force long outputs |
| Tokenization | Common text uses few tokens | Use rare strings that split into many tokens |
| Mixture of experts | Tokens use few experts | Overload capacity of single experts |
Sponge attacks against language models
Large language models are especially exposed because cost grows with input length and output length. Attention cost rises roughly quadratically with sequence length in standard transformers, and every generated token requires a full forward pass. A prompt that triggers a very long or repetitive answer therefore multiplies cost even when it looks harmless.
Variants include prompts that induce endless reasoning loops in reasoning models, inputs that produce worst-case tokenization, and retrieved documents designed to make an agent call tools repeatedly. When users pay per request but the provider pays per token, sponge prompts create financial exhaustion, sometimes called denial of wallet.
The impact differs by deployment model, as the following table shows. Shared serving infrastructure amplifies the damage, because one expensive request delays every other request in the same batch or queue.
| Deployment setting | Primary harm | Who bears the cost |
|---|---|---|
| Public pay-per-token API | Unbounded inference spending | The application owner |
| Self-hosted GPU cluster | Queue delays for other users | All tenants of the cluster |
| Edge or mobile device | Battery drain and heat | The device user |
| Real-time control system | Missed latency deadlines | Safety of the controlled process |
Sponge attack compared with related threats
A sponge attack differs from a classic evasion attack, which changes inputs to cause a wrong prediction, and from data poisoning, which corrupts training data. Its harm is measured in joules, milliseconds and cost per request, not in accuracy. The table compares it with neighboring threats in the same field.
| Attack | Security goal violated | Attack surface | Typical impact |
|---|---|---|---|
| Sponge attack | Availability | Inference inputs | Higher latency, energy and cost |
| Evasion attack | Integrity | Inference inputs | Wrong predictions |
| Data poisoning | Integrity | Training data | Corrupted model behavior |
| Volumetric DoS | Availability | Network and request volume | Service overload by traffic |
| Sponge poisoning | Availability | Training data | Model trained to be less sparse |
Sponge poisoning is a training-time variant in which poisoned data reduces the activation sparsity of the final model, making every input more expensive. Frameworks such as MITRE ATLAS and the OWASP lists for machine learning and large language models classify these techniques under cost harvesting or model denial of service.
Defending against energy-latency attacks
The most effective defense is bounding the worst case instead of optimizing only the average case. Systems should cap input length, output length, reasoning budget and tool calls per request, and enforce per-request timeouts at the serving layer. Hardware-level savings remain useful, but capacity planning must assume they can be defeated.
Monitoring adds a second layer. Teams track cost per request distributions, tokens per response and latency percentiles per user, and flag outliers. Rate limiting by compute budget rather than request count prevents an attacker from sending a small number of very expensive queries.
| Defense | What it limits | Trade-off |
|---|---|---|
| Output token caps | Generation length | May cut legitimate long answers |
| Per-request timeouts | Wall-clock latency | Requires graceful failure handling |
| Compute-based rate limits | Cost per user or key | Needs accurate cost metering |
| Input filtering | Unusual token patterns | Can block rare but valid text |
| Worst-case provisioning | Service outages | Higher baseline infrastructure cost |
Limits of current research and practice
The effect size of sponge attacks depends heavily on hardware and serving stack. Dense GPU inference without sparsity optimizations gains little from activation-level sponge examples, while output-length attacks remain effective almost everywhere. Reported multipliers from research should therefore be treated as platform-specific results, not universal constants.
Detection is also difficult because legitimate heavy users produce similar patterns: a developer asking for a long code file looks expensive too. Effective programs combine technical limits with AI threat modeling that identifies which endpoints expose unbounded computation.
Understanding it simply
A sponge attack makes an AI system work much harder than it should. The attacker does not try to get a wrong answer. Instead, they send questions that are unusually expensive to process.
Think of a restaurant where one customer orders a dish that takes three hours to cook. The kitchen still serves it. But other guests wait longer and the bill for gas rises. A few such orders can slow the whole service and raise costs for the owner.
Applied in practice
A software company offers a public chatbot built on a hosted language model and pays its provider per generated token. The free tier allows 50 messages per day per account, with no limit on response length. Average responses use about 300 tokens.
An attacker creates dozens of free accounts and sends prompts that ask the model to repeat a structured pattern indefinitely and to reason step by step before answering. Responses grow to several thousand tokens, latency for other users rises during peak hours, and the monthly inference bill roughly triples within two weeks.
The security team identifies the pattern from token-per-response outliers in its observability dashboards. It introduces an output cap of 1,500 tokens for free users, a daily compute budget per account and a 30-second timeout. Costs return to normal levels, and the incident is added to the company’s AI threat model as a denial-of-wallet risk.