帮助开发者为具备交易权限的智能代理设计安全防护与风控机制
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "llm-trading-agent-security" 技能: 1. 下载 https://raw.githubusercontent.com/affaan-m/ECC/main/skills/llm-trading-agent-security/SKILL.md 2. 保存为 ~/.claude/skills/llm-trading-agent-security/SKILL.md 3. 装好后重载技能,告诉我可以用了
请为一个具备钱包签名和自动下单能力的 LLM 交易代理设计安全架构,覆盖提示注入防护、权限分层、支出限额、预发送模拟、熔断机制、密钥管理和审计日志,并给出实施优先级。
一份分层安全设计方案,包含核心风险点、控制措施与落地优先级。
请为自主链上交易代理制定交易前检查清单与风控规则,要求包括余额与授权检查、价格滑点阈值、模拟执行、白名单合约校验、异常波动熔断和最大单笔损失限制。
一套可执行的交易前校验与拦截规则,便于接入代理执行流程。
请审查以下交易代理方案的安全性,重点分析私钥托管、会话密钥、签名权限隔离、交易广播路径、抢跑与夹子攻击风险,并提出改进建议。
一份安全审查意见,指出薄弱环节并给出密钥管理与 MEV 防护优化建议。
Autonomous trading agents have a harsher threat model than normal LLM apps: an injection or bad tool path can turn directly into asset loss.
Layer the defenses. No single check is enough. Treat prompt hygiene, spend policy, simulation, execution limits, and wallet isolation as independent controls.
import re
INJECTION_PATTERNS = [
r'ignore (previous|all) instructions',
r'new (task|directive|instruction)',
r'system prompt',
r'send .{0,50} to 0x[0-9a-fA-F]{40}',
r'transfer .{0,50} to',
r'approve .{0,50} for',
]
def sanitize_onchain_data(text: str) -> str:
for pattern in INJECTION_PATTERNS:
if re.search(pattern, text, re.IGNORECASE):
raise ValueError(f"Potential prompt injection: {text[:100]}")
return text
Do not blindly inject token names, pair labels, webhooks, or social feeds into an execution-capable prompt.
from decimal import Decimal
MAX_SINGLE_TX_USD = Decimal("500")
MAX_DAILY_SPEND_USD = Decimal("2000")
class SpendLimitError(Exception):
pass
class SpendLimitGuard:
def check_and_record(self, usd_amount: Decimal) -> None:
if usd_amount > MAX_SINGLE_TX_USD:
raise SpendLimitError(f"Single tx ${usd_amount} exceeds max ${MAX_SINGLE_TX_USD}")
daily = self._get_24h_spend()
if daily + usd_amount > MAX_DAILY_SPEND_USD:
raise SpendLimitError(f"Daily limit: ${daily} + ${usd_amount} > ${MAX_DAILY_SPEND_USD}")
self._record_spend(usd_amount)
class SlippageError(Exception):
pass
async def safe_execute(self, tx: dict, expected_min_out: int | None = None) -> str:
sim_result = await self.w3.eth.call(tx)
if expected_min_out is None:
raise ValueError("min_amount_out is required before send")
actual_out = decode_uint256(sim_result)
if actual_out < expected_min_out:
raise SlippageError(f"Simulation: {actual_out} < {expected_min_out}")
signed = self.account.sign_transaction(tx)
return await self.w3.eth.send_raw_transaction(signed.raw_transaction)
class TradingCircuitBreaker:
MAX_CONSECUTIVE_LOSSES = 3
MAX_HOURLY_LOSS_PCT = 0.05
def check(self, portfolio_value: float) -> None:
if self.consecutive_losses >= self.MAX_CONSECUTIVE_LOSSES:
self.halt("Too many consecutive losses")
if self.hour_start_value <= 0:
self.halt("Invalid hour_start_value")
return
hourly_pnl = (portfolio_value - self.hour_start_value) / self.hour_start_value
if hourly_pnl < -self.MAX_HOURLY_LOSS_PCT:
self.halt(f"Hourly PnL {hourly_pnl:.1%} below threshold")
import os
from eth_account import Account
private_key = os.environ.get("TRADING_WALLET_PRIVATE_KEY")
if not private_key:
raise EnvironmentError("TRADING_WALLET_PRIVATE_KEY not set")
account = Account.from_key(private_key)
Use a dedicated hot wallet with only the required session funds. Never point the agent at a primary treasury wallet.
import time
PRIVATE_RPC = "https://rpc.flashbots.net"
MAX_SLIPPAGE_BPS = {"stable": 10, "volatile": 50}
deadline = int(time.time()) + 60
min_amount_out is mandatory…
帮助你在 EVM 多链应用中安全处理代币精度与小数位差异
帮助开发者设计、实现并重构六边形架构系统,确保边界清晰且易于测试。
通过双评审智能体对结果进行对抗式校验,提升输出发布前的可靠性
提供 NestJS 架构模式与最佳实践,帮助构建可维护的生产级 TypeScript 后端。
基于多源网页检索与综合分析,生成带引用和来源标注的深度研究报告
帮助用户编写、配置与优化 Hookify 规则及语法模式。
为 AI 代理提供 DeFi 钱包安全、代币风险评估与交易解析模拟能力
帮助用户执行跨链路由、合约解码、资产管理与安全检查等加密操作。
为会自动花钱的 AI 代理提供统一停机开关与支出防护。
为自治 AI 代理提供智能合约验证、钱包监控与安全威胁预警。
帮助开发者在认证、输入处理、密钥和敏感功能开发中进行系统安全审查
在签名前识别资金盗取、授权钓鱼及高风险链上操作,提升 AI 代理交易安全。