01.Guess the number
2023-06-23 20:22:15 # 01.Capturetheether CTF

Guess the number

topic

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
pragma solidity ^0.4.21;

contract GuessTheNumberChallenge {
uint8 answer = 42;

function GuessTheNumberChallenge() public payable {
require(msg.value == 1 ether);
}

function isComplete() public view returns (bool) {
return address(this).balance == 0;
}

function guess(uint8 n) public payable {
require(msg.value == 1 ether);

if (n == answer) {
msg.sender.transfer(2 ether);
}
}
}

analyses

It is easy to complete this level. We can see the answer “42”. So we dont need to guess.

solution

call guess(uint8) with the parameter “42” and 1 ETH.