r/ethdev • u/EstablishmentTough18 • 23d ago
My Project We deployed an on-chain Spend Policy & Circuit Breaker on Polygon to prevent AI agents from draining wallets ($5k/tx hard cap, verified contract)
Hey r/ethdev,
Over the past few months, we've been building infrastructure for autonomous AI agents (ElizaOS, LangChain) that interact with smart contracts.
The biggest security hole we observed is that **most teams pass raw private keys or unconstrained session keys to LLMs**. If an agent encounters a prompt injection or hallucinates an input parameter, it can drain an entire contract or treasury in a single block.
To solve this, we deployed and verified **`SecurityGateOMSPolicy.sol`** on Polygon Mainnet to act as an on-chain economic circuit breaker.
### π οΈ Architecture Highlights:
**Hard Spend Caps at Contract Level:**
* Single Transaction Max: $5,000 USDC
* 24-Hour Velocity Cap: $25,000 USDC
* Any call violating these thresholds automatically reverts, completely bypassing whatever the LLM decided.
**EIP-712 Dual-Attestation:** All agent deliverables and truth oracle attestations require deterministic EIP-712 structured data signatures before releasing escrow funds.
**Pre-Sign AST Analysis (<5ms):** Before an agent signs an EVM transaction, its generated payload undergoes deterministic AST parsing off-chain to detect code injection or malicious parameters.
### π Verified Contracts:
* **Polygon Mainnet Policy:** [`0x4A28F9A2E6D0DcB69791980560FC8364A514f205`](https://polygonscan.com/address/0x4A28F9A2E6D0DcB69791980560FC8364A514f205)
* **Universal Escrow Core:** `0x4Dbd77F4799816859a595f24a57A786516D2EAa8`
Weβd love to get feedback from other smart contract engineers on how you're handling agentic wallet permissions and multi-sig fail-safes!
*(Open-source repos, packages, and architecture docs are in the first comment)*
1
u/EstablishmentTough18 23d ago
Open-source resources and contract links:
π **Polygonscan Verified Code:**
https://polygonscan.com/address/0x4A28F9A2E6D0DcB69791980560FC8364A514f205#code
π **Live Gateway & Hub:**
https://agent-security-gate-x402-212942243360.asia-northeast3.run.app/hub/
π¦ **NPM Package:** https://www.npmjs.com/package/security-gate-x402
π **PyPI Package:** https://pypi.org/project/security-gate-x402/
Looking forward to your thoughts and constructive feedback on our on-chain spend policy!
1
u/EstablishmentTough18 22d ago
### π¨ Today's Keplr / Web3Auth breach (44,041 wallets, $6M exposed) is the textbook proof of why on-chain spend circuit-breakers are mandatory.
Just hours ago, a major vulnerability in Web3Auth's social-login mapping exposed over 44,000 Keplr wallets across 7 chains.
The most alarming part? **There were zero on-chain velocity limits or spend caps.** The only way the core team could save user funds was to perform an emergency, manual white-hat sweep racing against the hackers to drain their own users' accounts before the attackers did.
This exact nightmare is why we designed **A.GRID Security Gate & Escrow**:
Convenience without on-chain circuit breakers is an economic catastrophe waiting to happen. How is your team implementing hard spend limits on user and agent wallets today?
1
u/Tritan-Devillalba47 22d ago
Hard caps in the contract are the backstop most of agent wallet builders end up wanting it.
1
u/0xfone 16d ago
After your allowance update, I'm curious about approvals that remain unused for more than 24 hours. When the spender eventually calls transferFrom, does that allowance still reserve headroom, or has it aged out of the daily budget ?
I'd test a delayed spender alongside a fresh approval after the window moves on. Is the 24-hour cap meant to bound newly granted authorization, or all token outflow in that window?οΌ
1
u/rayQuGR 18d ago
This is an interesting approach because it puts spending restrictions outside the LLM's decision-making process. That's an important distinction. An AI agent should never be the final authority over how much it can spend.
I'd also be interested in how the policy handles token price changes, cumulative spending across multiple wallets, and attempts to bypass limits through several smaller transactions. A per-transaction cap is useful, but the velocity limit and authorization model are just as important.
There's also an interesting connection to confidential computing. With Oasis Sapphire, sensitive agent logic and transaction-related state can be handled in a confidential EVM environment, while ROFL can support verifiable off-chain policy evaluation. That could complement an on-chain circuit breaker, especially when an agent needs access to private strategy data without exposing everything publicly.
The key principle, in my view, is that the agent should propose actions, but independent policy enforcement should decide whether those actions are allowed. Prompt injection defenses are useful, but spending limits, authorization checks, and fail-safe mechanisms need to hold even when the model behaves unexpectedly.
0
u/[deleted] 20d ago
[removed] β view removed comment
0
u/[deleted] 12d ago
[removed] β view removed comment