Skip to content

Conversation

@XiaoHai67890
Copy link

Ethernaut Vulnerability Fix PR

漏洞描述

原关卡合约存在重入攻击漏洞,攻击者可以在 withdraw 调用中再次调用自身函数,从而重复提取资金。

修复方案

  • 添加 noReentrant 修饰器,防止在函数执行中再次进入。
  • 先更新状态再发送以太币,符合 Checks-Effects-Interactions 模式。

部署

npm install
npx hardhat compile
npx hardhat test

# Ethernaut Vulnerability Fix PR

## 漏洞描述
原关卡合约存在重入攻击漏洞,攻击者可以在 `withdraw` 调用中再次调用自身函数,从而重复提取资金。

## 修复方案
- 添加 `noReentrant` 修饰器,防止在函数执行中再次进入。
- 先更新状态再发送以太币,符合 Checks-Effects-Interactions 模式。

## 部署
```bash
npm install
npx hardhat compile
npx hardhat test
```
@github-actions
Copy link
Contributor

Thank you for your contribution to OpenZeppelin Ethernaut. Before being able to integrate those changes, we would like you to sign our Contributor License Agreement.
You can sign the CLA by just posting a Pull Request Comment with the sentence below. Thanks.


I confirm that I have read and hereby agree to the OpenZeppelin Contributor License Agreement


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant