DEV Community

HaoJie Luo (Fone)
HaoJie Luo (Fone)

Posted on

4 Failure Modes When Giving AI Agents On-Chain Payment Access (and How ERC-4337 Fixes Them)

A lot of teams building paid AI agents start the exact same way: spin up an EOA wallet, drop the private key into an .env file on the agent server, fund it with $500 of USDC, and tell the system prompt "never spend more than $10 per task."

That works in a demo. It fails the first time a tool response contains a prompt injection, a retry loop fires twice, or someone asks how to kill the agent's access without migrating the whole treasury.

While building Agent Wallet Guard (an ERC-4337 smart-account permission stack in Solidity, Foundry, Next.js, and viem), four specific failure modes kept showing up. Here is how to design around them before going to production.

1. Mixing Owner Authority with Agent Execution

If the owner wallet and the agent share a signing key, you don't have a permission system—you have a shared password.

Instead, keep the master key with the owner and register only the agent's public address on-chain with explicit bounds (asset, cap, allowed recipients, expiration). The agent signs transactions inside its own isolated Node.js runtime. The owner never imports the agent's private key, and doesn't have to click "approve" on every routine payment.

2. Assuming Revocation Only Stops Future Signatures

A subtle edge case: what happens if the agent signs a valid UserOperation at 10:00:01, the owner revokes the session at 10:00:02, and a delayed worker or bundler submits that pre-signed operation at 10:00:05?

If revocation is only enforced in your off-chain backend, the bundler still executes the transaction. Enforcing session state inside the on-chain Guard validation means even a UserOperation signed prior to revocation is rejected when submitted to the bundler.

3. Treating On-Chain Confirmation and Backend Sync as One Step

When an owner grants a session on-chain, the UI usually needs to register that session in your application database or agent API.

If the on-chain transaction succeeds but the API call times out, a naive UI shows "Failed — Try Again." The user clicks again and pays gas for a duplicate grant transaction.

Fix: explicitly split on-chain confirmation state from API registration state. If chain confirmation succeeded, the retry button should only replay the API registration call.

4. Reusing Agent Keys After Revocation

Once a session is revoked, don't re-enable the same public key under a new window. Require rotating to a fresh agent public key on re-authorization so leaked or queued payloads from the previous lifecycle can never be replayed.


Minimal Foundry Reference & Full Stack

Top comments (0)