File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,6 +15,45 @@ timezone: UTC+8
1515## Notes
1616
1717<!-- Content_START -->
18+ # 2025-08-17
19+
20+ 1 . 重入攻击 Reentrancy
21+ • 利用外部合约在 fallback 中重新调用原函数。历史上最著名的 The DAO 事件便因重入漏洞导致约 6000 万美元 ETH 被盗,最终造成以太坊社区分裂(形成 ETH/ETC 链)。
22+ • 防护方法:先更新状态,再转账。
23+ • 示例:
24+ // ❌ 有漏洞
25+ function withdraw() public {
26+ require(balance[ msg.sender] > 0);
27+ (bool sent,) = msg.sender.call{value: balance[ msg.sender] }("");
28+ require(sent);
29+ balance[ msg.sender] = 0;
30+ }
31+
32+ // ✅ 修复后
33+ function withdraw() public {
34+ uint256 amount = balance[ msg.sender] ;
35+ balance[ msg.sender] = 0;
36+ (bool sent,) = msg.sender.call{value: amount}("");
37+ require(sent);
38+ }
39+ 2 . 预言机操纵 Oracle Manipulation
40+ • 依赖外部价格源的不可信更新。
41+ • 解决方法:
42+ • 使用 Chainlink 等权威价格源。
43+ • 增加时序约束和多源验证。
44+ • 使用 TWAP 等加权算法。
45+ 3 . 整数溢出/下溢
46+ • 使用 unchecked {} 时需确保逻辑安全。
47+ • 推荐使用Solidity 0.8+ 的内建溢出检查或 SafeMath。
48+ 4 . 权限控制缺失
49+ • 所有管理函数应使用 onlyOwner 或 AccessControl 修饰符保护。
50+ 5 . 未初始化代理
51+ • 基于代理模式的合约若未正确执行初始化函数,可能被任意人初始化并接管合约。
52+ • 著名的例子包括 Harvest Finance 其在使用 Uniswap V3 做市策略的 Vault 合约中存在未初始化漏洞,如果被利用攻击者可销毁实现合约。该团队曾为此漏洞支付高额赏金修复。
53+ 6 . 前置交易/三明治攻击
54+ • 攻击者在交易执行前后分别发送交易,以不利滑点或套利为目的。
55+ • 例如 2025 年 3 月,一名用户在 Uniswap V3 的稳定币兑换中遭遇三明治攻击,约 21.5 万美元的 USDC 兑换几乎被抢跑,损失了 98% 的资金>
56+
1857# 2025-08-16
1958
2059• 如果我们需要多次访问storage变量,并且还要对其进行修改的话,上面的这个优化方法就不合适了,因为上面的方法将storage读取到memory中,就算是修改memory变量,原本的storage变量也不会被修改(上面的方法适合只多次读取storage变量,但是不会对其进行修改的情况)。所以我们要用下面的优化方法:
You can’t perform that action at this time.
0 commit comments