30.SWC-130_Get Private Info
2023-07-13 16:23:50 # 09.SWC

SWC-130_Get Private Info

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
44
45
46
47
48
49
50
51
52
53
/*
* @source: https://youtu.be/P_Mtd5Fc_3E
* @author: Shahar Zini
*/
pragma solidity ^0.5.0;

contract GuessTheNumber
{
uint _secretNumber;
address payable _owner;
event success(string);
event wrongNumber(string);

constructor(uint secretNumber) payable public
{
require(secretNumber <= 10);
_secretNumber = secretNumber;
_owner = msg.sender;
}

function getValue() view public returns (uint)
{
return address(this).balance;
}

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

uint p = address(this).balance;
checkAndTransferPrize(/*The prize‮/*rebmun desseug*/n , p/*‭
/*The user who should benefit */,msg.sender);
}

function checkAndTransferPrize(uint p, uint n, address payable guesser) internal returns(bool)
{
if(n == _secretNumber) /*_secretNumber can be seen*/
{
guesser.transfer(p);
emit success("You guessed the correct number!");
}
else
{
emit wrongNumber("You've made an incorrect guess!");
}
}

function kill() public
{
require(msg.sender == _owner);
selfdestruct(_owner);
}
}
Prev
2023-07-13 16:23:50 # 09.SWC
Next