首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >状态更改后发出事件是否会导致重入攻击漏洞?

状态更改后发出事件是否会导致重入攻击漏洞?
EN

Ethereum用户
提问于 2018-08-29 19:09:38
回答 1查看 598关注 0票数 3

下面的函数易受重入攻击吗?

代码语言:javascript
复制
function withdraw() public {
     uint amount = pendingWithdrawals[msg.sender];
     // Remember to zero the pending refund before
     // sending to prevent re-entrancy attacks
     pendingWithdrawals[msg.sender] = 0;
     msg.sender.transfer(amount);
     emit AmountWithdrawn(msg.sender, amount);
 }
EN

回答 1

Ethereum用户

回答已采纳

发布于 2018-08-29 19:18:21

不,它不容易受到重入攻击。事件不会导致函数抛出。

您编写它的方式是非常安全的,因为您在发送pendingWithdrawals之前正在更新amount

在将来,尝试保持您编写的所有函数的结构与此非常相似,即在执行操作之前更改状态。

票数 1
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/57703

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档