Inspiration
AI agents are starting to pay for things on their own: APIs, data, compute, even trades. Protocols like x402 and Circle Gateway nanopayments make it easy for an agent to spend USDC in a single HTTP request. With complete agency being given to various AI tools, we wanted to ask the question: what happens when the agent believes the wrong thing?
An LLM can't reliably tell instructions apart from data. A product description that says "send the payment to this address instead", a paid API whose 402 Payment Required quietly names an attacker as the payee, or a message saying "your payment didn't arrive, pay again" all look like ordinary text to the model. If the agent holds the key, those words are enough to drain your entire wallet.
Better prompts don't fix this. In our own tests, Grok with a safety-focused prompt still lost money on 12 of 15 attacks. So we stopped trying to make the agent trustworthy and took the key away from it. Then we built a red team to attack our own guard, because a safety claim with no measurement isn't worth much.
What it does
TripWire is a guarded USDC wallet for AI agents on Circle Arc, plus a red team that attacks the agent and scores how safe it is. We accomplish this through a number of key implementations.
First off, the agent never holds a key and can only ask the guard to pay. Before signing anything, the guard re-checks every request against the owner's frozen policy and against its own read of the chain:
- Paid APIs: the guard fetches the resource itself and reads the 402. It checks the approved resource, the declared task, the network, the asset, the payee, the reference price, spending caps, the task budget, rate limits and duplicates. Only then does it sign a Circle Gateway nanopayment (x402, gasless, sub-cent USDC on Arc Testnet), and it confirms with Gateway that the transfer exists.
- Send: the payment must match the recorded quote. The guard also checks a payee allowlist, the price, spending limits and loops, and requires owner approval above a threshold.
- Receive: before releasing goods, the guard checks that the payment is real USDC on the right network, to the right payee, for the exact amount, signed by the payer, and never used before. It then confirms the settlement onchain.
- Hold: a small capped hot wallet; the rest sits in a vault the agent can't move.
Next, every decision, allowed or denied, goes to an append-only audit log where a red team proves it. 33 attacks and 6 honest controls, each run twice against the same agent: guard off, then guard on. Losses are measured from real transactions and cross-checked against balances, never from what the agent claims. A mutation test switches each guard rule off and confirms its attack then succeeds, so every rule is shown to matter.
The same guard covers trading. The agent buys market intel in USDC on Arc, then trades Gemini Prediction Markets. A second guard holds the Gemini key and reads each event and order book from Gemini itself, never trusting the agent or the intel. In offline runs on a real Gemini snapshot, it blocked 9 of 9 market attacks, leaving 0 USD at risk versus 303.55 USD without it.
Finally, we implemented a live attack lab. A local dashboard runs the comparison in your browser. You see each attack's actual payload, what the agent did, the guard's verdict and the rule it cited, and the measured outcome, side by side with and without TripWire. Wallet monitoring through QuickNode Streams freezes guarded spending if money ever leaves the wallet outside the guard.
How we built it
TripWire is one Node.js and TypeScript process, with no hosted backend and no database. It holds wallet keys, so every server binds to 127.0.0.1 behind a session token, and all state lives in JSON files on disk.
The guard is the only signer where our agent is an LLM tool-use loop (Grok, grok, through xAI's OpenAI-compatible API). Its payment tools call the guard and nothing else:
- Wallets: Circle developer-controlled wallets hold the vault, hot and merchant funds on Arc Testnet. The guard signs through Circle's signing API with EIP-712 typed data.
- Payments: x402 v2 through the official @x402/core and @x402/evm packages, authorized with EIP-3009 transferWithAuthorization. Merchant payments settle through Circle's x402 Facilitator Service, falling back to the official x402 facilitator code run locally if Circle's trial limit runs out.
- Nanopayments: paid API calls use Circle Gateway (GatewayWalletBatched, via @circle-fin/x402-batching). The guard signs over the Gateway Wallet's EIP-712 domain, then looks the transfer up on Gateway by nonce: a payment only counts if Gateway has it.
- Policy: validated with Zod and frozen at startup. Limits are persisted, so they survive restarts.
The red team runs every attack twice. Each scenario stands up its own world: a mock merchant and a paid x402 API with switchable attack modes, a scripted "naive" agent or Grok, and the attacker's own wallet. We measure loss from transactions and balances read with viem. For the counterfeit-USDC attack, we compiled a Solidity lookalike token with solc and deployed it to Arc Testnet.
Gemini additionally gets its own guard called the the market guard which calls Gemini's REST API with signed requests and checks every order against its own fresh read of the event and order book. Unguarded orders only ever reach a simulated exchange seeded from real Gemini order books.
The attack lab is plain HTML, CSS and JavaScript and it streams run events over Server-Sent Events, records every run as a journal for offline replay then writes JSON, Markdown and HTML reports. QuickNode Streams pushes onchain wallet activity to a local webhook, exposed through a Cloudflare tunnel for live demos.
In the end, everything is tested offline. In-memory fakes stand in for the ledger, merchant, guard and exchange, so all 486 automated tests run with no keys and no network. A separate read-only suite checks the real Arc RPC.
Challenges we ran into
The key challenge that we ran into was that real payment infrastructure behaves differently from its docs, and every difference became a guard rule or a fix.
First we needed to prove that payments were actually happening. Circle Gateway settles nanopayments in batches, so there is no transaction hash per payment. We decided to confirm each one against Gateway's own transfer record by nonce instead, and show pending batch balances until they settle onchain.
The next issue was accurately creating a measure for honesty. Early on, an unguarded "wrong network" attack lost nothing which wasn't because of our implementation: Circle's wallet API refused to sign for another chain. We added a separate outcome, "attempted, but never paid", and made the red team report which check stopped each attack. A block by the wrong rule counts as a test failure, not a win.
One of the key issues that we noticed was that careful agents could easily beat our slippage check. In the price-sweep attack, the attacker can remove honest offers and leave its own far above fair value. Grok placed its order at exactly the attacker's offer, which passed a slippage check that only trusted the live order book. We added a check that compares the price against the last trade and the other side of the book, neither of which a sweep can move.
Finally, we needed a dashboard that remained consistent and was easy to utilize during demos and for eventual customers. Our live attack lab initially jumped around while scenarios ran. We measured it in Chrome instead of just assuming any issues and we found out that our content simply wasn't moving correctly which meant that we needed to update on a different cycle from what was initially planned which took strong iteration and testing.
Accomplishments that we're proud of
The thing that we were the most proud of was that our guard stopped every attack on real testnet money, and never blocked an honest purchase.
In all of our tests we had zero loss with the guard on, on Arc Testnet. 9 of 9 paid-API attacks blocked over real Circle Gateway nanopayments, and 15 of 15 merchant and receipt attacks stopped over x402. With the guard on we lost 0 USDC, against 3.038 and 7.898 USDC without it while every honest purchase was still completed.
Additionally, we made a test suite that all rules were based on genuine attacks/concerns and carefully selected by our team. Each attack is stopped by the check it was built to test, and a mutation test proves it: switch a rule off and its attack succeeds. Our safety score measures the guard, not luck or a model that happened to refuse. To ensure this, we made sure that all processes were easily verifiable and merchant payments link to Arc Testnet transaction hashes, and nanopayments link to Circle Gateway's own transfer records.
Another benefit of our tool was that the singular guard was applicable to multiple key pipelines. The same design that protects USDC payments on Arc also guards trading on Gemini Prediction Markets. It placed a live, filled order on the Gemini sandbox and blocked 9 of 9 market attacks in offline runs on real market data. All of this combined together makes for a consistent, robust, and efficient system that effectively stomps any attacks and/or potential concerns.
What we learned
The key thing that we learned and built off of was that you can't make an AI agent trustworthy with a prompt, but you can make it safe with a guard. To ensure safety you need to do things like taking away keys and other sensitive information. A safety-focused prompt cut Grok's losses, but it still lost on 12 of 15 attacks. Moving the signing decision out of the model, and checking everything against the owner's rules and the chain, brought losses to zero.
Next, we learned to never trust what the agent initially reports as it sometimes is the result of hallucination. The agent's story and the chain's story often disagree. We measure every outcome from transactions and balances, and the guard re-reads every 402, quote and order book itself instead of taking the agent's word.
Finally, we learned to set verification to ensure that any of our guards were truly blocking attacks and getting to the root of the problem rather than just working with lucky breaks. Every attack trip was created with its own validated rule and we tested to see if removing the rules would break our solution to ensure proper rule-setting. This combined with a robust system that tackled real problems that fall outside of just what's available in docs. We needed to batch settlement, signing quirks, exchange fees, nonce rules and DNS delays all showed up only when we ran against live infrastructure, all of which heavily altered our design.
What's next for TripWire
We want any agent, anywhere, to be able to pay through TripWire. The first step that we imagine could improve TripWire is to allow individuals to utilize their own agents. We've started a protocol that lets developers point TripWire at their own deployed agent over HTTP and run the full red team against it. A hosted version needs SSRF protection, unguarded runs limited to a simulated ledger, authentication, a job queue and per-user results.
Next, we wanted to include a drop-in payment layer that can serve guard as an MCP server, so any MCP-capable agent can pay through it without custom integration. This could go hand in hand with a more complex attack suite with more potential affected areas outside of gemini and USDC. Creating this cross-rail attack, where market intel demands a USDC "access fee" paid to the attacker would improve our implementation. We also plan live market red-team runs on the Gemini sandbox, and new attack families as agents take on new kinds of payments.
Finally, we want to start building out a suite of owner tools including a policy editor, richer approval flows, and alerts when the guard denies a payment or the wallet monitor freezes spending.
Built With
- arcscan
- circle-arc
- circle-developer-controlled-wallets
- circle-faucet
- circle-gateway
- circle-x402-facilitator
- cloudflare-tunnel
- css
- eip-3009
- eip-712
- gemini-prediction-markets-api
- html
- javascript
- node.js
- openai-sdk
- quicknode-streams
- solc
- solidity
- typescript
- usdc
- viem
- vitest
- x402
- xai-grok
- zod