Building secure Uniswap v4 hooks

2026年7月30日

AI 摘要 AI 生成,可能有误

本文探讨了 Uniswap v4 钩子(hooks)中的安全风险,并通过 Cork(约 1200 万美元)和 Bunni(840 万美元)的攻击事件说明,重大损失主要源于应用层特定的授权与记账缺陷,而非核心协议或 PoolManager 本身的缺陷。作者借鉴 Trail of Bits 的审计报告和公开的漏洞利用报告,总结出七种反复出现的失效模式——包括缺失调用者检查、信任攻击者创建的资金池、记账错误、钩子逻辑放置不当、权限位不匹配以及钩子回退阻塞用户操作——作为面向开发者的安全开发清单和面向审计人员的审查指南。

Uniswap v4 hooks let developers add custom behavior to pools, including dynamic fees, custom accounting, and external integrations. This flexibility moves some security responsibilities into application and hook code.

The Cork and Bunni exploits are two app-level incidents that show what can go wrong in that code. Together, they account for more than $20M in losses. Neither incident stemmed from a flaw in the Uniswap v4 core protocol or the PoolManager; both arose from application-specific authorization and accounting logic built around hooks.

After analyzing dozens of findings from Trail of Bits audits (including our Uniswap v4-core security review), public reports from other firms, and the Solodit database, I’ve identified seven recurring failure patterns in application and hook code, including missing caller checks and accounting bugs that still satisfy the PoolManager’s settlement invariant. Builders can use these patterns as a secure-development checklist; auditors can use them to focus their review.

继续阅读全文

为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。

更多来自 Trail of Bits Blog

Answering your questions about Anthropic's lattice cryptography results

AI 摘要Anthropic's newly announced quantum algorithms for module lattices raise theoretical concerns about lattice-based cryptography but do not break deployed standards like ML-KEM, ML-DSA, or FN-DSA, since the attacks are asymptotic and impractical at real-world parameter sizes. Implementers are advised to take no immediate action, though cryptographers and standards bodies should study whether the attack could be improved in the future. Other cryptography, including RSA, elliptic curves, and symmetric schemes, is completely unaffected by these results.

After Binance, check what your signing systems can approve

AI 摘要The article examines Binance's October 2026 security incident, in which an attacker obtained valid signatures from the exchange's wallet-signing service via social engineering and stolen credentials, then used an EIP-7702 delegation to repeatedly drain funds without further signatures. It warns that many transaction monitoring and signing-policy systems fail to account for newer Ethereum execution paths such as EIP-7702 delegations, session keys, Safe modules, and ERC-4337 UserOperations, allowing malicious wallet-authority changes to go undetected. The author recommends four measures—reducing access to signing infrastructure, treating delegation as an administrative privilege, limiting damage even if signing is compromised, and detecting wallet-authority changes—each with verification tests to confirm the controls work.

The cryptography behind electronic voting (and why paper ballots are still essential)

AI 摘要The article explains why paper ballots remain essential for elections despite cryptographic advances, describing how systems like Helios and ElectionGuard use techniques such as homomorphic encryption, threshold key-sharing, and zero-knowledge proofs to protect voter privacy and provide verifiable tallies. It highlights that electronic voting introduces unique risks—such as scalable software vulnerabilities, compromised clients, and coercion—that paper-based systems largely avoid through physical controls and detectability of failures. Ultimately, cryptography can strengthen verifiability as a layer atop paper infrastructure, but it cannot fully replace the security and trust of paper ballots in high-stakes public elections.

Backporting security fixes at scale with Codex

AI 摘要The article describes how thousands of known CVEs remain unfixed in stable software like Linux kernel stable branches, Ubuntu LTS, and Debian because backporting security patches is time-consuming, thankless volunteer work that rarely gets prioritized. Using Codex with GPT-5.6, the team reduced backporting effort from days to roughly 30 minutes to three hours of human attention per fix, with AI agents handling patch adaptation, testing, and evidence gathering while engineers review and submit the patches. By October 29, this workflow had helped land fixes for 149 distinct CVEs in stable Linux kernel releases, along with patches for Fedora and Ubuntu packages, demonstrating that AI assistance can make neglected security work practical at scale.

Your AI agent fixed the bug, but what else did it change?

AI 摘要Trail of Bits has released two plugins, patching-bugs and regression-hunt, developed through its Patch the Planet initiative with OpenAI, which let AI agents reproduce reported bugs, develop fixes, and check whether changes break previously working behavior in open-source projects. The plugins standardize patching through strict input/output schemas, live proof-of-concept validation, and project-specific threat models and patching guidelines, with regression-hunt producing 25% fewer false-positive findings than a baseline Codex agent in preliminary evaluations. The authors argue that as AI accelerates bug discovery, the industry needs reliable, standardized patching workflows, and they encourage maintainers to add THREAT_MODEL.md and PATCHING_GUIDELINES.md files so the agents work within each project's rules.