LoginSignup
0
0

More than 5 years have passed since last update.

Level 10. Re-entrancy(The Ethernaut)

Posted at

「The Ethernaut by Zeppelin Level 10. Re-entrancy」を翻訳してみました(CryptoZombiesのように?)

原文はこちら

https://ethernaut.zeppelin.solutions
10. Re-entrancyをクリック

10. Re-entrancy

難易度 6/6
コントラクトからすべての資金を盗むことがこのレベルのクリア条件だ。

回答の助けになるヒント
  • 信頼されていないコントラクトでは、期待される動作以上にコードが実行されてしまうぞ。
  • フォールバックメソッドについて
  • バブルを投げ返す/戻す
  • 場合によっては、コントラクトを攻撃する最適な方法は別のコントラクトからの場合もありうるぞ。
  • 上記の「Help」ページから「Beyond the console」部分を参照せよ。

ソースコード

pragma solidity ^0.4.18;

contract Reentrance {

  mapping(address => uint) public balances;

  function donate(address _to) public payable {
    balances[_to] += msg.value;
  }

  function balanceOf(address _who) public view returns (uint balance) {
    return balances[_who];
  }

  function withdraw(uint _amount) public {
    if(balances[msg.sender] >= _amount) {
      if(msg.sender.call.value(_amount)()) {
        _amount;
      }
      balances[msg.sender] -= _amount;
    }
  }

  function() public payable {}
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0