DeFi 安全指南:AI 时代如何有效防御黑客攻击?

marsbitPublished on 2026-04-28Last updated on 2026-04-28

撰文:sysls

编译:AididiaoJP,Foresight News

引言

在了解大量 DeFi 协议黑客攻击事件,让我对「国家行为体」产生了恐惧。他们技术精湛、资源充足,并且玩的是极度长期的游戏;这些超级反派专注于梳理你协议和基础设施的每一个角落寻找漏洞,而普通协议团队的注意力却被分散在六七个不同的业务方向上。

我并不自称是安全专家,但我在高风险环境中领导过团队(包括军队和高额资金的金融领域),在思考和规划应急预案方面经验丰富。

我真心相信,只有偏执者才能生存。没有团队会一开始就想着「我要对安全采取漫不经心、敷衍了事的态度」;然而黑客攻击还是发生了。我们需要做得更好。

AI 意味着这次真的不同了

(数据来源:https://defillama.com/hacks)

黑客攻击并不罕见,但频率明显在增加。2026 年第一季度是有记录以来 DeFi 黑客攻击数量最多的季度,而第二季度才刚刚开始,却已经有望打破上一季度的纪录。

我的核心假设是:AI 大幅降低了寻找漏洞的成本,并极大扩展了攻击面。人类需要好几周时间才能梳理一百个协议的配置寻找错误配置;而最新的基础模型只需几个小时就能完成。

这应该彻底改变我们思考和应对黑客攻击的方式。那些习惯于 AI 变得强大之前安全措施的老协议,正越来越面临被「秒杀」的风险。

用表面与层级思考

(数据来源:https://defillama.com/hacks)

黑客攻击的表面面积实际上可以归结为三个:协议团队、智能合约与基础设施、用户信任边界(DSN、社交媒体等)。

一旦确定了这些表面,就叠加防御层:

  • 预防:如果严格执行,就能最大限度降低被利用概率的流程。
  • 缓解:预防失败时,限制损害程度。
  • 暂停:没有人能在巨大压力下做出最佳决策。一旦确认攻击,就立即启动总杀开关。冻结能阻止进一步损失,并争取思考空间......
  • 夺回:如果你失去了对有毒或被攻破组件的控制,就抛弃并替换它们。
  • 恢复:夺回你失去的东西。提前规划好联系能够冻结资金、撤销交易并协助调查的机构合作伙伴。

原则

这些原则指导我们实施各层防御的具体行动。

大量使用前沿 AI

大量使用前沿模型 AI 来扫描你的代码库和配置,寻找漏洞,并在大范围表面上进行红队测试:尝试在前端寻找漏洞,看它们是否能触达后端。攻击者会这么做。你能通过防御性扫描发现的,他们的进攻性扫描早就发现了。

使用 pashov、nemesis 等技能,以及 Cantina (Apex) 和 Zellic (V12) 等 AI 平台,在提交完整审计前快速扫描代码库。

时间与摩擦是好的防御

对任何可能造成损害的操作增加多步流程和时间锁。你需要足够的时间在发现异常时介入并冻结。

过去反对时间锁和多步设置的理由是会给协议团队带来摩擦。现在你不用太担心这一点:AI 可以轻松在后台点击通过这些摩擦。

不变量

智能合约可以通过写下不可变的「事实」来进行防御性构建:如果这些事实被打破,整个协议逻辑就会崩溃。

你通常只有少数几个不变量。要谨慎地将它们提升到代码层面;在每个函数中强制执行多个不变量会变得难以管理。

权力平衡

许多黑客攻击源于被攻破的钱包。你需要这样的配置:即使多签被攻破,也能迅速遏制损害,并将协议带回治理可以决策的状态。

这需要在 治理(决定一切)和 救援(恢复可治理稳定性的能力,但不能替换或推翻治理本身)之间取得平衡。

总会出问题

从一开始就假设:无论你有多聪明,你都会被黑。你的智能合约或依赖项可能会失效。你可能会遭受社会工程攻击,新升级可能会引入你没有预料到的漏洞。

一旦你这样思考,限制损害的速率限制和锁定协议的断路器就会成为你最好的朋友。将损害限制在 5-10%,然后冻结,再规划你的应对方案。没有人能在枪林弹雨中做出最佳决策。

最好的规划时间就是现在

在被黑之前就思考你的应对方案。尽可能将流程编码化,并与团队一起演练,这样你就不会在冲击发生时手忙脚乱。在 AI 时代,这意味着拥有能够尽可能快地呈现大量信息的技能和算法,并以摘要和长形式分享给你的核心圈子。

你不需要完美,但你必须生存。没有系统从第一天起就是坚不可摧的;通过多次迭代,你会通过吸取教训变得反脆弱。

没有被黑的证据,并不等于你不会被黑。最大舒适点往往就是最大危险点。

预防措施

智能合约设计

一旦确定了不变量,就将它们提升为运行时检查。仔细思考哪些不变量实际上值得强制执行。

这就是 FREI-PI(Function Requirements, Effects, Interactions, Protocol Invariants)模式:在每个触及价值的函数结束时,重新验证该函数承诺要维护的王冠不变量。许多通过 CEI(Checks-Effects-Interactions)的抽干攻击(闪电贷三明治、预言机辅助清算 grief、跨函数偿付能力抽干)都能被函数结束时的不变量检查捕获。

良好的测试

状态化模糊测试(Stateful fuzzing)会针对协议的完整公开表面生成随机调用序列,并在每一步断言不变量。大多数生产环境中的漏洞都是多笔交易的,状态化模糊测试几乎是唯一可靠的在攻击者之前发现这些路径的方法。

使用不变量测试来断言属性在模糊器能生成的所有调用序列中都成立。辅以形式验证,它能证明属性在所有可达状态下都成立。你的王冠不变量绝对应该接受这种处理。

预言机和依赖项

复杂性是安全的敌人。每一个外部依赖都会扩展攻击面。如果你在设计原语,就把信任谁和信任什么的选择权交给用户。如果无法移除依赖,就对其进行多元化,让没有任何单一故障点能摧毁你的协议。

将审计范围扩展到模拟预言机和依赖项可能失败的方式,并对如果它们失败可能造成的灾难程度施加速率限制。

最近的 KelpDAO 漏洞就是一个例子:他们继承了 LayerZero 默认的 requiredDVNCount=1 配置,而这个配置在他们的审计范围之外。最终被攻破的是审计范围之外的链下基础设施。

表面攻击

DeFi 中的大多数表面攻击已经被列举出来。逐一检查每个类别,问它是否适用于你的协议,然后实施针对该攻击向量的控制。培养红队技能,让你的 AI 智能体主动在你的协议中寻找漏洞;这在当下已经是基本要求。

拥有原生救援能力

在基于投票的治理中,权力最初集中在团队的多签中,需要时间才能扩散。即使代币分布广泛,委托也往往会将权威集中到少数钱包(有时甚至是 n=1)。当这些钱包被攻破时,游戏就结束了。

部署「守护者钱包」,赋予其严格狭窄的授权:它们只能暂停协议,并且在 >=4/7 阈值下,可以在极端情况下将受损委托轮换到预定义的替换钱包。守护者永远不能执行治理提案。

这样,你就拥有了一个始终能恢复可治理稳定性的救援层,而不会拥有推翻治理的权力。失去 >=4/7 守护者的最坏情况概率极低(考虑到持有者多样性),并且一旦治理成熟且分散,这一层可以逐步淘汰。

钱包与密钥拓扑

多签钱包是基本要求,最低 4/7。没有单个人控制所有 7 把密钥。频繁轮换签名者,并且要悄无声息地进行。

密钥永远不应与日常使用的设备交互。如果你用签名设备浏览互联网、收发邮件或打开 Slack,就当这个签名者已经被攻破了。

拥有多个多签,每个有不同的用途。假设至少有一个完整多签会被攻破,并从那里开始规划。没有任何单个人应该拥有足够控制权来攻破协议,即使在极端情景下(绑架、酷刑等)也是如此。

考虑赏金

如果你有资源,相对于协议 TVL 设置一个高额漏洞赏金是非常值得的;即使你是相对较小的协议,漏洞赏金也应该尽可能慷慨(例如最低 7-8 位数)。

如果你面对的是国家行为体的攻击,他们可能不会谈判,但你仍然可以参与「白帽安全港」计划,授权白帽代表你行动以保护资金,并收取漏洞金额的一定百分比作为费用(实际上是由存款人支付的赏金)。

找到好的审计师

我之前写过,随着大语言模型变得更聪明,聘请审计师的边际价值会下降。我仍然坚持这一观点,但我的看法有所转变。

首先,好的审计师会走在曲线前面。如果你正在做一些新颖的东西,你的代码及其漏洞可能不在训练数据中,单纯增加 Token 数量尚未被证明能有效发现新型漏洞。你不希望成为独特漏洞的第一个样本点。

其次,一个被低估的好处是:聘请审计师是在用他们的声誉做担保。如果他们签字批准而你被攻击,他们会受到强烈激励来帮忙。与那些职业就是做安全的人建立关系,是巨大的优势。

践行操作安全

将操作安全视为成功指标。进行钓鱼演练;聘请(可信的)红队尝试对团队进行社会工程攻击。准备备用硬件钱包和设备,以便在需要时替换整个多签。你不希望在 D-day 时匆忙去购买这些东西。

缓解措施

你的退出路径就是损失上限

任何将价值移出协议的路径的封顶大小,就是该路径被漏洞滥用时的最大理论损失。简单来说:没有每区块上限的铸币函数,就是给任何无限铸币漏洞开了一张空白支票。没有周上限的赎回函数,就是给任何资产余额损坏开了一张空白支票。

谨慎思考你的退出路径的明确数值。这个数字需要在你愿意承受的最大损害与用户最极端 UX 需求之间取得平衡。如果出了问题,这就是能让你免于彻底毁灭的东西。

白名单(和黑名单)

大多数协议都有可以被调用、交易或接收的列表,以及用户绝对不能做的列表。即使是隐式的,这些也是信任边界,应该被正式化。

将其正式化让你可以设置两阶段 setter,制造有意义的摩擦。攻击者首先需要添加到白名单(和 / 或从黑名单移除),然后才能行动。同时拥有两者意味着攻击者偷偷引入新向量时,必须同时攻破两个流程:市场必须被允许(集成 / 上市),并且该行动不能被禁止(安全审查)。

夺回

算法监控

如果没有人监控,杀开关就毫无用处。链下监控器应该持续监控不变量,一旦出现问题就算法化地升级警报。最终路径应该到达守护者多签的人类手中,并提供足够上下文,让他们在几分钟内做出决策。

停下来重新校准

如果你中枪了,你要先止血,而不是在倒计时中做决策。对于协议来说,这就是杀开关(也要在 UI 上体现):一个按钮就能在一笔交易中暂停所有价值移动路径。准备一个「暂停一切」的辅助脚本,枚举所有可暂停组件并原子化地暂停它们。

只有治理才能解除暂停,因此杀开关不能暂停治理合约本身。如果守护者层可以暂停治理合约,被攻破的守护者层就能永久死锁恢复流程。

启动你的战情室

冻结、止血,然后把你信任的所有人(小圈子,提前约定)拉到一个沟通频道。你希望表面小一些,以防止信息泄露给攻击者、公众或恶意套利者。

为团队需要的角色进行角色扮演:一个做决策的;一个熟练执行防御脚本和暂停操作的操作员;一个重构漏洞并识别根本原因的人;一个与关键方沟通的人;一个记录观察、事件和决策时间线的人。

当每个人都知道自己的角色并进行过演练时,你就能按流程反应,而不是在最坏的时刻手忙脚乱。

考虑连锁反应

假设你的攻击者非常老练。第一个漏洞可能是诱饵,或是为后续攻击埋下的种子。攻击可能是在诱使你做完全错误的事情,从而触发真正的漏洞。

暂停必须经过充分研究、完全可控,且本身不可被利用。暂停应该是全协议冻结:你不希望被诱导暂停某个组件,反而打开了另一个。一旦你找到根本原因和攻击向量,就要探索相邻暴露的表面和连锁反应,并一次性全部修复。

轮换预先承诺的继任者

只有提前知道继任者,轮换才是安全的。我喜欢预先承诺的继任者注册表这个想法:它让攻击者更难将健康的守护者 / 治理钱包替换为被攻破的。这与缓解措施中的「白名单 / 黑名单」理念一致。

为每个重要角色注册一个继任者地址。紧急层唯一能执行的轮换原语是「将角色 X 替换为其继任者」。这也让你可以在和平时期评估继任者:慢慢来,做尽职调查,飞过去和提出请求的人见面。

在升级前谨慎测试

一旦你确定了根本原因和影响范围,你就需要发布升级。这可能是你将要部署的最危险的代码:在压力下编写,针对已经证明自己足够了解你的协议并找到漏洞的攻击者。

在没有充分测试的情况下延迟发布。如果没有时间进行审计,就依靠白帽关系,或者在部署前设置一个 48 小时竞赛,获得一次新鲜的对抗性审查。

恢复

快速行动

被盗资金有半衰期;一旦漏洞落地,它们会迅速进入洗钱管道。提前准备好 Chainalysis 等链上分析提供商,以便实时标记攻击者的地址集群,并在它们跨链跳跃时通知交易所进行标记并追踪。

提前准备一份集中交易所合规部门、跨链桥管理员、托管人管理员以及其他拥有管理权限可以冻结跨链消息或特定在途存款的第三方名单。

谈判

是的,这很刺痛,但你仍然应该尝试与攻击者对话。生活中的很多事情都可以通过谈判解决。提供有时限的白帽赏金,并公开声明如果在截止日期前全额归还资金,将不采取法律行动。

如果你面对的是国家行为体,你可能运气不佳,但你可能面对的是不太老练的攻击者,他们只是找到了利用你的方法,并且想以较低成本脱身。

在这样做之前,一定要有法律顾问在场。

结论

黑客攻击不会停止,随着 AI 变得更聪明,攻击只会更多。仅仅让防御者「变得更敏锐」是不够的。我们需要使用攻击者使用的相同工具,对我们的协议进行红队测试,持续监控,并对损害设置硬性限制,以便我们能在最坏的情况下生存下来。

Trending Cryptos

Related Reads

GPT-5.6 Countdown: Abandon the Illusion of a Single API, Computational Iteration Can't Outpace a Single Page of Compliance

In mid-June, three seemingly independent industry events—the compliance-driven throttling of Fable 5, the open-sourcing of GLM-5.2, and the leaked release timeline for GPT-5.6—are pushing the global AI industry toward a watershed moment. These shifts signal a fundamental restructuring of the industry's underlying logic. First, **"usability" has substantially overtaken "advanced capabilities"** as the primary weight, pushing the global large language model (LLM) supply chain into a "dual-track" phase of controlled closed-source and local open-source coexistence. Second, **the competitive moats of closed-source giants are shifting**. Their technical focus is moving from "language intelligence" toward "spatial intelligence (world models)"—a domain heavily reliant on computing power. Third, faced with常态化 transnational compliance risks, **a "model-agnostic" decoupled design has become a survival necessity for application-layer developers to maintain business continuity.** The article details how Anthropic's Fable 5, despite its advanced engineering feats, was restricted for non-U.S. citizens within 72 hours of launch, highlighting how geopolitical compliance can instantly limit even the most advanced models. In response, the open-source camp, exemplified by Zhipu AI's MIT-licensed GLM-5.2, is gaining market share by offering stable performance improvements and significant cost advantages (up to 70% savings for enterprises), while achieving full adaptation with domestic semiconductor platforms. Meanwhile, closed-source leaders like OpenAI are pivoting. The anticipated GPT-5.6 reportedly shifts focus from language to spatial intelligence and world models, aiming to rebuild a generational gap in areas like 3D understanding, simulation, and industrial design that demand immense compute. The core conclusion is that the LLM supply chain's logic has changed. Enterprises must now evaluate infrastructure based on a composite of technical performance and policy compliance. For developers, complete reliance on a single closed-source API poses unacceptable risk. Implementing a truly model-agnostic architecture—enabling swift switches to compliant, locally deployable open-source alternatives—is no longer just good practice but a fundamental baseline for business continuity.

marsbit43m ago

GPT-5.6 Countdown: Abandon the Illusion of a Single API, Computational Iteration Can't Outpace a Single Page of Compliance

marsbit43m ago

Is the 'Token Subsidy War' Among AI Giants Almost Over?

The article discusses the ongoing "token subsidy war" among AI giants like OpenAI and Anthropic, questioning whether it's nearing its end. It reveals that current AI subscription prices are heavily subsidized, with some plans offering tokens at up to 70 times the actual cost to attract and retain heavy users, especially developers and enterprises. This strategy mirrors past internet-era subsidy battles, but with a key difference: AI tokens lack "lock-in" effects. Unlike ride-hailing or food delivery apps, users can easily switch between AI providers as APIs become standardized, making it difficult for companies to raise prices post-subsidy. The piece highlights a structural asymmetry in the competition. Giants like Google, with massive advertising revenue, can afford to subsidize tokens indefinitely, akin to using "tokens as a weapon." In contrast, venture-backed companies like OpenAI and Anthropic face pressure to become profitable, especially as they approach IPO. The article cites Google Ventures founder Bill Maris, who suggests Google could slash token prices by 80%, putting immense pressure on competitors. Two potential endgames are presented: the "internet service" model (subsidize, monopolize, then raise prices) and the "utility" model (tokens become a standardized, low-margin commodity like electricity). Given the low switching costs, the latter seems more likely. The competition may not have a single winner but could instead accelerate AI's evolution into a foundational, infrastructure-level technology, akin to a public utility. For now, users continue to benefit from heavily subsidized token costs.

marsbit1h ago

Is the 'Token Subsidy War' Among AI Giants Almost Over?

marsbit1h ago

Beyond the Stadium: The Profitable Games Surrounding the World Cup

"Beyond the Pitch: The Profit Game Around the World Cup" The FIFA World Cup transcends being a sporting spectacle, evolving into a massive global arena for speculation and profit-seeking. The 2026 tournament has amplified this dynamic, creating a multi-layered ecosystem of financial opportunism alongside the football. **Prediction markets** have surged into the mainstream. Platforms like Polymarket and Kalshi saw trading volumes for World Cup contracts soar, attracting new users with their financial trading model and high-profile, chain-based wealth stories that overshadow traditional sports betting in terms of growth and narrative. However, **traditional sportsbooks** remain the dominant force, leveraging established user habits, legal markets, and comprehensive product offerings to handle the vast majority of speculative wagers, with projections suggesting record-breaking betting volumes. Capital markets also react. **"Concept stocks"** in countries like South Korea and Japan experience volatile price swings based on team performance and anticipated fan spending on items like chicken, beer, and viewing parties, effectively becoming a stock market reflecting fan sentiment. The **ticket resale market** has become a sophisticated arena for arbitrage. Prices fluctuate wildly based on team draws and star power, with sellers sometimes listing tickets they don't yet own in a practice akin to short-selling, while FIFA's own "Right to Buy" tokens add another layer of speculative trading. **Collectibles and merchandise** offer another avenue. Panini sticker albums, with their inherent scarcity and nostalgic value, can become high-value collectibles. Limited-edition or locally themed jerseys command significant premiums on secondary markets, and even counterfeit vendors profit from fans' desire for affordable match-day identity. The **cryptocurrency** space has seen a frenzy of speculative, unauthorized World Cup-themed meme coins on chains like Solana. These tokens, often exploiting team names and player imagery, experience extreme pump-and-dump cycles, creating stories of massive gains for a few early entrants and steep losses for many others. Finally, an entire industry thrives on **providing information and tools** to other speculators. Developers create platforms like SeatSidekick to track ticket inventory and prices, while paid Telegram groups and subscriptions sell betting tips and predictions, monetizing the widespread desire for an informational edge. In essence, the World Cup has become a compressed, global laboratory for speculation. While the games determine champions on the field, a parallel, complex network of financial transactions—spanning prediction contracts, bets, stocks, tickets, collectibles, crypto, and information services—settles its own scores in the global market.

marsbit1h ago

Beyond the Stadium: The Profitable Games Surrounding the World Cup

marsbit1h ago

How Does Codex Use a Computer? Three Entry Points and Permission Boundaries

This article explains the three primary methods for Codex to interact with a computer, each with distinct use cases, permission boundaries, and trust levels. **1. Computer Use:** This offers the broadest access, allowing Codex to visually control and interact with the graphical user interface of authorized macOS/Windows apps, system settings, and even iOS simulators. It's ideal for tasks lacking APIs or structured tools, such as operating legacy software or multi-app workflows. However, it's the slowest method and has the widest permission scope, requiring careful supervision for sensitive actions. **2. Chrome Extension:** This grants Codex access to the user's logged-in Chrome browser state, including cookies, profiles, and open tabs. It's best for tasks requiring user identity across websites like Gmail, LinkedIn, Salesforce, or internal dashboards. Its key advantage is multi-tab control for complex workflows. While more powerful for browser-based tasks than Computer Use, it carries higher sensitivity as actions are performed under the user's identity. **3. In-App Browser:** This is a browser isolated within the Codex thread, separate from the user's personal browsing data. It excels in web development and debugging scenarios—previewing local servers, testing responsive layouts, or annotating designs directly on the page. Its isolation is a strength for development but a limitation for tasks requiring login sessions. The core principle is to choose the narrowest, safest, and most structured interface for the task. Use plugins or MCPs first, resort to visual control (Computer Use) only for GUI-dependent tasks, employ the Chrome extension for identity-reliant browser work, and prefer the In-App Browser for isolated development. **Appshots** are clarified as a fourth, complementary tool for *inputting* context—capturing a screenshot of a window to point Codex to something—rather than a method for Codex to *act*. Together, this layered approach highlights a key to AI agent productization: not granting unlimited permissions, but constraining them within clear boundaries for specific tasks while preserving user oversight.

marsbit3h ago

How Does Codex Use a Computer? Three Entry Points and Permission Boundaries

marsbit3h ago

Trading

Spot
Futures

Hot Articles

Discussions

Welcome to the HTX Community. Here, you can stay informed about the latest platform developments and gain access to professional market insights. Users' opinions on the price of AI (AI) are presented below.

活动图片