首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >折返攻击

折返攻击
EN

Ethereum用户
提问于 2021-05-27 08:47:28
回答 1查看 119关注 0票数 0

我需要一些帮助,这段代码容易受到重入攻击吗?

代码语言:javascript
复制
function withdraw(address to, uint256 amountOfEth) external override onlyOwner {
    require(_balances[to].shares >= amountOfEth, "Burn exceeds balance");

    (uint256 amortizedLiability, uint256 withdrawAmount) = _getWithdrawAmount(to, amountOfEth);

    _balances[to].eth = _balances[to].eth.sub(amountOfEth);
    _balances[to].liability = _balances[to].liability.sub(amortizedLiability);
    _eth = _eth.sub(amountOfEth);
    _totalLiability = _totalLiability.sub(amortizedLiability);

    if (withdrawAmount > 0) {
        IERC20(_token).safeTransfer(to, withdrawAmount);
        emit FeeWithdrawn(_token, to, withdrawAmount, amountOfEth);
    }
}
EN

回答 1

Ethereum用户

发布于 2022-03-16 18:21:57

由于您在IERC20(_token).safeTransfer之前更改了合同状态,所以我认为它看起来非常安全。

我很高兴_getWithdrawAmount不做任何外部调用。

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

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

复制
相关文章

相似问题

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