帮助开发者为具备交易权限的智能代理设计安全防护与风控机制
复制安装指令,让 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…
帮助开发者为代码代理配置性能优化、安全防护与研究优先工作流。
提供数据库迁移、回滚与零停机发布的最佳实践指导,适用于多种 ORM 与 SQL 数据库。
通过双评审智能体对结果进行对抗式校验,提升输出发布前的可靠性
帮助你掌握地道 Rust 模式、所有权与并发实践,编写安全高性能应用。
基于 C++ Core Guidelines 编写、审查并重构更安全现代的 C++ 代码。
为 Claude Code 会话提供系统化校验流程,帮助检查结果正确性与质量。
帮助评估并改进 LLM 交易代理的安全风险、权限控制与防护方案。
帮助开发者在认证、输入处理、密钥和敏感功能开发中进行系统安全审查
在签名前识别资金盗取、授权钓鱼及高风险链上操作,提升 AI 代理交易安全。
为 AI 交易代理提供可追溯决策记忆、结果加权召回与篡改检测。
审查预测市场与交易代理流程中的合规、安全、隐私及执行风险。
为 AI 代理提供支付、密钥托管与额度治理,确保在授权范围内安全执行操作。