From b3cbf04cd7f1adbfe5ce2024b3fbfb9c6e292fc0 Mon Sep 17 00:00:00 2001 From: Charliex2 Date: Mon, 17 Jun 2024 10:35:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E6=BC=8F=E6=B4=9E?= =?UTF-8?q?=E4=BE=8B=E5=AD=90=E6=B3=A8=E9=87=8A=E4=B8=8E=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=B8=8D=E4=B8=80=E8=87=B4=E7=9A=84=E9=94=99=E8=AF=AF=E4=B8=8E?= =?UTF-8?q?=E5=A4=9A=E5=A4=84typo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (1) 修改漏洞例子合约代码注释与代码不一致的错误; (2) 多处 typo; --- S14_TimeManipulation/readme.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/S14_TimeManipulation/readme.md b/S14_TimeManipulation/readme.md index 750068ee4..46cec51e0 100644 --- a/S14_TimeManipulation/readme.md +++ b/S14_TimeManipulation/readme.md @@ -34,16 +34,16 @@ tags: contract TimeManipulation is ERC721 { uint256 totalSupply; - // 构造函数,初始化NFT合集的名称、代号 + // 构造函数,初始化 NFT 合集的名称、代号 constructor() ERC721("", ""){} - // 铸造函数:当区块时间能被7整除时才能mint成功 + // 铸造函数:当区块时间能被 170 整除时才能 mint 成功 function luckyMint() external returns(bool success){ if(block.timestamp % 170 == 0){ _mint(msg.sender, totalSupply); // mint totalSupply++; success = true; - }else{ + } else { success = false; } } @@ -52,7 +52,7 @@ contract TimeManipulation is ERC721 { ## Foundry复现攻击 -攻击者只需操纵区块时间,将它设为能被 170 整除的数字,就可以成功铸造 NFT。我们选择 Foundry 来复现这个攻击,因为它提供了修改区块时间的作弊码(cheatcodes)。如果你不了解 Foundry/作弊码,可以阅读 [Foundry教程](https://github.com/AmazingAng/WTF-Solidity/blob/main/Topics/Tools/TOOL07_Foundry/readme.md) 和 [Foundry Book](https://book.getfoundry.sh/forge/cheatcodes)。 +攻击者只需操纵区块时间,将它设为能被 170 整除的数字,就可以成功铸造 NFT。我们选择 Foundry 来复现这个攻击,因为它提供了修改区块时间的作弊码(cheatcodes)。如果你不了解 Foundry 作弊码,可以阅读 [Foundry教程](https://github.com/AmazingAng/WTF-Solidity/blob/main/Topics/Tools/TOOL07_Foundry/readme.md) 和 [Foundry Book](https://book.getfoundry.sh/forge/cheatcodes)。 代码大致逻辑 @@ -87,7 +87,7 @@ contract TimeManipulationTest is Test { // Set block.timestamp to 169 vm.warp(169); console.log("block.timestamp: %s", block.timestamp); - // Sets all subsequent calls' msg.sender to be the input address + // Set all subsequent calls's msg.sender to be the input address // until `stopPrank` is called vm.startPrank(alice); console.log("alice balance before mint: %s", nft.balanceOf(alice)); @@ -139,7 +139,7 @@ Logs: Test result: ok. 1 passed; 0 failed; finished in 7.64ms ``` -我们可以看到,当我们将`block.timestamp` 修改为 17000时,铸造成功。 +我们可以看到,当我们将`block.timestamp` 修改为 17000 时,铸造成功。 ## 总结