guillemustafa-ux/dvdefi-writeups
GitHub: guillemustafa-ux/dvdefi-writeups
该项目为 Damn Vulnerable DeFi v4 安全挑战提供经过验证的 exploit 代码及审计级别的漏洞分析报告,帮助开发者系统学习 DeFi 智能合约攻防。
Stars: 0 | Forks: 0
# Damn Vulnerable DeFi — 解决方案与审计报告
[Damn Vulnerable DeFi](https://www.damnvulnerabledefi.xyz)的解决方案及审计级别的报告
**v4.1.0**,由[@tinchoabbate](https://github.com/tinchoabbate) / [The Red Guild](https://github.com/theredguild)开发的、基于 Foundry 的智能合约安全攻防游戏。
这是一篇关于**安全实践/训练**的作品:每个挑战都是一个故意留下漏洞的 DeFi 协议,目标是编写一个满足挑战链上成功条件的 exploit。对于这里的每一个挑战,都包含:
- 一个**已验证通过的 exploit**([`solutions/`](./solutions))—— 实际耗尽/破坏目标的测试代码;以及
- 一份**审计报告**([`writeups/`](./writeups)),其结构完全按照我在审计中报告的格式组织:漏洞类型 → 根本原因 → exploit 演练 → 修复方案 → 真实案例对照。
这是我防御性工作的进攻性对应部分(参见*相关项目*):破解这些挑战能让我精确掌握我在自己合约中致力于防范的那些失效模式。
## 已解决的挑战 (7)
| # | 挑战 | 漏洞类型 | 审计报告 |
|---|-----------|---------------------|----------|
| 01 | Unstoppable | 直接转账破坏了 ERC-4626 的记账不变量 (griefing/DoS) | [01-unstoppable.md](./writeups/01-unstoppable.md) |
| 02 | Naive Receiver | 缺少发起者检查 + trusted-forwarder/multicall 发起者伪造 | [02-naive-receiver.md](./writeups/02-naive-receiver.md) |
| 03 | Truster | 包含攻击者可控 target 和 calldata 的任意外部调用 | [03-truster.md](./writeups/03-truster.md) |
| 04 | Side Entrance | 通过铸币产生免费索取权的后门偿还闪电贷 | [04-side-entrance.md](./writeups/04-side-entrance.md) |
| 05 | The Rewarder | 批量领取的幂等性被破坏 → 奖励双花 | [05-the-rewarder.md](./writeups/05-the-rewarder.md) |
| 06 | Selfie | 通过即时投票权力实现闪电贷治理劫持 | [06-selfie.md](./writeups/06-selfie.md) |
| 07 | Puppet | 在流动性稀薄的 Uniswap V1 交易对上进行即时价格预言机操纵 | [07-puppet.md](./writeups/07-puppet.md) |
这七个挑战涵盖了 DeFi 基础的攻击面 —— 闪电贷、任意调用、预言机操纵、治理劫持、元交易伪造以及奖励记账。剩余的 v4 挑战(Compromised、Puppet V2/V3、Free Rider、Backdoor、Climber、Wallet Mining、ABI Smuggling、Shards、Curvy Puppet、Withdrawal)**尚未完成**,随着我逐步攻克它们将会被添加进来 —— 本 README 记录的是实际进展,而非预期目标。
## 凭证
所有七个 exploit 均在干净的 v4.1.0 checkout 版本上通过测试(Foundry `forge 1.7.1`,`solc 0.8.25`):
```
Ran 7 test suites: 7 tests passed, 0 failed, 0 skipped (7 total tests)
[PASS] test_unstoppable() (gas: 66,791)
[PASS] test_naiveReceiver() (gas: 398,237)
[PASS] test_truster() (gas: 102,157)
[PASS] test_sideEntrance() (gas: 234,332)
[PASS] test_theRewarder() (gas: 34,954,186)
[PASS] test_selfie() (gas: 685,520)
[PASS] test_puppet() (gas: 218,209)
```
## 复现
本仓库**不**包含上游挑战代码(出于对作者要求不要全盘镜像解决方案的尊重,同时也为了保持本仓库专注于*我个人的*工作)。相反,它只提供了解决方案的测试文件以及一个用于克隆上游代码并放入这些文件的脚本:
```
git clone https://github.com/guillemustafa-ux/dvdefi-writeups.git
cd dvdefi-writeups
bash scripts/reproduce.sh # clones DVDeFi v4, copies solutions in, runs forge test
```
或者手动操作:克隆 [`theredguild/damn-vulnerable-defi`](https://github.com/theredguild/damn-vulnerable-defi)(版本为 `v4.1.0`),执行 `git submodule update --init --recursive`,将 [`solutions/`](./solutions) 中的每个文件复制并覆盖对应的 `test//.t.sol`,然后运行 `forge test`。
每个解决方案都**原封不动**地保留了挑战原有的 `setUp`/`_isSolved` 测试套件 —— 成功条件是原作者设定的,而非我设定的;只有 `CODE YOUR SOLUTION HERE` 区域(以及任何辅助的 exploit 合约)是我的工作成果。
## 相关工作
我作品集中的防御性对应部分(经过自审计、强化并已部署):
- **rwa-yield-protocol** — 旗舰级 RWA 收益协议(ERC-7540 + Chainlink Automation/CCIP + UUPS),包含完整的 `SECURITY.md` 威胁模型。
- **yield-vault** — 带有不变量测试的 ERC-4626 + ERC-7540 金库。
- **botpass**、**aa-smart-wallet** — 链上订阅(ERC-721)和 ERC-4337 智能账户。
## 致谢与许可
- 挑战内容 © [@tinchoabbate](https://github.com/tinchoabbate) / The Red Guild —
[Damn Vulnerable DeFi](https://github.com/theredguild/damn-vulnerable-defi),基于 MIT 许可。
- 本仓库中的解决方案和审计报告均为我个人作品,基于 MIT 许可发布。
标签:Cutter, DeFi, Foundry, Solidity, 区块链安全, 安全靶场, 智能合约审计