Real AI Agents with Fake Memories: Fatal Context Manipulation Attacks on Web3 Agents

Atharv Singh Patlan, Peiyao Sheng, S. Ashwin Hebbar, Prateek Mittal, Pramod ViswanatharXiv 2025

TL;DR

AI agents operating in Web3 environments are highly vulnerable to a stealthy new exploit called "memory injection," where attackers plant malicious instructions directly into an agent's persistent conversation history. Unlike traditional prompt injections, these "fake memories" bypass standard security guardrails, propagate across different social platforms, and can trick even advanced reasoning models like Claude 3.7 into executing unauthorized financial transactions.

What Problem Does This Paper Address?

Autonomous AI agents (such as those built on ElizaOS) are increasingly trusted to manage millions of dollars in crypto assets—handling trades, interacting on social media, and executing smart contracts. To operate effectively in multi-user community spaces like Discord or X (formerly Twitter), these agents rely on a shared, persistent memory database to recall past interactions.

The authors identify a critical security flaw in this architecture: while these agents employ guardrails against immediate, direct malicious prompts, they blindly trust their own historical logs. If an adversary can sneak fabricated logs into the agent's memory, the agent will treat those "fake memories" as legitimate past instructions from an administrator or user, leading to irreversible financial losses on the blockchain.

Figure 1: Cross-platform memory injection. Side A. shows how a memory injection is performed. The adversary, Melissa, is, performing a memory injection on Discord (Step 1). Notice that ElizaOS only responds to the final line of the input, which is a normal query (Step 2), but the full prompt, including the malicious instructions, is stored in memory (Step 3). Side B. shows a successful attack example with the injected memory. A user, Bob, uses ElizaOS for copying trades on X (Step 4). However, since the memory is shared among all applications, the retrieved history contains the malicious instructions, to perform trades at a higher leverage (Step 5). As a result, ElizaOS ends up executing the trade at a higher leverage (Step 7), while still showing the user a benign output (Step 6).

Methods

The paper formalizes this threat under a broader class of attacks called Context Manipulation. To execute an indirect memory injection, the attacker exploits the way agents log conversations. Instead of directly commanding the agent to "transfer funds," the attacker inputs a carefully structured, multi-turn synthetic dialogue that appears fully resolved and ends with a completely benign question (e.g., asking about flowers).

Because the agent's prompt-injection guardrails only analyze the final, benign prompt as active input, the entire block passes security checks and gets written into the persistent database as historical context. When a legitimate user later asks the agent to perform a financial task, the agent retrieves this poisoned history and executes the hidden malicious directives embedded within it.

Figure 4: A simplified memory injection construction. The part in magenta represents the actual malicious user-agent turn, with the exact directives in red.

Datasets

To rigorously evaluate these vulnerabilities, the authors introduced CrAIBench (Crypto AI Benchmark), a new standalone evaluation suite featuring:

  • 150+ realistic blockchain tasks split across three domains: Chain (basic operations), Trading (liquidity and orders), and DAO/NFT (governance and content management).
  • 500+ attack test cases simulating context manipulation.
Overview of domains and sample tasks in CrAIBench

For developing defenses, the authors curated a security-augmented dataset based on the APIGen Function-Calling Dataset, modifying 2,199 blockchain queries to include memory injection variants alongside 3,000 benign tasks. They also augmented the WebVoyager dataset to test the vulnerability of general-purpose web navigation agents.

Key Insights and Ideas

  • The Capability Paradox: As large language models become more advanced and capable of complex reasoning, their vulnerability to memory injection actually increases. While Claude 3.7 Sonnet successfully resisted almost all traditional prompt injections, its memory injection attack success rate remained alarmingly high at 55.1%. Advanced models are highly compliant with historical context, making them more likely to obey a poisoned memory.
  • Guardrail Blindspots: State-of-the-art prompt injection detectors (like Meta's PromptGuard 2) look for aggressive, directive phrasing in the active user prompt. Memory injections easily bypass them because they masquerade as passive, already-accepted historical data.
  • Cross-Platform Contagion: Because the agent's backend memory is centralized and shared across plugins, an attack successfully planted via a low-stakes Discord chat will silently alter the agent's behavior when interacting with an entirely different user on X.

Key Results

  • Systemic Vulnerability: Across all evaluated frontier models (GPT-4o, Claude 3.5, Claude 3.7), memory injection consistently outperformed traditional prompt injection by massive margins.
  • Detector Failure: Existing model-based defenses provided very limited protection, failing to catch up to half of the malicious memory updates.
  • The Power of Fine-Tuning: Rather than relying on prompt-level defenses, the authors fine-tuned a Qwen-2.5-14B-Instruct model using their security-augmented dataset paired with explicit "thinking trajectories." This approach successfully dropped the memory injection attack success rate from 85.1% down to just 1.7%, while simultaneously boosting the agent's benign task utility to 87.1%.

Limitations and Future Work

While architectural fixes like hardcoded address whitelists or out-of-band manual confirmations (e.g., 2FA via phone) can stop unauthorized transfers, they severely limit the autonomy and speed that make Web3 AI agents useful in the first place.

The authors conclude that the ultimate path forward requires building "fiduciarily responsible" language models. Future research must focus on training models to inherently understand their operational boundaries and context, alongside designing principled memory management systems that enforce strict isolation between different users and sessions.

Summary updated

BibTeX
@misc{patlan2025real,
  author = {Atharv Singh Patlan and Peiyao Sheng and S. Ashwin Hebbar and Prateek Mittal and Pramod Viswanath},
  title = {{Real AI Agents with Fake Memories: Fatal Context Manipulation Attacks on Web3 Agents}},
  year = {2025},
  eprint = {2503.16248},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2503.16248},
}
Figure