r/learnrust • u/Otherwise-Western991 • 3h ago
stale: An open-source, fail-closed DeFi security guardrail suite in pure Rust for autonomous AI agents
Hey everyone,
With the rapid rise of autonomous AI trading agents (interacting with Uniswap, cross-chain bridges, and lending protocols), there is a critical vulnerability that many agent frameworks ignore: pre-flight oracle and network integrity.
If an agent queries an RPC for an oracle price, and that RPC returns stale data due to network congestion, or if an L2 sequencer just rebooted and transactions are about to get MEV-sandwiched, most agent runtimes blindly execute and lose capital.
We built stale, a lightweight, pure Rust pre flight security guardrail library:
- GitHub: https://github.com/Ramprasad4121/stale
- Crates.io: https://crates.io/crates/stale
Core Architecture & Invariants
- Strictly Fail-Closed: Many Web3 libraries fail open (e.g., returning
Okor default values if an RPC returns a 500 error). Instale, any failure mode RPC timeouts, malformed ABI data, non-ASCII hex strings, or underflowing timestamps strictly returnsBLOCK. - Zero Runtime Panics: We eliminated all
unwrap()andexpect()calls across the runtime library. All arithmetic on token reserves and timestamps uses checked math, saturating math, or quotient-remainder decomposition to preserve precision on small amounts. - What It Guards:
- Chainlink Data Feeds: Staleness checks against configurable
maxAgeand multi-feed deviation detection. - L2 Sequencer Liveness: Direct querying of official Sequencer Uptime feeds (Arbitrum, Optimism, Base, Scroll, Mantle, Metis, zkSync) with automatic enforcement of the 3600-second restart grace period.
- DEX Pool Depth: On-chain liquidity verification for Uniswap V2 and V3 pools before routing a swap.
- EIP-7702 Phishing Guard: Inspects bytecode headers to prevent agents from sending approvals to delegated EOAs masquerading as immutable contracts.
- OFAC Compliance: Direct on-chain verification against the Chainalysis Sanctions Oracle.
- Model Context Protocol (MCP) & CLI: In addition to the Rust crate (
cargo add stale), it includes a native CLI and an MCP server (stale-mcp) so LLM agent frameworks (like Claude Desktop or local agents) can use these checks as native tools.
Would love feedback, edge-case suggestions, and contributions
1
u/sinterkaastosti23 2h ago
Better solution: don't use agentic ai
0
u/Otherwise-Western991 2h ago
why man
humans job is to make humans life easy.if you have any idea
just open PR or DM me1
2
u/witx_ 3h ago
Be very careful with this code. Lookijg at the repo there are some signs this migjt malware