File size: 827 Bytes
5de1250
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract RandomnessVulnerability {
    mapping(address => bool) public hasWon;
    uint256 public prize = 1 ether;
    
    function playLottery() external payable {
        require(msg.value >= 0.1 ether, "Insufficient payment");
        
        // Vulnerable randomness using block properties
        uint256 randomNumber = uint256(keccak256(abi.encodePacked(
            block.timestamp,
            block.difficulty, 
            msg.sender
        ))) % 100;
        
        if (randomNumber < 10) {
            hasWon[msg.sender] = true;
            payable(msg.sender).transfer(prize);
        }
    }
    
    function getBlockHash() external view returns (bytes32) {
        // Predictable block hash usage
        return blockhash(block.number - 1);
    }
}