安全6.5k · #14011
reentrancy
它能做什么
这份手册指导在智能合约中寻找重入弱点。适合希望确认每一处有风险的外部调用都是安全的审计人员和开发者。
适用场景
- ✓当合约进行转移价值或改变状态的外部调用时。
- ✓当合约中的多个函数共享同一存储时。
- ✓当只读函数在调用过程中可能返回过期数值时。
技能链接
https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/contracts/reentrancy/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
请用这个技能帮我:https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/contracts/reentrancy/SKILL.md
阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
npx skills add BitterSecurity/Decepticon --skill reentrancy
下载 SKILL.md,放进智能体的技能文件夹。
curl -L https://raw.githubusercontent.com/BitterSecurity/Decepticon/main/packages/decepticon/decepticon/skills/standard/contracts/reentrancy/SKILL.md -o SKILL.md
可以这样问 AI
“请帮我检查我们的金库合约是否存在重入漏洞,并确认提款函数是否安全?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体找出外部调用,检查状态变更是否发生在调用之前,以及是否应用了重入防护,然后进行测试。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Reentrancy Playbook
Variants
- Classic — external call before state update (The DAO)
- Cross-function — A calls out, reentered into B which reads/writes A's state
- Read-only — view function reads stale state during reentrancy, consumed by a second contract making decisions
- Cross-contract — same attack pattern across protocol boundaries
- ERC777 / ERC1155 hook —
onERC*Receivedcallback re-enters
Audit steps
solidity_scan_fileflags every.call{value:...}anddelegatecall- For each hit, check:
- Is there a state write BEFORE the external call?
- Is
ReentrancyGuard'snonReentrantmodifier applied? - Does it follow checks-effects-interactions?
- Trace call graph — if any function the call target can invoke reads or writes the same state slot, that's a reentrancy chain.
PoC via Foundry
foundry_reentrancy_test(target="Vault", function="withdraw", target_path="src/Vault.sol")
Then:
cp generated.t.sol /workspace/foundry/test/
cd /workspace/foundry && forge test -vvv --match-contract Test_withdraw
Success criteria
The attacker contract balance grows by more than its initial deposit after the attack transaction. The Foundry test should assert this.
CVSS
- Direct fund drain:
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H= 10.0 - Read-only with downstream impact: 8.1-9.1 depending on impact
Known exemplars
- The DAO (2016)
- Lendf.Me (2020, ERC777 hook reentrancy, $25M)
- Cream Finance (2021)
- Rari Capital (2022)
- Curve pool read-only reentrancy (2023)
常见问题
经典的修复方法是什么?
在外部调用之前更新状态,遵循检查、生效、交互的模式。
什么是只读重入?
视图函数在调用过程中可能返回过期数值,而其他合约可能依赖这些数值。
发现的问题如何确认?
使用 Foundry 测试检查合约余额是否超过了存入的金额。
详情
作者的原始描述
Hunt and validate reentrancy bugs — classic cross-function, same-function, read-only, and cross-contract variants.
热度
- GitHub 星标
- 6.5k
- 排名
- #14011
- 许可证
- Apache-2.0
- 更新时间
- 2026/11/1
评论
- …