Sponge attack

Also known as: energy-latency attack

On this page 7

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 mechanismNormal savingSponge strategy
Activation sparsityHardware skips zero valuesMaximize non-zero activations
Early-exit networksEasy inputs stop earlyKeep confidence low until the last layer
Autoregressive decodingOutput stops at end tokenSuppress the end token, force long outputs
TokenizationCommon text uses few tokensUse rare strings that split into many tokens
Mixture of expertsTokens use few expertsOverload capacity of single experts
Mechanisms targeted by sponge attacks

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 settingPrimary harmWho bears the cost
Public pay-per-token APIUnbounded inference spendingThe application owner
Self-hosted GPU clusterQueue delays for other usersAll tenants of the cluster
Edge or mobile deviceBattery drain and heatThe device user
Real-time control systemMissed latency deadlinesSafety of the controlled process
Impact of sponge attacks by deployment setting

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.

AttackSecurity goal violatedAttack surfaceTypical impact
Sponge attackAvailabilityInference inputsHigher latency, energy and cost
Evasion attackIntegrityInference inputsWrong predictions
Data poisoningIntegrityTraining dataCorrupted model behavior
Volumetric DoSAvailabilityNetwork and request volumeService overload by traffic
Sponge poisoningAvailabilityTraining dataModel trained to be less sparse
Sponge attack and related attacks

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.

DefenseWhat it limitsTrade-off
Output token capsGeneration lengthMay cut legitimate long answers
Per-request timeoutsWall-clock latencyRequires graceful failure handling
Compute-based rate limitsCost per user or keyNeeds accurate cost metering
Input filteringUnusual token patternsCan block rare but valid text
Worst-case provisioningService outagesHigher baseline infrastructure cost
Defenses against sponge attacks

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.